Rosetta Problems

First Second

https://atcoder.jp/contests/agc047/tasks/agc047_b