Codechef august challenge CHEFWED

codechef august challenge CHEFWED

please review this code and help me why some test case are failed
thanks for help