F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Game

Time 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
3 1 -2 3
 

Sample Output
2
 

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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2025-03-28 23:37:54, Gzip enabled