URI OJ -- 1663 (Ambiguous Permutations)

Solution :