A few days ago i stumbeld upon a 1200 which gave me a headache 1822D - Super-Permutation , and just now i solved it. What i want you to do is look at this problem and try figuring it out , then read the rest of this post.

The way i solved it , and what i believe to be the easiest way of solving it looking at last test case and finding the pattern, after this you should be all set , the implementation is really easy.

This problem taught me that i really need to observe the test cases more , even if there is really only one useful test case.

Enjoy the rest of your day.