Circular street

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:

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.

Problem information

Author: Joan Alemany
Event: Vint-i-quatrè Concurs de Programació de la UPC - Final
Date: 2026-10-07

Generation: 2026-10-03T14:13:10.383Z

© Jutge.org, 2006–2026.
https://jutge.org