Getting runtime error

question -https://www.codechef.com/COOK120B/problems/ORTHODOX/
my solution -https://www.codechef.com/viewsolution/35805933

please tell me why i am getting run time error during submission but i am getting correct answers for the test cases

You cannot use an array of INT_MAX size, so it gives a segmentation fault.
Also your solution is bound TLE even if it worked.
Take a look at editorial, it would be better.
Also look at this code for implementation details https://www.codechef.com/viewsolution/35848157