Problem : http://www.codechef.com/problems/ACUPALIN
My Solution : http://www.codechef.com/viewsolution/6469499