Circular street P38997


Statement
 

pdf   zip

Jacobo loves to travel. He has discovered a city whose streets form a single circle with nn houses. Each house is labeled with an integer.

Jacobo starts at the first house. From a house with label xx, he moves exactly xx houses along the circular street:

  • If x>0x > 0, he moves xx houses to the right.

  • If x<0x < 0, he moves −x-x houses to the left.

  • If x=0x = 0, he stays at the current house.

After moving, he looks at the number written on the house he reaches, and repeats the same process. Because the street is circular, moving past the last house continues from the first house, and moving before the first house continues from the last house.

Your task is to determine the length of the cycle eventually followed by Jacobo. A cycle consists of the houses visited repeatedly from some point onward. In particular, if Jacobo reaches a house labeled 0, he remains there forever, so the cycle has length 1.

Input

Input consists of several cases, each with nn, followed by nn integer numbers with absolute value at most 10910^9. Assume 1≤n≤1051 \le n \le 10^5.

Output

For each case, print a single integer: the length of the cycle eventually followed by Jacobo.

Public test cases
  • Input

    5  3 2 -1 -1 0
    1  0
    2  -1000001 1000001
    

    Output

    3
    1
    2
    
  • Information
    Author
    Joan Alemany
    Language
    English
    Official solutions
    C++
    User solutions
    C++