Rosetta Problems

Ancient Scrolls

https://atcoder.jp/contests/jag2012autumn/tasks/icpc2012autumn_k