Rosetta Problems

魔法の訓練 (Magical Training)

https://atcoder.jp/contests/ijpc2012-1/tasks/ijpc_training