## Algorithm

C. Round Table Knights
time limit per test
0.5 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.

Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.

A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.

On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood.

King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not.

Input

The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood.

Output

Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO".

Examples
input
Copy
`31 1 1`
output
Copy
`YES`
input
Copy
`61 0 1 1 1 0`
output
Copy
`YES`
input
Copy
`61 0 0 1 0 1`
output
Copy
`NO`

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````#include <cstdio>
#include <vector>

int main(){

long n; scanf("%ld", &n);
std::vector<int> a(n); for(long p = 0; p < n; p++){scanf("%d", &a[p]);}
std::vector<long> div;

for(long p = 1; p * p <= n; p++){if(n % p == 0){div.push_back(p); div.push_back(n / p);}}

bool possible(false);
for(long p = 0; p < div.size(); p++){
if(possible){break;}
long step = div[p];
long nodes = n / step;
if(nodes < 3){continue;}
for(long offset = 0; offset < step; offset++){
bool test(true);
for(long u = 0; u < nodes; u++){if(!a[(step * u + offset) % n]){test = false; break;}}
if(test){possible = true; break;}
}
}

puts(possible ? "YES" : "NO");

return 0;
}``````
Copy The Code &

Input

cmd
3
1 1 1

Output

cmd
YES