I am getting correct output for all the given test cases
http://www.codechef.com/problems/MIME2
http://www.codechef.com/viewsolution/2228224