Codechef -- Ambiguous Permutations

problem  link 

Solution :