I have been trying the question , Just Some Permutations , for quite some time and I am unable to make real progress. I guess we need to apply Principle of Inclusion Exclusion somehow but I am unable to understand exactly how. The question appeared in the 2014 ACM ICPC Dhaka Regionals. Any help on how to solve it will be great.