![]() |
||||||||||
|
||||||||||
GameTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 247 Accepted Submission(s): 16 Problem Description Alice and Bob are playing game. Firstly, Alice drew a regular polygon with n vertices, then assigned each vertex a number. Then Bob's goal is to change all the numbers to non-negative numbers. He can do following operation in each step: choose one vertex i, supposed Ai is the number on vertex i, then add Ai to it's left and right adjacent vertex, and turn Ai into -Ai. Now you are to help Bob to find out the minimum step to reach his goal. Input Multiple test cases ended with EOF. Each test case begins with one integer n, followed a line consist of by n integers representing the numbers on the vertices clockwise. 2<n¡Ü105 |Ai| ¡Ü 105 |sum{Ai}| ¡Ü 10 Output If Bob cannot end this game, then output 'Endless'(without quotes), otherwise output the minimum step for Bob to end this game. Sample Input
Sample Output
Hint In the sample, first turn -2 to 2, then the sequences became -1 2 1, then choose -1, the result is 1 1 0, all the numbers are non-negative, so the minimum step would be 2. Source | ||||||||||
|