Discovering Permutations

LightOJ - 1023