#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;

#define ll long long
#define pii pair<int,int>

const int maxn = 4e5 + 5;
const int mod = 998244353;

int n;
ll a[maxn], b[maxn];
unordered_map<ll, int> mp;
unordered_map<ll, int> sum;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    mp[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 1; i <= n; i++) {
    sum[a[i]] += b[i];
  }
  sort(a + 1, a + n + 1);
  int num = unique(a + 1, a + n + 1) - a - 1;
 // cout << num << endl;
  ll ans = 0;
  for (int i = 1; i <= num; i++) {
    if (mp[a[i]] >= 2) {
      ll now = sum[a[i]];
      for (int j = 1; j <= num; j++) {
        if (i == j)
          continue;
        if (((a[j] & a[i]) == a[j]) ||  mp[a[j]] > 1) {
          now += sum[a[j]];
        }
      }
      //cout << i << ' ' << now << endl;
      ans = max(ans, now);
    }
  }
  printf("%lld\n", ans);
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;

#define ll long long
#define pii pair<int,int>

const int maxn = 4e5 + 5;
const int mod = 998244353;

int n;
ll a[maxn], b[maxn];
unordered_map<ll, int> mp;
bool vis[maxn];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
    ++mp[a[i]];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", b + i);
  }
  for (int i = 1; i <= n; i++) {
    if (mp[a[i]] > 1) {
      for (int j = 1; j <= n; j++) {
        if ((a[i] & a[j]) == a[j]) {
          vis[j] = 1;
        }
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      ans += b[i];
  }
  printf("%lld\n", ans);
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;

#define ll long long
#define pii pair<int,int>

const int maxn = 4e5 + 5;
const int mod = 998244353;

int n;
ll a[maxn], b[maxn];
unordered_map<ll, int> mp;
unordered_map<ll, int> sum;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    mp[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 1; i <= n; i++) {
    sum[a[i]] += b[i];
  }
  sort(a + 1, a + n + 1);
  int num = unique(a + 1, a + n + 1) - a - 1;
 // cout << num << endl;
  ll ans = 0;
  for (int i = 1; i <= num; i++) {
    if (mp[a[i]] >= 2) {
      ll now = sum[a[i]];
      for (int j = 1; j < i; j++) {
        if ((a[j] & a[i]) == a[j]) {
          now += sum[a[j]];
        }
      }
      //cout << i << ' ' << now << endl;
      ans = max(ans, now);
    }
  }
  printf("%lld\n", ans);
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;

#define ll long long
#define pii pair<int,int>

const int maxn = 4e5 + 5;
const int mod = 998244353;

int n;
int a[maxn], b[maxn];
unordered_map<ll, int> mp;
bool vis[maxn];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    ++mp[a[i]];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", b + i);
  }
  for (int i = 1; i <= n; i++) {
    if (mp[a[i]] > 1) {
      for (int j = 1; j <= n; j++) {
        if ((a[i] & a[j]) == a[j]) {
          vis[j] = 1;
        }
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      ans += b[i];
  }
  printf("%lld\n", ans);
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;

#define ll long long
#define pii pair<int,int>

const int maxn = 4e5 + 5;
const int mod = 998244353;

int n;
ll a[maxn], b[maxn];
unordered_map<ll, int> mp;
unordered_map<ll, int> sum;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    mp[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 1; i <= n; i++) {
    sum[a[i]] += b[i];
  }
  sort(a + 1, a + n + 1);
  int num = unique(a + 1, a + n + 1) - a - 1;
 // cout << num << endl;
  ll ans = 0;
  for (int i = 1; i <= num; i++) {
    if (mp[a[i]] >= 2) {
      ll now = sum[a[i]];
      for (int j = 1; j < i; j++) {
        if (((a[j] & a[i]) == a[j]) ||  mp[a[j]] > 1) {
          now += sum[a[j]];
        }
      }
      //cout << i << ' ' << now << endl;
      ans = max(ans, now);
    }
  }
  printf("%lld\n", ans);
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;

#define ll long long
#define pii pair<int,int>

const int maxn = 4e5 + 5;
const int mod = 998244353;

int n;
ll a[maxn], b[maxn];
unordered_map<ll, int> mp;
unordered_map<ll, int> sum;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    mp[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 1; i <= n; i++) {
    sum[a[i]] += b[i];
  }
  sort(a + 1, a + n + 1);
  int num = unique(a + 1, a + n + 1) - a - 1;
 // cout << num << endl;
  ll ans = 0;
  for (int i = 1; i <= num; i++) {
    if (mp[a[i]] >= 2) {
      ll now = sum[a[i]];
      for (int j = 1; j < i; j++) {
        if (((a[j] & a[i]) == a[j]) || ( (a[i] & a[j]) == 0 && mp[a[j]] > 1)) {
          now += sum[a[j]];
        }
      }
      //cout << i << ' ' << now << endl;
      ans = max(ans, now);
    }
  }
  printf("%lld\n", ans);
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=7005;
struct Node{
	ll a;
	int b;
}a[N];
bool cmp(const Node a, const Node b)
{
	return a.a<b.a;
}
ll work(int x)
{
	ll sum=a[x].b;
	ll p=a[x].a;
	for(int i=x-1;i>0;i--){
		if(((a[i].a)|p)==p){
			sum+=a[i].b;
//			printf("%d ",i);
		}
	}
//	printf("%I64d\n",sum);
	return sum;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%I64d",&a[i].a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].b);
	}
	sort(a+1,a+1+n,cmp);
//	for(int i=1;i<=n;i++){
//		printf("%I64d %d\n",a[i].a,a[i].b);
//	}
	ll p=a[n].a+1;
	ll ans=0;
	for(int i=n;i>1;i--){
		if(a[i].a==a[i-1].a&&a[i].a!=p){
			ans=max(ans,work(i));
			p=a[i].a;
		}
	}
	printf("%I64d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=7005;
struct Node{
	ll a;
	int b;
}a[N];
int n;
bool cmp(const Node a, const Node b)
{
	return a.a<b.a;
}
ll work(ll x)
{
	ll sum=0;
	for(int i=1;i<=n;i++){
		if((a[i].a|x)==x){
			sum+=a[i].b;
		}
	}
	return sum;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%I64d",&a[i].a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].b);
	}
	sort(a+1,a+1+n,cmp);
	ll p=0;
	bool q=0;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if((i-1>0&&a[i].a==a[i-1].a)||(i+1<=n&&a[i].a==a[i+1].a)){
			p=(p|a[i].a);
			q=1;
		}
	}
	if(q==0)printf("0");
	else printf("%I64d",work(p));
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=7005;
struct Node{
	ll a;
	int b;
}a[N];
ll b[N];
int n,cnt;
bool cmp(const Node a, const Node b)
{
	return a.a<b.a;
}
ll work()
{
	ll sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=cnt;j++){
			if((a[i].a|b[j])==b[j]){
				sum+=a[i].b;
				break;
			}
		}
	}
	return sum;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%I64d",&a[i].a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].b);
	}
	sort(a+1,a+1+n,cmp);
	cnt=0;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if((i-1>0&&a[i].a==a[i-1].a)||(i+1<=n&&a[i].a==a[i+1].a)){
			if(cnt>0&&b[cnt]==a[i].a)continue;
			cnt++;
			b[cnt]=a[i].a;
		}
	}
	if(cnt==0)printf("0");
	else printf("%I64d",work());
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=7005;
struct Node{
	ll a;
	int b;
}a[N];
bool cmp(const Node a, const Node b)
{
	return a.a<b.a;
}
ll work(int x)
{
	ll sum=a[x].b;
	ll p=a[x].a;
	for(int i=x-1;i>0;i--){
		if(((a[i].a)|p)==p||a[i].a==a[i+1].a||(i>1&&a[i].a==a[i-1].a)){
			sum+=a[i].b;
			p=(p|a[i].a);
//			printf("%d ",i);
		}
	}
//	printf("%I64d\n",sum);
	return sum;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%I64d",&a[i].a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].b);
	}
	sort(a+1,a+1+n,cmp);
//	for(int i=1;i<=n;i++){
//		printf("%I64d %d\n",a[i].a,a[i].b);
//	}
	ll p=a[n].a+1;
	ll ans=0;
	for(int i=n;i>1;i--){
		if(a[i].a==a[i-1].a&&a[i].a!=p){
			ans=max(ans,work(i));
			p=a[i].a;
		}
	}
	printf("%I64d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=7005;
struct Node{
	int a;
	int b;
}a[N];
bool cmp(const Node a, const Node b)
{
	return a.a<b.a;
}
ll work(int x)
{
	ll sum=a[x].b;
	int p=a[x].a;
	for(int i=x-1;i>0;i--){
		if((a[i].a)|p==p){
			sum+=a[i].b;
		}
	}
	return sum;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].b);
	}
	sort(a+1,a+1+n,cmp);
//	for(int i=1;i<=n;i++){
//		printf("%d %d\n",a[i].a,a[i].b);
//	}
	int p=998244353;
	ll ans=0;
	for(int i=n;i>1;i--){
		if(a[i].a==a[i-1].a&&a[i].a!=p){
			ans=max(ans,work(i));
			p=a[i].a;
		}
	}
	printf("%I64d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=7005;
struct Node{
	ll a;
	int b;
}a[N];
bool cmp(const Node a, const Node b)
{
	return a.a<b.a;
}
ll work(int x)
{
	ll sum=a[x].b;
	ll p=a[x].a;
	for(int i=x-1;i>0;i--){
		if((a[i].a)|p==p){
			sum+=a[i].b;
		}
	}
	return sum;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%I64d",&a[i].a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].b);
	}
	sort(a+1,a+1+n,cmp);
//	for(int i=1;i<=n;i++){
//		printf("%d %d\n",a[i].a,a[i].b);
//	}
	int p=998244353;
	ll ans=0;
	for(int i=n;i>1;i--){
		if(a[i].a==a[i-1].a&&a[i].a!=p){
			ans=max(ans,work(i));
			p=a[i].a;
		}
	}
	printf("%I64d",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=7005;
struct Node{
	ll a;
	int b;
}a[N];
int n;
bool cmp(const Node a, const Node b)
{
	return a.a<b.a;
}
ll work(ll x)
{
	ll sum=0;
	for(int i=1;i<=n;i++){
		if((a[i].a|x)==x){
			sum+=a[i].b;
		}
	}
	return sum;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%I64d",&a[i].a);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].b);
	}
	sort(a+1,a+1+n,cmp);
	ll p=0;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if((i-1>0&&a[i].a==a[i-1].a)||(i+1<=n&&a[i].a==a[i+1].a)){
			p=(p|a[i].a);
		}
	}
	printf("%I64d",work(p));
	return 0;
}


/*
 * Created by: Son Dinh
 */
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sqr(x) (x)*(x)
#define sz(X) (int)(X).size()
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const int mod = 1e9+7;

int n;
ll a[7005],b[7005],res = 0;
map<ll,ll> p,cnt,used;
vector<ll> v;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(int i = 1; i <= n; ++i){
        cin >> b[i];
        p[a[i]] += b[i];
    }
    sort(a+1,a+n+1);
    for(int i = 1; i <= n; ++i){
        if(cnt[a[i]] > 1 && !used[a[i]]){
            res += p[a[i]];
            used[a[i]] = 1;
            v.pb(a[i]);
        }
    }
    for(int i = 0; i < sz(v); ++i){
            ll tmp = 0;
            ll x = v[i];
            for(int i = 0; i <= 60; ++i)
            if(x & (1LL << i)){
                x &= ~(1LL << i);
                if(cnt[x] && !used[x]){
                    tmp += p[x];
                    used[x] = 1;
                }
            }
            res += tmp;
    }
    cout << res;
    return 0;
}


import java.util.*;
import java.io.*;
public class a {
  static long mod = 1000000000l;
public static void main(String[] args) throws IOException
{
  input.init(System.in);
  PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
  int n = input.nextInt();
  int[] data = new int[n];
  for(int i = 0; i<n; i++) data[i] = input.nextInt();
  boolean good = false;
  for(int i = 1; i<(n+1)/2; i++)
  {
    //System.out.println(n+" "+i);
    if(n%i != 0) continue;
    //while(n%i == 0 && i>1) n/=i;
    boolean check = false;
    for(int j = 0; j<i; j++)
    {
      boolean okay = true;
      for(int k = 0; k<n/i; k++)
      {
        if(0==data[(j+k*i)%n])
        {
          okay = false;
          break;
        }
      }
      if(okay)
      {
        good = true;
        check = true;
        break;
      }
    }
    if(check) break;
  }
  out.println(good?"YES":"NO");

  out.close();

}
static void sort(int[] data)
{
  Random r = new Random();
  int n = data.length;
  for(int i = 0; i<2*n; i++)
  {
    int a = r.nextInt(n), b = r.nextInt(n), temp = data[a];
    data[a] = data[b];
    data[b] = temp;
  }
  Arrays.sort(data);
}
static class input {
  static BufferedReader reader;
  static StringTokenizer tokenizer;

  /** call this method to initialize reader for InputStream */
  static void init(InputStream input) {
      reader = new BufferedReader(
                   new InputStreamReader(input) );
      tokenizer = new StringTokenizer("");
  }

  /** get next word */
  static String next() throws IOException {
      while ( ! tokenizer.hasMoreTokens() ) {
          //TODO add check for eof if necessary
          tokenizer = new StringTokenizer(
                 reader.readLine() );
      }
      return tokenizer.nextToken();
  }

  static int nextInt() throws IOException {
      return Integer.parseInt( next() );
  }

  static double nextDouble() throws IOException {
      return Double.parseDouble( next() );
  }
  static String nextLine() throws IOException {
    return reader.readLine();
  }
}
}


import java.util.*;
import java.io.*;
public class a {
  static long mod = 1000000000l;
public static void main(String[] args) throws IOException
{
  input.init(System.in);
  PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
  int n = input.nextInt();
  int[] data = new int[n];
  for(int i = 0; i<n; i++) data[i] = input.nextInt();
  boolean good = false;
  int m = n;
  for(int i = 1; i<(m+1)/2; i++)
  {
    //System.out.println(n+" "+i);
    if(n%i != 0) continue;
    while(n%i == 0 && i>1) n/=i;
    boolean check = false;
    for(int j = 0; j<i; j++)
    {
      boolean okay = true;
      for(int k = 0; k<m/i; k++)
      {
        if(0==data[(j+k*i)%m])
        {
          okay = false;
          break;
        }
      }
      if(okay)
      {
        good = true;
        check = true;
        break;
      }
    }
    if(check) break;
  }
  out.println(good?"YES":"NO");

  out.close();

}
static void sort(int[] data)
{
  Random r = new Random();
  int n = data.length;
  for(int i = 0; i<2*n; i++)
  {
    int a = r.nextInt(n), b = r.nextInt(n), temp = data[a];
    data[a] = data[b];
    data[b] = temp;
  }
  Arrays.sort(data);
}
static class input {
  static BufferedReader reader;
  static StringTokenizer tokenizer;

  /** call this method to initialize reader for InputStream */
  static void init(InputStream input) {
      reader = new BufferedReader(
                   new InputStreamReader(input) );
      tokenizer = new StringTokenizer("");
  }

  /** get next word */
  static String next() throws IOException {
      while ( ! tokenizer.hasMoreTokens() ) {
          //TODO add check for eof if necessary
          tokenizer = new StringTokenizer(
                 reader.readLine() );
      }
      return tokenizer.nextToken();
  }

  static int nextInt() throws IOException {
      return Integer.parseInt( next() );
  }

  static double nextDouble() throws IOException {
      return Double.parseDouble( next() );
  }
  static String nextLine() throws IOException {
    return reader.readLine();
  }
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        int[] knight = nextIntArray(n);
        boolean res = false;
        for (int x = 3; x <= n; x++) {
            if (n % x == 0) {
                int limit = n/x, sum = 0;
                for (int y = 0; y < limit ; y++) {
                    sum = 0;
                    for (int z = y; z < n; z += limit) {
                        if (knight[z] == 1) {
                            sum++;
                        }
                    }
                    if (sum == x) {
                        res= true;
                        break;
                    }
                }
            }
        }
        out.println(res ? "YES" : "NO");
    }

    public static void main(String[] args) {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            new Main().solve();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(239);
        }
    }
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    static String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    static int[] nextIntArray(int n) throws IOException {
        int[] temp = new int[n];
        for (int x = 0; x < n; x++) {
            temp[x] = nextInt();
        }
        return temp;
    }

    static long[] nextLongArray(int n) throws IOException {
        long[] temp = new long[n];
        for (int x = 0; x < n; x++) {
            temp[x] = nextLong();
        }
        return temp;
    }

    static String[] nextArray(int n) throws IOException {
        String[] temp = new String[n];
        for (int x = 0; x < n; x++) {
            temp[x] = nextToken();
        }
        return temp;
    }

    static <T> void debug(T x) {
        System.out.println("debug x: " + x.toString());
    }

    static void debugInt(int[] x) {
        for (int a = 0; a < x.length; a++) {
            System.out.println("debug array no: " + a + " value: " + x[a]);
        }
    }
    static void debugArray(String[] x) {
        for (int a = 0; a < x.length; a++) {
            System.out.println("debug array no: " + a + " value: " + x[a]);
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class C {
    private void solve() throws IOException {
        int n = Integer.parseInt(stdin.readLine());
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            int r = Integer.parseInt(stdin.readLine());
            if (r == 1)
                b[i] = true;
        }
        for (int d = 3; d <= n; d++) {
            if (n%d == 0) {
                int k = n/d;
                end : for (int i = 0; i < k; i++) {
                    for (int j = i; j < n; j += k)
                        if (!b[j]) continue end;
                            out.println("YES");
                            out.flush();
                            return;
                }
            }
        }
        out.println("NO");
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new C().run();
    }

    BufferedReader stdin;
    PrintWriter out;

    public void run() throws IOException {
        stdin = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
        stdin.close();
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class C {
    private void solve() throws IOException {
        int n = Integer.parseInt(stdin.readLine());
        StringTokenizer o = new StringTokenizer(stdin.readLine());
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            int r = Integer.parseInt(o.nextToken());
            if (r == 1)
                b[i] = true;
        }
        for (int d = 3; d <= n; d++) {
            if (n%d == 0) {
                int k = n/d;
                end : for (int i = 0; i < k; i++) {
                    for (int j = i; j < n; j += k)
                        if (!b[j]) continue end;
                            out.println("YES");
                            out.flush();
                            return;
                }
            }
        }
        out.println("NO");
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new C().run();
    }

    BufferedReader stdin;
    PrintWriter out;

    public void run() throws IOException {
        stdin = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
        stdin.close();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class C071 {
	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(r.readLine());
		StringTokenizer st = new StringTokenizer(r.readLine());
		int[] facs = facs(n);
		int[] ar = new int[n];
		for(int x =0;x<n;x++)
			ar[x]=Integer.parseInt(st.nextToken());
		for (int p:facs) {
			boolean[] ad = new boolean[p];
			if (2*p>=n) continue;
			for(int x=0;x<n;x++)
				if(ar[x]==0) {
					ad[x%p] = true;
				}
			for(int x =0;x<p;x++) {
				if(!ad[x]) {
					System.out.println("YES");
					return;
				}
			}

		}
		System.out.println("NO");

	}
	static int[] facs(int a) {
		ArrayList<Integer> ar = new ArrayList<Integer>();
		ar.add(1);
		for(int x = 2;x<a;x++) {
			if(a%x==0) {
				while(a%x==0) {
					a/=x;
				}
				ar.add(x);
			}
		}

		int[] i = new int[ar.size()];
		for(int x = 0;x<ar.size();x++)
			i[x]=ar.get(x);
		return i;
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class C071 {
	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(r.readLine());
		StringTokenizer st = new StringTokenizer(r.readLine());
		int[] facs = facs(n);
		int[] ar = new int[n];
		for(int x =0;x<n;x++)
			ar[x]=Integer.parseInt(st.nextToken());
		for (int p:facs) {
			boolean[] ad = new boolean[p];
			if (2*p>=n) continue;
			for(int x=0;x<n;x++)
				if(ar[x]==0) {
					ad[x%p] = true;
				}
			for(int x =0;x<p;x++) {
				if(!ad[x]) {
					System.out.println("YES");
					return;
				}
			}

		}
		System.out.println("NO");

	}
	static int[] facs(int a) {
		ArrayList<Integer> ar = new ArrayList<Integer>();
		ar.add(1);
		for(int x = 2;x<=a;x++) {
			if(a%x==0) {
				while(a%x==0) {
					a/=x;
				}
				ar.add(x);
			}
		}

		int[] i = new int[ar.size()];
		for(int x = 0;x<ar.size();x++)
			i[x]=ar.get(x);
		return i;
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class C071 {
	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(r.readLine());
		StringTokenizer st = new StringTokenizer(r.readLine());
		int[] facs = facs(n);
		int[] ar = new int[n];
		for(int x =0;x<n;x++)
			ar[x]=Integer.parseInt(st.nextToken());
		for (int p:facs) {
			boolean[] ad = new boolean[p];
			for(int x=0;x<n;x++)
				if(ar[x]==0) {
					ad[x%p] = true;
				}
			for(int x =0;x<p;x++) {
				if(!ad[x]) {
					System.out.println("YES");
					return;
				}
			}

		}
		System.out.println("NO");

	}
	static int[] facs(int a) {
		ArrayList<Integer> ar = new ArrayList<Integer>();
		for(int x = 1;x*2<a;x++) {
			if(a%x==0) {
				ar.add(x);
			}
		}

		int[] i = new int[ar.size()];
		for(int x = 0;x<ar.size();x++)
			i[x]=ar.get(x);
		return i;
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = s; j < n - s; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i < sqrt(n) + 3; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}

			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = s; j < n - s; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i <= n / 3; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}

			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = i; j < n - i; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i <= sqrt(n) + 3; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}

			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = s; j < n; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i <= sqrt(n) + 3; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}

			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = i; j < n; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i < n; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}
			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = s; j <= n - s; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i <= sqrt(n) + 3; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}

			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = s; j < n - s; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i < sqrt(n) + 5; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}

			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;

@SuppressWarnings("unused")
public class Main implements Runnable {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter out;
	static String file = "";

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(new FileWriter("1.txt"));
		new Main().run();
		out.close();
	}

	@Override
	public void run() {
		solve();
	}

	String ns() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		} catch (Exception ex) {
			return null;
		}
	}

	String nline() {
		st = null;
		try {
			return br.readLine();
		} catch (Exception ex) {
			return null;
		}
	}

	int ni() {
		return Integer.parseInt(ns());
	}

	long nl() {
		return Long.parseLong(ns());
	}

	double nd() {
		return Double.parseDouble(ns());
	}

	int[] mas;
	int n;

	boolean check(int z) {
		int s = n / z;
		for (int i = 0; i < s; i++) {
			boolean f = true;
			for (int j = s; j < n - s; j += s) {
				if (mas[j] == 0) {
					f = false;
					break;
				}
			}
			if (f) {
				return true;
			}
		}
		return false;
	}

	void solve() {
		n = ni();
		mas = new int[n];
		for (int i = 0; i < n; i++) {
			mas[i] = ni();
		}

		for (int i = 1; i < sqrt(n) + 3; i++) {
			if (n % i == 0) {
				int z = n / i;
				if (z < 3) {
					break;
				}
				if (check(z)) {
					out.print("YES");
					return;
				}

			}
		}
		out.print("NO");
	}

}


import java.util.Arrays;
import java.util.Scanner;

public class Prob071C
{
    public static void main( String[] Args )
    {
        Scanner scan = new Scanner( System.in );
        int knights = scan.nextInt();
        int[] mood = new int[knights];

        for ( int i = 0; i < knights; i++ )
            mood[i] = scan.nextInt();

        boolean[] isPrime = new boolean[1000000];
        Arrays.fill( isPrime, true );
        isPrime[0] = false;
        isPrime[1] = false;
        for ( int i = 2; i < isPrime.length; i++ )
            if ( isPrime[i] )
                for ( int j = 2; i * j < isPrime.length; j++ )
                    isPrime[i * j] = false;
        isPrime[4] = true;

        boolean possible = false;
        all: for ( int i = 3; i <= knights; i++ )
            if ( isPrime[i] && knights % i == 0 )
                for ( int j = 0; j < knights / i; j++ )
                {
                    possible = true;
                    for ( int k = 0; k < i; k++ )
                    {
                        if ( mood[k + j * knights / i] == 0 )
                            possible = false;
                    }
                    if ( possible )
                        break all;
                }

        if ( possible )
            System.out.println( "YES" );
        else
            System.out.println( "NO" );
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Prob071C
{
    public static void main( String[] Args )
    {
        Scanner scan = new Scanner( System.in );
        int knights = scan.nextInt();
        int[] mood = new int[knights];

        for ( int i = 0; i < knights; i++ )
            mood[i] = scan.nextInt();

        boolean[] isPrime = new boolean[1000000];
        Arrays.fill( isPrime, true );
        isPrime[0] = false;
        isPrime[1] = false;
        for ( int i = 2; i < isPrime.length; i++ )
            if ( isPrime[i] )
                for ( int j = 2; i * j < isPrime.length; j++ )
                    isPrime[i * j] = false;
        isPrime[4] = true;

        boolean possible = false;
        all: for ( int i = 3; i <= knights; i++ )
            if ( isPrime[i] && knights % i == 0 )
                for ( int j = 0; j < knights / i; j++ )
                {
                    possible = true;
                    for ( int k = 0; k < i; k++ )
                        if ( mood[j + k * knights / i] == 0 )
                            possible = false;

                    if ( possible )
                        break all;
                }

        if ( possible )
            System.out.println( "YES" );
        else
            System.out.println( "NO" );
    }
}


import java.util.Scanner;

public class C {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);

        int n=in.nextInt();
        boolean[] mas=new boolean[n];

        for(int i=0;i<n;i++){
            if(in.nextInt()==1)
                mas[i]=true;
        }

        boolean[] isNotProst=func(n);

        for(int i=3;i<=n;i++){
            if(isNotProst[i-1] || n%i!=0)
                continue;

            boolean[] notTrue=new boolean[n/i];
            for(int j=0;j<i;j++){
                for(int l=0;l<n/i;l++){
                    if(!mas[(j*n)/i+l])
                        notTrue[l]=true;
                }
            }

            for(int j=0;j<n/i;j++)
                if(notTrue[j]==false){
                    System.out.println("YES");
                    return;
                }
        }

        System.out.println("NO");
    }

    public static boolean[] func(int n){
        boolean[] mas=new boolean[n];

        for(int i=3;i*i<=n;i++){
            if(mas[i-1]){
                for(int j=i*i;j<=n;j+=i)
                    mas[j-1]=true;
            }
        }

        return mas;
    }

}


import java.util.Scanner;

public class C {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);

        int n=in.nextInt();
        boolean[] mas=new boolean[n];

        for(int i=0;i<n;i++){
            if(in.nextInt()==1)
                mas[i]=true;
        }

        boolean[] isNotProst=func(n);

        for(int i=3;i<=n;i++){
            if(isNotProst[i-1] || n%i!=0)
                continue;

            boolean[] notTrue=new boolean[n/i];
            for(int j=0;j<i;j++){
                for(int l=0;l<n/i;l++){
                    if(!mas[j*(n/i)+l])
                        notTrue[l]=true;
                }
            }

            for(int j=0;j<n/i;j++)
                if(notTrue[j]==false){
                    System.out.println("YES");
                    return;
                }
        }

        System.out.println("NO");
    }

    public static boolean[] func(int n){
        boolean[] mas=new boolean[n];

        for(int i=3;i*i<=n;i++){
            if(mas[i-1]){
                for(int j=i*i;j<=n;j+=i)
                    mas[j-1]=true;
            }
        }

        return mas;
    }

}


import java.util.*;
import java.io.*;
public class C65C{
    static BufferedReader br;
    public static void main(String args[])throws Exception{
        br=new BufferedReader(new InputStreamReader(System.in));
        int n=toInt();
        int nm[]=toIntArray();
        //for(int i=0;i<10000;i++){
        //    System.out.print("1 ");
        //}
        for(int i=1;i<=n;i++){
            int count=0;
            if(n/i<3) break;
            if(n%i==0 && n/i>=3){
                //System.out.println("i:"+i);
                for(int j=0;j<n;j+=i){
                    if(nm[j]==1){
                        count++;
                    }

                }
                //System.out.println("count: "+count);

                if(count==n/i){
                    System.out.println("YES");
                    return;
                }
            }

        }

        System.out.println("NO");

    }

    /****************************************************************/
    public static int[] toIntArray()throws Exception{
       String str[]=br.readLine().split(" ");
       int k[]=new int[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Integer.parseInt(str[i]);
       }
       return k;
    }
    public static int toInt()throws Exception{
       return Integer.parseInt(br.readLine());
    }
    public static String toStr()throws Exception{
       return br.readLine();
    }
    public static String[] toStrArray()throws Exception{
       String str[]=br.readLine().split(" ");
       return str;
    }
    /****************************************************************/

}


import java.util.*;
import java.io.*;
public class C65C{
    static BufferedReader br;
    public static void main(String args[])throws Exception{
        br=new BufferedReader(new InputStreamReader(System.in));
        int n=toInt();
        int nm[]=toIntArray();
        for(int i=1;i<=n;i++){
            int count=0;
            if(n/i<3) break;
            if(n%i==0 && n/i>=3){
                int k=0;
                while(k<i){
                    count=0;
                    for(int j=k;j<n;j+=i){
                        if(nm[j]==1){
                            count++;
                        }
                        else break;
                    }
                    if(count==n/i){

                        System.out.println("YES");
                        return;
                    }
                    k++;
                }

            }

        }

        System.out.println("NO");

    }

    /****************************************************************/
    public static int[] toIntArray()throws Exception{
       String str[]=br.readLine().split(" ");
       int k[]=new int[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Integer.parseInt(str[i]);
       }
       return k;
    }
    public static int toInt()throws Exception{
       return Integer.parseInt(br.readLine());
    }
    public static String toStr()throws Exception{
       return br.readLine();
    }
    public static String[] toStrArray()throws Exception{
       String str[]=br.readLine().split(" ");
       return str;
    }
    /****************************************************************/

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class C71 {

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(
            new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);

    static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    public static void main(String[] args) throws Exception {
        int n = nextInt();
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++)
            b[i] = nextInt() == 1;
        for (int d = 3; d <= n; d++) if (n%d == 0) {
            int k = n/d;
            L : for (int i = 0; i < k; i++) {
                for (int j = i; j < n; j += k)
                    if (!b[j]) continue L;
                out.println("YES");
                out.flush();
                return;
            }
        }

        out.println("NO");
        out.flush();
    }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class C implements Runnable {

	final static int MAXP = 100001;
	final static int[] p;

	static {
		p = new int[MAXP];
		for (int i = 2; i * i < MAXP; i++) {
			if (p[i] == 0) {
				for (int j = i * i; j < MAXP; j += i) {
					p[j] = i;
				}
			}
		}
	}

	void solve() {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		HashSet<Integer> primes = new HashSet<Integer>();
		for (int i = n; ; i /= p[i]) {
			if (p[i] == 0) {
				primes.add(i);
				break;
			}
			primes.add(p[i]);
		}
		primes.remove(2);
		if ((n & 3) == 0) {
			primes.add(4);
		}
		for (int i : primes) {
			int k = n / i;
			for (int j = 0; j < k; j++) {
				boolean can = true;
				for (int t = j; t < n; t += k) {
					if (a[t] == 0) {
						can = false;
						break;
					}
				}
				if (can) {
					out.println("YES");
					return;
				}
			}
		}
		out.println("NO");
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	BigInteger nextBigInteger() {
		return sc.nextBigInteger();
	}

	class FastScanner extends BufferedReader {
		StringTokenizer st;
		boolean eof;
		String buf;
		String curLine;
		boolean createST;

		public FastScanner(String fileName) throws FileNotFoundException {
			this(fileName, true);
		}

		public FastScanner(String fileName, boolean createST)
				throws FileNotFoundException {
			super(new FileReader(fileName));
			this.createST = createST;
			nextToken();
		}

		public FastScanner(InputStream stream) {
			this(stream, true);
		}

		public FastScanner(InputStream stream, boolean createST) {
			super(new InputStreamReader(stream));
			this.createST = createST;
			nextToken();
		}

		String nextLine() {
			String ret = curLine;
			if (createST) {
				st = null;
			}
			nextToken();
			return ret;
		}

		String nextToken() {
			if (!createST) {
				try {
					curLine = readLine();
				} catch (Exception e) {
					eof = true;
				}
				return null;
			}
			while (st == null || !st.hasMoreTokens()) {
				try {
					curLine = readLine();
					st = new StringTokenizer(curLine);
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(nextToken());
		}

		public void close() {
			try {
				buf = null;
				st = null;
				curLine = null;
				super.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	public static void main(String[] args) {
		new C().run();
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

/**
 * @author Egor Kulikov (egor@egork.net)
 * @author Alexey Safronov (safronov.aa@gmail.com)
 */
public class Round65 {
        @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
        private InputReader in;
        private PrintWriter out;

        private void solve() {
                int N = in.readInt();
                int[] A = new int[N];
                for(int i = 0; i < N; i++) {
                        A[i] = in.readInt();
                }

                ArrayList<Integer> dels = new ArrayList<Integer>();

                for(int i = 3; i <= N; i++) {
                        if(N % i == 0) {
                                boolean ok = true;

                              //  for(int del : dels) {
                                   //     if(N % del == 0) {
                                //               // ok = false;
                                              //  break;
                                ///        }
                                //}

                                if(ok) {
                                        dels.add(i);
                                }
                        }
                }

                for(int del : dels) {
                        for(int i = 0; i < N; i++) {
                                if(A[i] == 0) {
                                        continue;
                                }

                                boolean ok = true;

                                int counter = 1;
                                int current = (i + (N / del)) % N;

                                while(counter < del) {
                                        if(A[current] == 0) {
                                                break;
                                        }

                                        ++counter;
                                        current = (current + (N / del)) % N;
                                }

                                if(counter == del) {
                                        out.println("YES");
                                        return;
                                }
                        }
                }

                out.println("NO");
        }

        public static void main(String[] args) {
                new Round65().run();
        }

        private Round65() {
                @SuppressWarnings({"UnusedDeclaration"})
                String id = getClass().getName().toLowerCase();
                //noinspection EmptyTryBlock
                try {
//                      System.setIn(new FileInputStream(id + ".in"));
//                      System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//                      System.setIn(new FileInputStream("input.txt"));
//                      System.setOut(new PrintStream(new FileOutputStream("output.txt")));
                } catch (Exception e) {
                        throw new RuntimeException(e);
                }
                in = new InputReader(System.in);
                out = new PrintWriter(System.out);
        }

        private void run() {
                //noinspection InfiniteLoopStatement
//              int testCount = in.readInt();
//              for (int i = 0; i < testCount; i++)
//              while (true)
                solve();
                exit();
        }

        @SuppressWarnings({"UnusedDeclaration"})
        private void exit() {
                out.close();
                System.exit(0);
        }

        @SuppressWarnings({"UnusedDeclaration"})
        private static class InputReader {
                private InputStream stream;
                private byte[] buf = new byte[1024];
                private int curChar, numChars;

                public InputReader(InputStream stream) {
                        this.stream = stream;
                }

                public int read() {
                        if (numChars == -1)
                                throw new InputMismatchException();
                        if (curChar >= numChars) {
                                curChar = 0;
                                try {
                                        numChars = stream.read(buf);
                                } catch (IOException e) {
                                        throw new InputMismatchException();
                                }
                                if (numChars <= 0)
                                        return -1;
                        }
                        return buf[curChar++];
                }

                public int readInt() {
                        int c = read();
                        while (isSpaceChar(c))
                                c = read();
                        int sgn = 1;
                        if (c == '-') {
                                sgn = -1;
                                c = read();
                        }
                        int res = 0;
                        do {
                                if (c < '0' || c > '9')
                                        throw new InputMismatchException();
                                res *= 10;
                                res += c - '0';
                                c = read();
                        } while (!isSpaceChar(c));
                        return res * sgn;
                }

                public long readLong() {
                        int c = read();
                        while (isSpaceChar(c))
                                c = read();
                        int sgn = 1;
                        if (c == '-') {
                                sgn = -1;
                                c = read();
                        }
                        long res = 0;
                        do {
                                if (c < '0' || c > '9')
                                        throw new InputMismatchException();
                                res *= 10;
                                res += c - '0';
                                c = read();
                        } while (!isSpaceChar(c));
                        return res * sgn;
                }

                public String readString() {
                        int c = read();
                        while (isSpaceChar(c))
                                c = read();
                        StringBuffer res = new StringBuffer();
                        do {
                                res.appendCodePoint(c);
                                c = read();
                        } while (!isSpaceChar(c));
                        return res.toString();
                }

                private boolean isSpaceChar(int c) {
                        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
                }

                private String readLine0() {
                        StringBuffer buf = new StringBuffer();
                        int c = read();
                        while (c != '\n' && c != -1) {
                                if (c != '\r')
                                        buf.appendCodePoint(c);
                                c = read();
                        }
                        return buf.toString();
                }

                public String readLine() {
                        String s = readLine0();
                        while (s.trim().length() == 0)
                                s = readLine0();
                        return s;
                }

                public String readLine(boolean ignoreEmptyLines) {
                        if (ignoreEmptyLines)
                                return readLine();
                        else
                                return readLine0();
                }

                public BigInteger readBigInteger() {
                        try {
                                return new BigInteger(readString());
                        } catch (NumberFormatException e) {
                                throw new InputMismatchException();
                        }
                }

                public char readCharacter() {
                        int c = read();
                        while (isSpaceChar(c))
                                c = read();
                        return (char) c;
                }

                public double readDouble() {
                        int c = read();
                        while (isSpaceChar(c))
                                c = read();
                        int sgn = 1;
                        if (c == '-') {
                                sgn = -1;
                                c = read();
                        }
                        double res = 0;
                        while (!isSpaceChar(c) && c != '.') {
                                if (c == 'e' || c == 'E')
                                        return res * Math.pow(10, readInt());
                                if (c < '0' || c > '9')
                                        throw new InputMismatchException();
                                res *= 10;
                                res += c - '0';
                                c = read();
                        }
                        if (c == '.') {
                                c = read();
                                double m = 1;
                                while (!isSpaceChar(c)) {
                                        if (c == 'e' || c == 'E')
                                                return res * Math.pow(10, readInt());
                                        if (c < '0' || c > '9')
                                                throw new InputMismatchException();
                                        m /= 10;
                                        res += (c - '0') * m;
                                        c = read();
                                }
                        }
                        return res * sgn;
                }

                public int[] readIntArray(int size) {
                        int[] array = new int[size];
                        for (int i = 0; i < size; i++)
                                array[i] = readInt();
                        return array;
                }

                public long[] readLongArray(int size) {
                        long[] array = new long[size];
                        for (int i = 0; i < size; i++)
                                array[i] = readLong();
                        return array;
                }

                public double[] readDoubleArray(int size) {
                        double[] array = new double[size];
                        for (int i = 0; i < size; i++)
                                array[i] = readDouble();
                        return array;
                }

                public String[] readStringArray(int size) {
                        String[] array = new String[size];
                        for (int i = 0; i < size; i++)
                                array[i] = readString();
                        return array;
                }

                public char[][] readTable(int rowCount, int columnCount) {
                        char[][] table = new char[rowCount][columnCount];
                        for (int i = 0; i < rowCount; i++) {
                                for (int j = 0; j < columnCount; j++)
                                        table[i][j] = readCharacter();
                        }
                        return table;
                }

                public void readIntArrays(int[]... arrays) {
                        for (int i = 0; i < arrays.length; i++) {
                                for (int j = 0; j < arrays[0].length; j++)
                                        arrays[i][j] = readInt();
                        }
                }
        }
}


import java.io.*;
import java.math.*;
import java.util.*;

/**
 * @author Egor Kulikov (egor@egork.net)
 * @author Alexey Safronov (safronov.aa@gmail.com)
 */
public class Round65 {
	@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
	private InputReader in;
	private PrintWriter out;

	private void solve() {
		int N = in.readInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = in.readInt();
		}

		ArrayList<Integer> dels = new ArrayList<Integer>();

		for(int i = 3; i <= N; i++) {
			if(N % i == 0) {
				boolean ok = true;

				for(int del : dels) {
					if(N % del == 0) {
						ok = false;
						break;
					}
				}

				if(ok) {
					dels.add(i);
				}
			}
		}

		for(int del : dels) {
			for(int i = 0; i < N; i++) {
				if(A[i] == 0) {
					continue;
				}

				boolean ok = true;

				int counter = 1;
				int current = (i + (N / del)) % N;

				while(counter < del) {
					if(A[current] == 0) {
						break;
					}

					++counter;
					current = (current + (N / del)) % N;
				}

				if(counter == del) {
					out.println("YES");
					return;
				}
			}
		}

		out.println("NO");
	}

	public static void main(String[] args) {
		new Round65().run();
	}

	private Round65() {
		@SuppressWarnings({"UnusedDeclaration"})
		String id = getClass().getName().toLowerCase();
		//noinspection EmptyTryBlock
		try {
//			System.setIn(new FileInputStream(id + ".in"));
//			System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//			System.setIn(new FileInputStream("input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	private void run() {
		//noinspection InfiniteLoopStatement
//		int testCount = in.readInt();
//		for (int i = 0; i < testCount; i++)
//		while (true)
		solve();
		exit();
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private void exit() {
		out.close();
		System.exit(0);
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar, numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public int[] readIntArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = readInt();
			return array;
		}

		public long[] readLongArray(int size) {
			long[] array = new long[size];
			for (int i = 0; i < size; i++)
				array[i] = readLong();
			return array;
		}

		public double[] readDoubleArray(int size) {
			double[] array = new double[size];
			for (int i = 0; i < size; i++)
				array[i] = readDouble();
			return array;
		}

		public String[] readStringArray(int size) {
			String[] array = new String[size];
			for (int i = 0; i < size; i++)
				array[i] = readString();
			return array;
		}

		public char[][] readTable(int rowCount, int columnCount) {
			char[][] table = new char[rowCount][columnCount];
			for (int i = 0; i < rowCount; i++) {
				for (int j = 0; j < columnCount; j++)
					table[i][j] = readCharacter();
			}
			return table;
		}

		public void readIntArrays(int[]... arrays) {
			for (int i = 0; i < arrays.length; i++) {
				for (int j = 0; j < arrays[0].length; j++)
					arrays[i][j] = readInt();
			}
		}
	}
}


import java.util.*;

public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   ArrayList<Integer> genPrimes(int N)
   {
      boolean[] isPrime = new boolean[N+1];
      Arrays.fill(isPrime, true);
      isPrime[0] = false;
      isPrime[1] = false;
      for (int i=2; i<=N; i++)
         if (isPrime[i])
            for (long j = i*1L*i; j<=N; j+=i)
               isPrime[(int)j] = false;

      ArrayList<Integer> primes = new ArrayList<Integer>();
      for (int i=3; i<=N; i++)
         if (isPrime[i])
            primes.add(i);
      if (4 <= N)
         primes.add(4);
      return primes;
   }

   public C(Scanner in)
   {
      int N = in.nextInt();
      boolean[] vs = new boolean[N];
      for (int i=0; i<N; i++)
         vs[i] = (in.nextInt() == 1);

      ArrayList<Integer> primes = genPrimes(N);
      ArrayList<Integer> rs = new ArrayList<Integer>();
      for (int p : primes)
         if ((N%p) == 0)
            rs.add(p);

      boolean passed = false;
      for (int p : rs)
      {
         int q = N/p;
         boolean[] table = new boolean[q];
         Arrays.fill(table, true);
         for (int i=0; i<N; i++)
         {
            int j = i%q;
            table[j] = table[j] && vs[i];
         }

         for (int i=0; i<q; i++)
            if (table[i])
               passed = true;
      }

      System.out.println(passed?"YES":"NO");
   }
}


import java.io.*;
import java.util.ArrayList;
import java.util.*;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        for (int i = 3; i <= n; i++) {
            if (!m[i]) {
                primes.add(i);
            }
        }
        primes.add(Math.min(n, 4));
        Collections.sort(primes);
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        for (int i = 3; i <= n; i++) {
            if (!m[i]) {
                primes.add(i);
            }
        }
        primes.add(Math.min(n, 4));
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        if (n >= 4) {
            m[4] = true;
        }
        for (int i = 3; i <= n; i++) {
            if (!m[i] && n % i == 0) {
                int other = n / i;
                if (other < 3 || i < other) {
                    primes.add(i);
                }
            }
        }
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        if (n <= 4) {
            m[4] = true;
        }
        for (int i = 3; i <= n; i++) {
            if (!m[i] && n % i == 0) {
                int other = n / i;
                if (other < 3 || i < other) {
                    primes.add(i);
                }
            }
        }
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        for (int i = 3; i <= n; i++) {
            if (!m[i]) {
                primes.add(i);
            }
        }
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        for (int i = 3; i <= n; i++) {
            if (!m[i]) {
                primes.add(i);
            }
        }
        primes.add(n);
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        for (int i = 3; i <= n; i++) {
            if (!m[i]) {
                primes.add(i);
            }
        }
        primes.add(4);
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import org.omg.CORBA.PRIVATE_MEMBER;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    static final boolean DEBUG = false;

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(DEBUG ? new FileInputStream("input.txt") : System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n + n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
            ok[n + i] = ok[i];
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        for (int i = 3; i <= n; i++) {
            primes.add(i);
        }
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = -1;
        for (int i = ok.length - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            } else if (i < n) {
                next[i] = lastGoodInd;
            }
        }
        if (lastGoodInd == -1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            p[0] = 0;
            final int delta = n / k;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        new C().solve();
    }

    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    void solve() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        boolean[] ok = new boolean[n];
        for (int i = 0; i < n; i++) {
            ok[i] = nextInt() == 1;
        }
        br.close();
        boolean res = find(n, ok);
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res ? "YES" : "NO");
        pw.close();
    }

    List<Integer> findPrimes(int n) {
        boolean[] m = new boolean[n + 1];
        int up = Math.min(n, (int) Math.sqrt(n + 1));
        for (int i = 2; i <= up; i++) {
            if (!m[i]) {
                int j = i + i;
                while (j <= n) {
                    m[j] = true;
                    j += i;
                }
            }
        }
        List<Integer> primes = new ArrayList<Integer>();
        for (int i = 3; i <= n; i++) {
            if (!m[i]) {
                primes.add(i);
            }
        }
        primes.add(Math.min(n, 4));
        Collections.sort(primes);
        return primes;
    }

    boolean find(int n, boolean[] ok) {
        List<Integer> primes = findPrimes(n);
        int[] next = new int[n];
        int lastGoodInd = n + 1;
        for (int i = n - 1; i >= 0; i--) {
            if (ok[i]) {
                lastGoodInd = i;
            }
            next[i] = lastGoodInd;
        }
        if (lastGoodInd == n + 1) {
            return false;
        }
        int[] p = new int[primes.get(primes.size() - 1)];
        for (int k : primes) {
            if (n % k != 0) {
                continue;
            }
            final int delta = n / k;
            p[0] = 0;
            for (int i = 1; i < k; i++) {
                p[i] = p[i - 1] + delta;
            }
            while (p[0] < delta) {
                int max = 0;
                for (int i = 0; i < k; i++) {
                    final int nextInd = p[i] + max;
                    if (nextInd >= n) {
                        break;
                    }
                    if (!ok[nextInd]) {
                        max = Math.max(max, next[nextInd] - p[i]);
                        if (max >= delta) {
                            break;
                        }
                    }
                }
                if (max == 0) {
                    return true;
                }
                for (int i = 0; i < k; i++) {
                    p[i] += max;
                }
            }
        }
        return false;
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}