Rosetta Problems

Following Permutations

https://atcoder.jp/contests/bitflyer2018-final/tasks/bitflyer2018_final_g