Rosetta Problems

Cut the Ribbon and Collect the Passwords

https://atcoder.jp/contests/awc0118/tasks/awc0118_c