Rosetta Problems

Colorful Hats

https://atcoder.jp/contests/agc016/tasks/agc016_b