Rosetta Problems

IOI 列車で行こう (Take the 'IOI' train)

https://atcoder.jp/contests/joi2013ho/tasks/joi2013ho2