Getting runtime error in TEMPLELAnd

Can someone tell me why i am getting runtime error in TEMPLELAND question of Snackdown 17 qualifier?? Here is my code https://www.codechef.com/viewsolution/13785482

First take all the input, then proceed to solution.

I strictly believe that its happening because you are taking array in input only when n is odd. Try taking array as input just after taking n, meaning outside your if statement and get back to me.

1 Like

Yes, it worked.Thanks a lot. I think when i tried it out on my compiler i must have only given odd length array as test cases and hence couldnt figure out the error.

if n%2!=0:

this line in your code.
No matter whether number of strips are ODD or EVEN.
You’ve to take input after that check the number of strips and provide output.
In your code since you are only taking input when number of strips are odd.
so when codechef compiler tried to enter even number of strips then your code didn’t provide it the console to enter array that’s why Runtime Error.