Rosetta Problems

Ancient Commemorative Monolith

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