getting ac on big inputs; w/a on task 3 and 4

https://www.codechef.com/viewsolution/55673357

what is the problem with my code?