codechef; solve "Ambiguous Permutations"