Why i got worng ans

[question link][1]
[1]: http://www.codechef.com/problems/WALK
[my code][2]
[2]: http://ideone.com/2UJOKL

Hi, your code gives wrong answer for the case

1

5

6 6 6 6 6

Expected Answer=10, Your Answer=6, Your code with the test case: Solution