#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
        {
            if(n%i==0 && n/i>=3)
            {
                for(int k=0;k<i;k++)
                {
                    int z=1;
                    for(int u=k;u<n;u=u+i)
                    {
                        z=z&a[u];
                        if(z==0)
                        {
                            break;
                        }

                    }
                    if(z)
                    {
                        cout<<"YES";
                        return 0;
                    }

                }
            }

        }
        cout<<"NO";
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <ctime>
#include <cmath>
#include <vector>
#include <map>
#include <climits>
#include <set>
#include <stack>
#include <queue>
#include <sstream>
#include <functional>
using namespace std;
typedef vector<int> VI;
typedef map<string, int> MSI;
typedef map<int, int> MII;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define F(i,n)                      for(int i=0;i<(n);++i)
#define FOR(i,x,y)                  for(int i=(x);i<=(y);++i)
#define FD(i,n)                     for(int i=(n-1);i>=0;--i)
#define FORD(i,y,x)                 for(int i=(y);i>=(x);--i)
#define MEM(x,i)                    memset(x,i,sizeof(x))
#define mp                          make_pair
#define db(a)                       cout<<(a)<<endl
#define whatis(a)                   cout<<#a<<" is "<<a<<endl
#define bug                         puts("here!!!")
#define fi                          first
#define se                          second
#define pb                          push_back
#define sz(a)                       ((int)(a.size()))
#define s(n)                        scanf("%d",&(n))
#define sc(n)                       scanf("%c",&(n))
#define sf(n)                       scanf("%lf",&(n))
#define ss(n)                       scanf("%s",(n))
// #define              LOCAL
#ifdef LOCAL
#define LLD                         "%lld"
#else
#define LLD                         "%I64d"
#endif
#define sl(n)                       scanf(LLD,&(n))

const int N = 100010;
int n;
bool a[N], vis[N];

int main() { _
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    s(n);
    bool yes = true;
    F(i, n)  {
        s(a[i]);
        yes &= a[i];
    }
    if (!yes) {
        int j, t;
        FOR (i, 3, n) {
            if (!vis[i] && n % i == 0) {
                j = n / i;
                yes = true;

                F(k, j) {
                    t = k;

                    while (t < n) {
                        // whatis(t), whatis(a[t]), whatis(yes);
                        yes &= a[t];
                        t += j;
                    }
                    if (yes) break;
                }
                if (yes) break;
                int k = i;
                while (k < n) {
                    vis[k] = true;
                    k += k;
                }
            }
        }
    }
    printf("%s", yes ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <ctime>
#include <cmath>
#include <vector>
#include <map>
#include <climits>
#include <set>
#include <stack>
#include <queue>
#include <sstream>
#include <functional>
using namespace std;
typedef vector<int> VI;
typedef map<string, int> MSI;
typedef map<int, int> MII;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define F(i,n)                      for(int i=0;i<(n);++i)
#define FOR(i,x,y)                  for(int i=(x);i<=(y);++i)
#define FD(i,n)                     for(int i=(n-1);i>=0;--i)
#define FORD(i,y,x)                 for(int i=(y);i>=(x);--i)
#define MEM(x,i)                    memset(x,i,sizeof(x))
#define mp                          make_pair
#define db(a)                       cout<<(a)<<endl
#define whatis(a)                   cout<<#a<<" is "<<a<<endl
#define bug                         puts("here!!!")
#define fi                          first
#define se                          second
#define pb                          push_back
#define sz(a)                       ((int)(a.size()))
#define s(n)                        scanf("%d",&(n))
#define sc(n)                       scanf("%c",&(n))
#define sf(n)                       scanf("%lf",&(n))
#define ss(n)                       scanf("%s",(n))
// #define              LOCAL
#ifdef LOCAL
#define LLD                         "%lld"
#else
#define LLD                         "%I64d"
#endif
#define sl(n)                       scanf(LLD,&(n))
const int N = 100010;
int n;
bool a[N];

int main() { _
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    s(n);
    bool yes = true;
    F(i, n)  {
        s(a[i]);
        yes &= a[i];
    }
    if (!yes) {
        int j, t, i = 3, tn = n;
        while (i <= tn) {
            if (tn % i == 0) {
            	// whatis(i);
                j = n / i;
                F(k, j) {
                    t = k;
                    yes = true;
                    while (t < n) {
                        // whatis(t), whatis(a[t]), whatis(yes);
                        yes &= a[t];
                        t += j;
                    }
                    if (yes) break;
                }
                if (yes) break;
                while (tn % i == 0) tn /= i;
            }
            i++;
        }
    }
    printf("%s", yes ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <ctime>
#include <cmath>
#include <vector>
#include <map>
#include <climits>
#include <set>
#include <stack>
#include <queue>
#include <sstream>
#include <functional>
using namespace std;
typedef vector<int> VI;
typedef map<string, int> MSI;
typedef map<int, int> MII;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define F(i,n)                      for(int i=0;i<(n);++i)
#define FOR(i,x,y)                  for(int i=(x);i<=(y);++i)
#define FD(i,n)                     for(int i=(n-1);i>=0;--i)
#define FORD(i,y,x)                 for(int i=(y);i>=(x);--i)
#define MEM(x,i)                    memset(x,i,sizeof(x))
#define mp                          make_pair
#define db(a)                       cout<<(a)<<endl
#define whatis(a)                   cout<<#a<<" is "<<a<<endl
#define bug                         puts("here!!!")
#define fi                          first
#define se                          second
#define pb                          push_back
#define sz(a)                       ((int)(a.size()))
#define s(n)                        scanf("%d",&(n))
#define sc(n)                       scanf("%c",&(n))
#define sf(n)                       scanf("%lf",&(n))
#define ss(n)                       scanf("%s",(n))
// #define              LOCAL
#ifdef LOCAL
#define LLD                         "%lld"
#else
#define LLD                         "%I64d"
#endif
#define sl(n)                       scanf(LLD,&(n))

const int N = 100010;
int n;
bool a[N], vis[N];

int main() { _
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    s(n);
    bool yes = true;
    F(i, n)  {
        s(a[i]);
        yes &= a[i];
    }
    if (!yes) {
        int j, t;
        FOR (i, 3, n-1) {
            if (!vis[i] && n % i == 0) {
                // whatis(i);
                j = n / i;

                F(k, j) {
                    t = k;
                    yes = true;
                    while (t < n) {
                        // whatis(t), whatis(a[t]), whatis(yes);
                        yes &= a[t];
                        t += j;
                    }
                    if (yes) break;
                }
                if (yes) break;
                int k = i;
                while (k < n) {
                    vis[k] = true;
                    k += k;
                }
            }
        }
    }
    printf("%s", yes ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <ctime>
#include <cmath>
#include <vector>
#include <map>
#include <climits>
#include <set>
#include <stack>
#include <queue>
#include <sstream>
#include <functional>
using namespace std;
typedef vector<int> VI;
typedef map<string, int> MSI;
typedef map<int, int> MII;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define F(i,n)                      for(int i=0;i<(n);++i)
#define FOR(i,x,y)                  for(int i=(x);i<=(y);++i)
#define FD(i,n)                     for(int i=(n-1);i>=0;--i)
#define FORD(i,y,x)                 for(int i=(y);i>=(x);--i)
#define MEM(x,i)                    memset(x,i,sizeof(x))
#define mp                          make_pair
#define db(a)                       cout<<(a)<<endl
#define whatis(a)                   cout<<#a<<" is "<<a<<endl
#define bug                         puts("here!!!")
#define fi                          first
#define se                          second
#define pb                          push_back
#define sz(a)                       ((int)(a.size()))
#define s(n)                        scanf("%d",&(n))
#define sc(n)                       scanf("%c",&(n))
#define sf(n)                       scanf("%lf",&(n))
#define ss(n)                       scanf("%s",(n))
// #define              LOCAL
#ifdef LOCAL
#define LLD                         "%lld"
#else
#define LLD                         "%I64d"
#endif
#define sl(n)                       scanf(LLD,&(n))

const int N = 100010;
int n;
bool a[N];

int main() { _
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    s(n);
    bool yes = true;
    F(i, n)  {
        s(a[i]);
        yes &= a[i];
    }
    if (!yes) {
        int j, t;
        FOR (i, 3, n-1) {
            if (n % i == 0) {
                // whatis(i);
                j = n / i;

                F(k, j) {
                    t = k;
                    yes = true;
                    while (t < n) {
                        // whatis(t), whatis(a[t]), whatis(yes);
                        yes &= a[t];
                        t += j;
                    }
                    if (yes) break;
                }
                if (yes) break;
                while (n % i == 0) n /= i;
            }
        }
    }
    printf("%s", yes ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

bool find_figure(int k, vector <int> &v){
	int size = v.size();
	vector <int> tail(k);
	int counter = 0;
	for(int i = 0; i < size; i++){
		if(tail[v[i] % k] == 0){
			tail[v[i] % k] = 1;
			counter++;
			if(counter == k){
				return false;
			}
		}
	}
	if(counter < k){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int n;
	cin >> n;

	vector <int> good, bad;

	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a == 0){
			bad.push_back(i);
		}
	}
	if(bad.empty()){
		cout << "YES\n";
		return 0;
	}

	for(int i = 2; i < sqrt(n); i++){
		if(n % i == 0){
			bool is2 = find_figure(i, bad);
			bool is1 = find_figure(n/i, bad);
			if(is1 || is2){
				cout << "YES\n";
				return 0;
			}

		}
	}
	cout << "NO\n";

}


#include <iostream>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

bool find_figure(int k, vector <int> &v){
	int size = v.size();
	vector <int> tail(k);
	int counter = 0;
	for(int i = 0; i < size; i++){
		if(tail[v[i] % k] == 0){
			tail[v[i] % k] = 1;
			counter++;
			if(counter == k){
				return false;
			}
		}
	}
	if(counter < k){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int n;
	cin >> n;

	vector <int> good, bad;

	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a == 0){
			bad.push_back(i);
		}
	}
	if(bad.empty()){
		cout << "YES\n";
		return 0;
	}
	if(n % 2 == 0){
		if(find_figure(2, bad)){
			cout << "YES\n";
			return 0;
		}
	}
	for(int i = 3; i < sqrt(n); i++){
		if(n % i == 0){
			bool is2 = find_figure(i, bad);
			bool is1 = find_figure(n/i, bad);
			if(is1 || is2){
				cout << "YES\n";
				return 0;
			}

		}
	}
	cout << "NO\n";

}


#include <iostream>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

bool find_figure(int k, vector <int> &v){
	int size = v.size();
	vector <int> tail(k);
	int counter = 0;
	for(int i = 0; i < size; i++){
		if(tail[v[i] % k] == 0){
			tail[v[i] % k] = 1;
			counter++;
			if(counter == k){
				return false;
			}
		}
	}
	if(counter < k){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int n;
	cin >> n;

	vector <int> good, bad;

	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a == 0){
			bad.push_back(i);
		}
	}
	if(bad.empty()){
		cout << "YES\n";
		return 0;
	}
	for(int i = 2; i < sqrt(n); i++){
		if(n % i == 0 && n/i != 2){
			bool is2 = find_figure(i, bad);
			if(i != 2){
				bool is1 = find_figure(n/i, bad);
				if(is1){
					cout << "YES\n";
					return 0;
				}
			}
			if(is2){
				cout << "YES\n";
				return 0;
			}

		}
	}
	cout << "NO\n";

}


#include <iostream>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

bool find_figure(int k, vector <int> &v){
	int size = v.size();
	vector <int> tail(k);
	int counter = 0;
	for(int i = 0; i < size; i++){
		if(tail[v[i] % k] == 0){
			tail[v[i] % k] = 1;
			counter++;
			if(counter == k){
				return false;
			}
		}
	}
	if(counter < k){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int n;
	cin >> n;

	vector <int> good, bad;

	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a == 0){
			bad.push_back(i);
		}
	}
	if(bad.empty()){
		cout << "YES\n";
		return 0;
	}

	for(int i = 2; i < sqrt(n); i++){
		if(n % i == 0){
			bool is = find_figure(i, bad);
			if(is){
				cout << "YES\n";
				return 0;
			}
		}
	}
	cout << "NO\n";

}


#include <bits/stdc++.h>

using namespace std;

int a[10000];

int main(){

	int n;
	cin >> n;

	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i < n; i ++){
		if(a[i] == 0 && a[i + 1] == 0){
			cout<<"NO";
			return 0;
		}
	}

	cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 100;

int a[maxn];

int main(){

	int n;
	scanf("%d",&n);

	for(int i = 1; i <= n; i ++){
		scanf("%d",&a[i]);
	}

	int c = 0;

	for(int i = 3; i <= n; ++ i){
		if(n % i == 0){
			for(int k = 1; k <= sqrt(n); ++k){
			c = 0;
			for(int j = k; j <= n; j += n / i){
				if(a[j] == 1){
					++c;
				}
			}
			if(c == i){
				puts("YES");
				return 0;
			}
			}
		}
	}
	puts("NO");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 100;

int a[maxn];

int main(){

	int n;
	scanf("%d",&n);

	for(int i = 1; i <= n; i ++){
		scanf("%d",&a[i]);
	}

	int c = 0;

	for(int i = 3; i <= n; ++ i){
		if(n % i == 0){
			for(int k = 1; k <= n / 2; ++k){
			c = 0;
			for(int j = k; j <= n; j += n / i){
				if(a[j] == 1){
					++c;
				}
			}
			if(c == i){
				puts("YES");
				return 0;
			}
			}
		}
	}
	puts("NO");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 100;

int a[maxn];

int main(){

	int n;
	scanf("%d",&n);

	for(int i = 1; i <= n; i ++){
		scanf("%d",&a[i]);
	}

	int c = 0;

	for(int i = 3; i <= n; ++ i){
		if(n % i == 0){
			for(int k = 1; k <= n / i; ++k){
			c = 0;
			for(int j = k; j <= n; j += n / i){
				if(a[j] == 1){
					++c;
				}
			}
			if(c == i){
				puts("YES");
				return 0;
			}
			}
		}
	}
	puts("NO");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 100;

vector<int>g[maxn];
int a[maxn];

int main(){

	int n;
	cin >> n;

	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}

	int c = 0;

	for(int i = 3; i <= n; i ++){
		if(n % i == 0){
			for(int k = 1; k <= n / 2; k ++){
			int c = 0;
			for(int j = k; j <= n; j += n / i){
				if(a[j] == 1){
					c ++;
				}
			}
			if(c == i){
				cout<<"YES";
				return 0;
			}
			}
		}
	}
	cout<<"NO";

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int isGood[100001];
bool goodPath(int n,int v,int k)
{
    for(int i=v;i<n;i+=k)
    {
        if(!isGood[i])
            return false;
    }
    return true;
}
int main ()
{
    int n,k;
    scanf("%d",& n);
    for(int i=0;i<n;++i)
        scanf("%d",isGood+i);
    for(int len=1;len*3<=n;++len)
    {
        if(n%len>0)
            continue;
        for(int i=1;i*3<=n;++i)
        {
            if(goodPath(n,i,len))
            {
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll isGood[10001];
bool goodPath(int n,int v,int k)
{
    for(int i=v;i<n;i+=k)
    {
        if(!isGood[i])
            return false;
    }
    return true;
}
int main ()
{
    ll n,k,chet=0;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>isGood[i];
    for(int len=1;len*3<=n;++len)
    {
        for(int i=0;i*3<n;++i)
        {
            if(goodPath(n,i,len))
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll isGood[100001];
bool goodPath(int n,int v,int k)
{
    for(int i=v;i<n;i+=k)
    {
        if(!isGood[i])
            return false;
    }
    return true;
}
int main ()
{
    ll n,k;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>isGood[i];
    for(int len=1;len*3<=n;++len)
    {
        if(n%len>0)
            continue;
        for(int i=1;i*3<=n;++i)
        {
            if(goodPath(n,i,len))
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll isGood[100001];
bool goodPath(int n,int v,int k)
{
    for(int i=v;i<n;i+=k)
    {
        if(!isGood[i])
            return false;
    }
    return true;
}
int main ()
{
    ll n,k;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>isGood[i];
    for(int len=1;len*3<=n;++len)
    {
        for(int i=0;i*3<n;++i)
        {
            if(goodPath(n,i,len))
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second

using namespace std;
const int N=1e6 ;
int b[50],n,l,bo,ans,sum,mx,k,vis[N];
int a[N] ;
char c ;
vector <  int   >  vec ;
int dp[N][3] ;
main()
{
    int n ;
    cin >> n ;
    vec.push_back(n) ;

    if (n%2==0&&n/2>=3)
        vec.push_back(n/2) ;

    for (int i=3; i<=sqrt(n); i++)
        if (n%i==0)
        {
            vec.push_back(i) ;
            if (n/i>=3)
                vec.push_back(n/i) ;
        }

    for (int i=1; i<=n; i++)
        cin >> a[i] ;

    for (auto x : vec)
    {
            ans=x ;
        for (int i=1; i<=n/ans; i++)
        {
            k=0 ;
            for (int j=i; j<=n; j+=n/ans)
                if (a[j])
                    k++ ;
                else
                    k=0 ;
            if (k>=ans)
            {
                bo=i ;
                goto d ;
            }
        }
    }
    d :
    if (bo)
        cout << "YES" << endl ;
    else
        cout << "NO" << endl ;
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second

using namespace std;
const int N=1e6 ;
int b[50],n,l,bo,ans,sum,mx,k ;
int a[N] ;
char c ;
vector <  int   >  vec ;
int dp[N][3] ;
main()
{
    int n ;
    cin >> n ;
    vec.push_back(n) ;

    if (n%2==0&&n/2>=3)
        vec.push_back(n/2) ;

    for (int i=3; i<=sqrt(n); i++)
        if (n%i==0)
        {
            vec.push_back(i) ;
            if (n/i>=3)
                vec.push_back(n/i) ;
        }

    for (int i=1; i<=n; i++)
        cin >> a[i] ;

    for (auto x : vec)
    {
        for (int i=1; i<=n; i++)
        {
            k=0 ;
            ans=x ;
            for (int j=i; j<=n; j+=n/ans)
                if (a[j])
                    k++ ;
                else
                    k=0 ;
            if (k>=ans)
                bo=i ;
        }
    }

    if (bo)
        cout << "YES" << endl ;
    else
        cout << "NO" << endl ;
}


#include <bits/stdc++.h>
#define int long long
#define F first
#define S second

using namespace std;
const int N=1e6 ;
int b[50],n,l,bo,ans,sum,mx,k ;
int a[N] ;
char c ;
vector < pair < int,int >  >  vec ;
int dp[N][3] ;
main()
{
    int n ;
    cin >> n ;
    ans=n ;
    if (n%2==0&&n/2>=3)
        ans=min(ans,n/2) ;
    for (int i=3; i<=sqrt(n); i++)

        if (n%i==0)
        {
            ans=i ;
            break ;
        }
    for (int i=1; i<=n; i++)

        cin >> a[i] ;

    for (int i=1; i<=n; i++)
    {
        k=0 ;

        for (int j=i; j<=n; j+=n/ans)
        {
            if (a[j])
                k++ ;
            else
                k=0 ;
            if (k>=ans)
                bo=1 ;
        }

    }
    if (bo)
    cout << "YES" << endl ;
    else cout << "NO" << endl ;
}


#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define int long long

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int32_t main()
{
    IO;
    int n;
    cin>>n;
    int a[n],f=n+1,fl=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]) f=min(f,i);
    }
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0){
        for(int l=0;l<i;l++)
        {
            int k=0;
            for(int j=l;j<n;j=j+i)
            {
                k+=a[j];
            }
            if(k==(n/i)) fl=1;
        }}
    }
    if(fl) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define int long long

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int32_t main()
{
    IO;
    int n;
    cin>>n;
    int a[n],f=n+1,fl=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]) f=min(f,i);
    }
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0){
        for(int l=0;l<i;l++)
        {
            int k=0;
            for(int j=l;j<n;j=j+i)
            {
                k+=a[j];
            }
            if(k==(n/i)) fl=1;
        }
        for(int l=0;l<(n/i);l++)
        {
            int k=0;
            for(int j=l;j<n;j=j+(n/i))
            {
                k+=a[j];
            }
            if(k==i) fl=1;
        }
        }
    }
    if(fl) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define int long long

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

int32_t main()
{
    IO;
    int n;
    cin>>n;
    int a[n],f=n+1,fl=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]) f=min(f,i);
    }
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0){
        for(int l=0;l<i;l++)
        {
            int k=0;
            for(int j=l;j<n;j=j+i)
            {
                k+=a[j];
            }
            if((n/i)>=3 && k==(n/i)) fl=1;
        }
        for(int l=0;l<(n/i);l++)
        {
            int k=0;
            for(int j=l;j<n;j=j+(n/i))
            {
                k+=a[j];
            }
            if(i>=3 && k==i) fl=1;
        }
        }
    }
    if(fl) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#pragma comment(linkerr, "/STACK: 1024000000,1024000000")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pii pair<int,int>
#define de(x) cout << #x << " = " << x << endl
#define clr(a,b) memset(a,b,sizeof(a))
#define INF (0x3f3f3f3f)
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))
#define F first
#define S second
using namespace std;

const int N = 1e5 + 15;
int a[N];
int n;

bool chk( int x )
{
	if ( n / x < 3 ) return 0;
	int ed;
	int d = n / x - 1;
	for ( int i = 1; a[i] && i <= d; i ++ )
	{
		ed = 0;
		for ( int j = i; j <= n; j += d )
			if ( a[j] ) ed ++;
		if ( ed >= d ) return 1;
	}
	return 0;
}

int main()
{
	scanf("%d", &n);
	int sm = 0;
	for ( int i = 1; i <= n; i ++ )
		scanf("%d", &a[i]), sm += a[i];
	if ( sm == n )
	{
		puts("YES");
		return 0;
	}
	int e = sqrt(n);
	for ( int i = 2; i <= n; i ++ )
	{
		if ( n % i == 0 )
		{
			if ( chk(i) )
			{
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}


#pragma comment(linkerr, "/STACK: 1024000000,1024000000")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pii pair<int,int>
#define de(x) cout << #x << " = " << x << endl
#define clr(a,b) memset(a,b,sizeof(a))
#define INF (0x3f3f3f3f)
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))
#define F first
#define S second
using namespace std;

const int N = 1e5 + 15;
int a[N];
int n;

bool chk( int x )
{
	if ( x < 3 ) return 0;
	int ed;
	int d = n / x;
	for ( int i = 1; i < d; i ++ )
	{
		if ( a[i] )
		{
			ed = 0;
			for ( int j = i; j <= n; j += d )
				if ( a[j] ) ed ++;
			if ( ed >= x ) return 1;
		}
	}
	return 0;
}

int main()
{
	scanf("%d", &n);
	int sm = 0;
	for ( int i = 1; i <= n; i ++ )
		scanf("%d", &a[i]), sm += a[i];
	if ( sm == n )
	{
		puts("YES");
		return 0;
	}
	int e = sqrt(n);
	for ( int i = 2; i <= e; i ++ )
	{
		if ( n % i == 0 )
		{
			if ( chk(i) || chk(n/i) )
			{
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}


#pragma comment(linkerr, "/STACK: 1024000000,1024000000")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pii pair<int,int>
#define de(x) cout << #x << " = " << x << endl
#define clr(a,b) memset(a,b,sizeof(a))
#define INF (0x3f3f3f3f)
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))
#define F first
#define S second
using namespace std;

const int N = 1e5 + 15;
int a[N];
int n;

bool chk( int x )
{
	if ( x < 3 ) return 0;
	int ed;
	int d = n / x;
	for ( int i = 1; a[i] && i < d; i ++ )
	{
		ed = 0;
		for ( int j = i; j <= n; j += d )
			if ( a[j] ) ed ++;
		if ( ed >= x ) return 1;
	}
	return 0;
}

int main()
{
	scanf("%d", &n);
	int sm = 0;
	for ( int i = 1; i <= n; i ++ )
		scanf("%d", &a[i]), sm += a[i];
	if ( sm == n )
	{
		puts("YES");
		return 0;
	}
	int e = sqrt(n);
	for ( int i = 2; i <= e; i ++ )
	{
		if ( n % i == 0 )
		{
			if ( chk(i) || chk(n/i) )
			{
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}


#pragma comment(linkerr, "/STACK: 1024000000,1024000000")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pii pair<int,int>
#define de(x) cout << #x << " = " << x << endl
#define clr(a,b) memset(a,b,sizeof(a))
#define INF (0x3f3f3f3f)
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))
#define F first
#define S second
using namespace std;

const int N = 1e5 + 15;
int a[N];
int n;

bool chk( int x )
{
	if ( x < 3 ) return 0;
	int ed;
	int d = n / x;
	for ( int i = 1; i <= d; i ++ )
	{
		if ( a[i] )
		{
			ed = 0;
			for ( int j = i; j <= n; j += d )
				if ( a[j] ) ed ++;
			if ( ed >= x ) return 1;
		}
	}
	return 0;
}

int main()
{
	scanf("%d", &n);
	int sm = 0;
	for ( int i = 1; i <= n; i ++ )
		scanf("%d", &a[i]), sm += a[i];
	if ( sm == n )
	{
		puts("YES");
		return 0;
	}
	int e = sqrt(n);
	for ( int i = 2; i <= e; i ++ )
	{
		if ( n % i == 0 )
		{
			if ( chk(i) || chk(n/i) )
			{
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
vector <int>v;
int vis[100005];
int main(){
//	freopen("readin.txt", "r", stdin);
	scanf("%d",&n);
	for(int i=1;i*i<=n;i++){
			if(n%i==0&&n/i>=3){
			v.push_back(i);
	}

	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	bool ans=false;
	int sz=v.size();
	for( int k=0;k<sz;k++){

	int x=v[k];
	for(int i=0;i<x;i++){

	int temp=1;
		for(int j=i;j<n;j+=x){
			if(a[j]==0)
			{
				temp=0;
				break;
			}
		}
		if(temp)
		{
			ans=true;
			//cout<<x<<endl;
			break;
		}
	}
	if(ans)
		break;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
vector <int>v;
int vis[100005];
int main(){
//	freopen("readin.txt", "r", stdin);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		if(vis[i]==1)
			continue;
		else{
			if(n%i==0&&n/i>=3){
			v.push_back(i);
			if(i==1)
				continue;
			for(int j=i+i;j<n;j+=i)
				vis[j]=1;
			}

		}
	}

	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	bool ans=false;
	int sz=v.size();
	for( int k=0;k<sz;k++){

	int x=v[k];
	for(int i=0;i<x;i++){

	int temp=1;
		for(int j=i;j<n;j+=x){
			if(a[j]==0)
			{
				temp=0;
				break;
			}
		}
		if(temp)
		{
			ans=true;
			//cout<<x<<endl;
			break;
		}
	}
	if(ans)
		break;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");

return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <stack>
#define mp make_pair
#define pb push_back
#define setval(a,v) memset(a,v,sizeof(a))

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

typedef long long int64;
typedef long double ld;

int a[110000];
int n;

void check(int x){
    if (n/x < 3)
        return;
    for (int i=0;i<x;i++){
        bool q = true;
        for (int j = i;j<n;j+=x)
            q &= a[j];
        if (q){
        	if(n==1001)
            printf("%d %d YES\n",x,i);
            else
            printf("YES\n");
            exit(0);
        }
    }
}

int main()
{

   // freopen("readin.txt","r",stdin);

    scanf("%d",&n);
    for (int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for (int i=1;i*i<=n;i++)
        if (n%i == 0){
            check(i);
            check(n/i);
        }
    printf("NO\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
vector <int>v;
int vis[100005];
int main(){
	//freopen("readin.txt", "r", stdin);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		if(vis[i]==1)
			continue;
		else{
			if(n%i==0&&n/i>=3){
			v.push_back(i);
			if(i==1)
				continue;
			for(int j=i+i;j<n;j+=i)
				vis[j]=1;
			}

		}
	}

	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	bool ans=false;
	int sz=v.size();
	for( int k=0;k<sz;k++){

	int x=v[k];
	for(int i=0;i<x;i++){

	int temp=1;
int sum=1;
int ind=i;

		while(sum!=n/x)
		{
			sum++;

			if(a[ind]==0)
			{
				temp=0;
				break;
			}
			ind+=x;

		}
		if(temp)
		{
			ans=true;
			//cout<<x<<endl;
			break;
		}
	}
	if(ans)
		break;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
vector <int>v;
int vis[100005];
int main(){
//freopen("readin.txt", "r", stdin);
	scanf("%d",&n);
	for(int i=1;i*i<=n;i++){
		int c=n/i;
			if(n%i==0 && n/i>=3)
			v.push_back(i);
			if(n%c==0 && n/c>=3)
				v.push_back(c);

	}

	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	bool ans=false;
	int sz=v.size();
	//cout<<sz<<endl;
	for( int k=0;k<sz;k++){

	int x=v[k];
	for(int i=0;i<x;i++){

	int temp=1;
		for(int j=i;j<n;j+=x){
			if(a[j]==0)
			{
				temp=0;
				break;
			}
		}
		if(temp)
		{
			ans=true;
			//cout<<x<<endl;
			break;
		}
	}
	if(ans)
		break;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
vector <int>v;
int vis[100005];
int main(){
//freopen("readin.txt", "r", stdin);
	scanf("%d",&n);
	for(int i=1;i*i<=n;i++){
			if(n%i==0)
			v.push_back(i);
			if(n/i>=3)
				v.push_back(n/i);
	}

	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	bool ans=false;
	int sz=v.size();
	//cout<<sz<<endl;
	for( int k=0;k<sz;k++){

	int x=v[k];
	for(int i=0;i<x;i++){

	int temp=1;
		for(int j=i;j<n;j+=x){
			if(a[j]==0)
			{
				temp=0;
				break;
			}
		}
		if(temp)
		{
			ans=true;
			//cout<<x<<endl;
			break;
		}
	}
	if(ans)
		break;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
vector <int>v;
int vis[100005];
int main(){
//	freopen("readin.txt", "r", stdin);
	scanf("%d",&n);
	for(int i=1;i*i<=n;i++){
			if(n%i==0&&n/i>=3)
			v.push_back(i);
	}

	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	bool ans=false;
	int sz=v.size();
	for( int k=0;k<sz;k++){

	int x=v[k];
	for(int i=0;i<x;i++){

	int temp=1;
		for(int j=i;j<n;j+=x){
			if(a[j]==0)
			{
				temp=0;
				break;
			}
		}
		if(temp)
		{
			ans=true;
			//cout<<x<<endl;
			break;
		}
	}
	if(ans)
		break;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");

return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll>ans;
    vector<ll>v;
    ll cnt1=0,cnt2=0;
    for(ll i=0;i<n;i++){
       ll s;
       cin>>s;
       if(s==0) cnt1++;
       if(s==1) cnt2++;
       ans.push_back(s);
    }
    if(cnt1==n){
        cout<<"NO"<<endl;
        return 0;
    }
    else if(cnt2==n){
        cout<<"YES"<<endl;
        return 0;
    }
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i) continue;
        if(i*i==n) {
            if(i>=3){
                v.push_back(i);
                continue;
            }
        }
        if(i>=3) v.push_back(i);
        if(n/i>=3) v.push_back(n/i);
    }
    ll m=v.size();
    for(ll j=0;j<m;j++){
       for(ll k=0;k<v[j];k++){
           ll res=0;

           for(ll i=k;i<n;i+=n/v[j]){
               if (v[i]) res++;
               else{res=0;break;}
           }
           if(res==n/v[j]){
                cout<<"YES"<<endl;
                return 0;
           }

       }
    }
    cout<<"NO"<<endl;
    return 0;
    }


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll>ans;
    vector<ll>v;
    ll cnt1=0,cnt2=0;
    for(ll i=0;i<n;i++){
       ll s;
       cin>>s;
       if(s==0) cnt1++;
       if(s==1) cnt2++;
       ans.push_back(s);
    }
    if(cnt1==n){
        cout<<"NO"<<endl;
        return 0;
    }
    else if(cnt2==n){
        cout<<"YES"<<endl;
        return 0;
    }
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i) continue;
        if(i*i==n) {
            if(i>=3){
                v.push_back(i);
                continue;
            }
        }
        if(i>=3) v.push_back(i);
        if(n/i>=3) v.push_back(n/i);
    }
    ll m=v.size();
    for(ll j=0;j<m;j++){
       for(ll k=0;k<v[j];k++){
           ll res=0;

           for(ll i=k;i<n+k;i+=n/v[j]){

               if (ans[i%n]==1) res++;
               else{
                    res=0;
                    break;
                    }
           }
           if(res==v[j]){
                cout<<"YES"<<endl;
                return 0;
           }

       }
    }
    cout<<"NO"<<endl;
    return 0;
    }


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll>ans;
    vector<ll>v;
    ll cnt1=0,cnt2=0;
    for(ll i=0;i<n;i++){
       ll s;
       cin>>s;
       if(s==0) cnt1++;
       if(s==1) cnt2++;
       ans.push_back(s);
    }
    if(cnt1==n){
        cout<<"NO"<<endl;
        return 0;
    }
    else if(cnt2==n){
        cout<<"YES"<<endl;
        return 0;
    }
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i) continue;
        if(i*i==n) {
            if(i>=3){
                v.push_back(i);
                continue;
            }
        }
        if(i>=3) v.push_back(i);
        if(n/i>=3) v.push_back(n/i);
    }
    ll m=v.size();
    for(ll j=0;j<m;j++){
       for(ll k=0;k<v[j];k++){
           ll res=0;
           for(ll i=k;i<n;i+=n/v[j]){
               if (v[i]) res++;
               else{res=0;break;}
           }
           if(res==n/v[j]){
                cout<<"YES"<<endl;
                return 0;
           }

       }
    }
    cout<<"NO"<<endl;
    return 0;
    }


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll>ans;
    vector<ll>v;
    ll cnt1=0,cnt2=0;
    for(ll i=0;i<n;i++){
       ll s;
       cin>>s;
       if(s==0) cnt1++;
       if(s==1) cnt2++;
       ans.push_back(s);
    }
    if(cnt1==n){
        cout<<"NO"<<endl;
        return 0;
    }
    else if(cnt2==n){
        cout<<"YES"<<endl;
        return 0;
    }
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i) continue;
        if(i*i==n) {
            if(i>=3){
                v.push_back(i);
                continue;
            }
        }
        if(i>=3) v.push_back(i);
        if(n/i>=3) v.push_back(n/i);
    }
    ll m=v.size();
    for(ll j=0;j<m;j++){
       for(ll k=0;k<n/v[j];k++){
           ll res=0;

           for(ll i=k;i<n;i+=n/v[j]){

               if (ans[i]==1) res++;
               else{
                    res=0;
                    break;
                    }
           }
           if(res==v[j]){
                cout<<"YES"<<endl;
                return 0;
           }

       }
    }
    cout<<"NO"<<endl;
    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
int a,s,d[100002],f[100002],g[100002],h,j,k,l,i,n,n1,m;
int chk(int dis){
    l=0;
    for(i=0;i<n1;i++){
        if(!f[i]){
            if(g[i%dis]!=dis) l++;
            g[i%dis]=dis;
        }
        if(l==dis) return 0;
    }
    cout<<"YES";
    return 1;
}
main(){
    cin>>n;
    n1=n;
    for(i=2;i<=n;i++){
        if(d[i]==0)
        for(a=i;a<=n;a+=i){
            if(!d[a])d[a]=i;
        }
    }

    for(i=0;i<n;i++) cin>>f[i];

    while(n>2){
        if(d[n]!=2)k=chk(d[n]);
        else if(n1%4==0) k=chk(4);
        if(k) return 0;
        n=n/d[n];
    }
    cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int a,s,d[100002],f[100002],g[100002],h,j,k,l,i,n,n1,m;
int chk(int dis){
    l=0;
    for(i=0;i<n1;i++){
        if(!f[i]){
            if(g[i%dis]!=dis) l++;
            g[i%dis]=dis;
        }//cout<<l<<" ";
        if(l==dis) return 0;
    }
    cout<<"YES";
    return 1;
}
main(){
    cin>>n;
    n1=n;
    for(i=3;i<=n;i++){
        if(d[i]==0)
        for(a=i;a<=n;a+=i){
            d[a]=i;
        }
    }

    for(i=0;i<n;i++) cin>>f[i];

    while(n>2){
        k=chk(n/d[n]);
        if(k) return 0;
        n=n/d[n];
    }
    cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int a,s,d[100002],f[100002],g[100002],h,j,k,l,i,n,n1,m;
int chk(int dis){
    l=0;
    for(i=0;i<n1;i++){
        if(!f[i]){
            if(g[i%dis]!=dis) l++;
            g[i%dis]=dis;
        }
        if(l==dis) return 0;
    }
    cout<<"YES";
    return 1;
}
main(){
    cin>>n;
    n1=n;
    for(i=2;i<=n;i++){
        if(d[i]==0)
        for(a=i;a<=n;a+=i){
            if(!d[a])d[a]=i;
        }
    }

    for(i=0;i<n;i++) cin>>f[i];

    while(n>2){
        if(d[n]*2!=n1)k=chk(d[n]);
        else if(n1%4==0) k=chk(n1/4);
        if(k) return 0;
        n=n/d[n];
    }
    cout<<"NO";
}


#pragma once
#include <bits/stdc++.h>
//#include <primesieve.hpp>
//#include <mymaths.h>
//#include <bigint.h>
//#include <utils.h>
using namespace std;
//struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;
vector<int> k;
map<int,vector<int>>p;
int main() {
	//clock_t c_start = clock();

	int n; scanf("%d\n", &n);
	k.reserve(n);
	for (int i = 0; i < n; i++) {
		int m; scanf("%d", &m);
		if (m) {
			k.push_back(i);
		}
	}
	if (k.size() == n) {
		printf("YES\n");
		//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
		return 0;
	}
	for (int i = 2; i <= n / 3; i++)
	{
		p.clear();
		for (int j = 0; j < k.size(); j++)
		{
			p[k[j] % i].push_back(k[j]);
		}
		for (auto item : p) {
			if (item.second.size() > 2) {
				if ((item.second.back() + i) % n == item.second.front()) {
					printf("YES\n");
					//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
					return 0;
				}
			}
		}
	}
	printf("NO\n");
	//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
}


#pragma once
#include <bits/stdc++.h>
using namespace std;
#define rep(x,y) for (int x = 0; x < (y); x++)
#define N 100007
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;
int a[N];
bool vis[N];
int main()
{
	int n; cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n + 1) if (i > 2 && !(n%i)) {
		int d = n / i;
		rep(j, d) {
			bool BizZ = true;
			for (int k = j; k < n; k += d)
				if (!a[k])
				{
					BizZ = false;
					break;
				}
			if (BizZ) {
				cout << "YES";
				return 0;
			}
		}
	}
	cout << "NO";

}


#pragma once
#include <bits/stdc++.h>
using namespace std;
#define rep(x,y) for (int x = 0; x < (y); x++)
#define N 100007

int a[N];
bool vis[N];
int main()
{
	int n; cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n + 1) if (i > 2 && !(n%i)) {
		int d = n / i;
		rep(j, d) {
			bool BizZ = true;
			for (int k = j; k < n; k += d)
				if (!a[k])
				{
					BizZ = false;
					break;
				}
			if (BizZ) {
				cout << "YES";
				return 0;
			}
		}
	}
	cout << "NO";

}


#pragma once
#include <bits/stdc++.h>
//#include <primesieve.hpp>
//#include <mymaths.h>
//#include <bigint.h>
//#include <utils.h>
using namespace std;
//struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;
vector<int> k;
vector<int>p[33334];
int main() {
	//clock_t c_start = clock();

	int n; scanf("%d\n", &n);
	k.reserve(n);
	for (int i = 0; i < n; i++) {
		int m; scanf("%d", &m);
		if (m) {
			k.push_back(i);
		}
	}
	if (k.size() == n) {
		printf("YES\n");
		//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
		return 0;
	}
	for (int i = 2; i <= n / 3; i++)
	{
		memset(p, 0, sizeof(p));
		for (int j = 0; j < k.size(); j++)
			p[k[j] % i].push_back(k[j]);
		for (int j = 0; j < 33334; j++)
		{
			int last;
			if ((last = p[j].size()) > 2) {
				if (p[j][0] == (p[j][last - 1] + i) % n) {
					printf("YES\n");
					//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
					return 0;
				}
			}
		}
	}
	printf("NO\n");
	//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
}


#pragma once
#include <bits/stdc++.h>
//#include <primesieve.hpp>
//#include <mymaths.h>
//#include <bigint.h>
//#include <utils.h>
using namespace std;
//struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;
vector<int> k;
map<int,vector<int>>p;
int main() {
	//clock_t c_start = clock();

	int n; scanf("%d\n", &n);
	k.reserve(n);
	for (int i = 0; i < n; i++) {
		int m; scanf("%d", &m);
		if (m) {
			k.push_back(i);
		}
	}
	for (int i = 2; i <= n / 3; i++)
	{
		p.clear();
		for (int j = 0; j < k.size(); j++)
		{
			p[k[j] % i].push_back(k[j]);
		}
		for (auto item : p) {
			if (item.second.size() > 2) {
				if ((item.second.back() + i) % n == item.second.front()) {
					printf("YES\n");
					//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
					return 0;
				}
			}
		}
	}
	printf("NO\n");
	//cout << fixed << setprecision(2) << 1000.0 * (clock() - c_start) / CLOCKS_PER_SEC << " ms\n";
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define VAL(x) #x << " = " << (x) << "   "
#define SQR(a) ((a) * (a))
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define CLR(x, a) memset(x, a, sizeof x)
#define FOREACH(i, x) for(__typeof((x).begin()) i = (x).begin(); i != (x).end(); i ++)
#define FOR(i, n) for (int i = 0; i < (n); i ++)
#define X first
#define Y second
#define pp pair <ll, ll>
const int maxn = 1 * 1000000 + 5;
        ll c[26][maxn];
vector <ll> v[100006];
ll visited[100006];
ll ans = 0;
vector <ll> ansp;

ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
void dfs(ll root, ll od, ll ev, ll level, ll a[], ll b[])
{
    if (visited[root])
    return ;
    visited[root] = 1;
    if (level % 2 && od)
    {
        a[root] = 1-a[root];
    }
    if (level % 2 == 0 && ev)
    {
        a[root] = 1-a[root];
    }

    if (a[root] != b[root])
    {
        if (level%2)
        {
            od = 1- od;
        }
        else
        {
            ev = 1 - ev;
        }

        a[root] = b[root];
        ans++;
        ansp.push_back(root);
    }
    for (auto i : v[root])
    dfs(i, od, ev, level+1, a , b);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pi 3.14159265358979323846

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // int n, d, k;
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll c = 0;
        for (ll i = 0 ; i < n ; i++)
        {
            cin >> a[i];
            if (a[i] == 1)
            c++;
        }
        vector <ll> p;
        for (ll i = 2; i <= sqrt(n); i++)
        {
            if (n%i)
            continue;
            ll f1 = i, f2 = n/i;
            p.push_back(i);
            if (f1 != f2)
            p.push_back(f2);
        }
        ll x = 0;
        for (ll i = 0 ; i < p.size(); i++)
        {
            for (ll j = 0 ; j < p[i]; j++)
            {
                ll ok = 1;
                ll u = 0;
                for (ll k = j; k < n ; k += (p[i]))
                {
                    if (a[k] == 0)
                    {
                        ok = 0;
                        break;
                    }
                    else
                    u++;
                }
                if (ok && u > 2)
                {
                    x = 1;
                    break;
                }
            }
            if (x)
            break;
        }
        if (c == n)
        x = 1;
        if (x)
        cout << "YES" ;
        else
        cout << "NO";

    }
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define VAL(x) #x << " = " << (x) << "   "
#define SQR(a) ((a) * (a))
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define CLR(x, a) memset(x, a, sizeof x)
#define FOREACH(i, x) for(__typeof((x).begin()) i = (x).begin(); i != (x).end(); i ++)
#define FOR(i, n) for (int i = 0; i < (n); i ++)
#define X first
#define Y second
#define pp pair <ll, ll>
const int maxn = 1 * 1000000 + 5;
        ll c[26][maxn];
vector <ll> v[100006];
ll visited[100006];
ll ans = 0;
vector <ll> ansp;

ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
void dfs(ll root, ll od, ll ev, ll level, ll a[], ll b[])
{
    if (visited[root])
    return ;
    visited[root] = 1;
    if (level % 2 && od)
    {
        a[root] = 1-a[root];
    }
    if (level % 2 == 0 && ev)
    {
        a[root] = 1-a[root];
    }

    if (a[root] != b[root])
    {
        if (level%2)
        {
            od = 1- od;
        }
        else
        {
            ev = 1 - ev;
        }

        a[root] = b[root];
        ans++;
        ansp.push_back(root);
    }
    for (auto i : v[root])
    dfs(i, od, ev, level+1, a , b);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pi 3.14159265358979323846

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // int n, d, k;
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll c = 0;
        for (ll i = 0 ; i < n ; i++)
        {
            cin >> a[i];
            if (a[i] == 1)
            c++;
        }
        vector <ll> p;
        for (ll i = 2; i <= sqrt(n); i++)
        {
            if (n%i)
            continue;
            ll f1 = i, f2 = n/i;
            p.push_back(i);
            if (f1 != f2)
            p.push_back(f2);
        }
        ll x = 0;
        for (ll i = 0 ; i < p.size(); i++)
        {
            for (ll j = 0 ; j < p[i]; j++)
            {
                ll ok = 1;
                ll u = 0;
                for (ll k = j; k < n ; k += (p[i]))
                {
                    if (a[k] == 0)
                    {
                        ok = 0;
                        break;
                    }
                    else
                    u++;
                }
                if (ok && u > 2)
                {
                    x = 1;
                    break;
                }
            }
            if (x)
            break;
        }
        if (c == n)
        x = 1;
        if (x)
        cout << "YES" ;
        else
        cout << "NO";
    }
       return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define VAL(x) #x << " = " << (x) << "   "
#define SQR(a) ((a) * (a))
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define CLR(x, a) memset(x, a, sizeof x)
#define FOREACH(i, x) for(__typeof((x).begin()) i = (x).begin(); i != (x).end(); i ++)
#define FOR(i, n) for (int i = 0; i < (n); i ++)
#define X first
#define Y second
#define pp pair <ll, ll>
const int maxn = 1 * 1000000 + 5;
        ll c[26][maxn];
vector <ll> v[100006];
ll visited[100006];
ll ans = 0;
vector <ll> ansp;

ll powerm(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
void dfs(ll root, ll od, ll ev, ll level, ll a[], ll b[])
{
    if (visited[root])
    return ;
    visited[root] = 1;
    if (level % 2 && od)
    {
        a[root] = 1-a[root];
    }
    if (level % 2 == 0 && ev)
    {
        a[root] = 1-a[root];
    }

    if (a[root] != b[root])
    {
        if (level%2)
        {
            od = 1- od;
        }
        else
        {
            ev = 1 - ev;
        }

        a[root] = b[root];
        ans++;
        ansp.push_back(root);
    }
    for (auto i : v[root])
    dfs(i, od, ev, level+1, a , b);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pi 3.14159265358979323846

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // int n, d, k;
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll c = 0;
        for (ll i = 0 ; i < n ; i++)
        {
            cin >> a[i];
            if (a[i] == 1)
            c++;
        }
        vector <ll> p;
        for (ll i = 2; i <= sqrt(n); i++)
        {
            if (n%i)
            continue;
            ll f1 = i, f2 = n/i;
            p.push_back(i);
            if (f1 != f2)
            p.push_back(f2);
        }
        ll x = 0;
        for (ll i = 0 ; i < p.size(); i++)
        {
            for (ll j = 0 ; j < p[i]-1; j++)
            {
                ll ok = 1;
                ll u = 0;
                for (ll k = j; k < n ; k += (p[i]))
                {
                    if (a[k] == 0)
                    {
                        ok = 0;
                        break;
                    }
                    else
                    u++;
                }
                if (ok && u > 2)
                {
                    // cout << p[i] << " ";
                    x = 1;
                    break;
                }
            }
            if (x)
            break;
        }
        if (c == n)
        x = 1;
        if (x)
        cout << "YES" ;
        else
        cout << "NO";
    }
       return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+20,M=505;
int n,a[N];
vector<int> v;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	bool flag=false;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			v.push_back(i);
			if(i*i!=n)
				v.push_back(n/i);
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++)
	{
		int d=v[i];
		if(n/d<=2)
			continue;
		for(int j=1;j<=d;j++)
		{
			bool mk=true;
			for(int k=j;k<=n;k+=d)
			{
				if(a[k]==0)
				{
					mk=false;
					break;
				}
			}
			if(mk)
			{
				cout<<j<<' '<<d<<endl;
				flag=true;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+20,M=505;
int n,a[N];
vector<int> v;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	bool flag=false;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			v.push_back(i);
			if(i*i!=n)
				v.push_back(n/i);
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++)
	{
		int d=v[i];
		if(n/d<=2)
			continue;
		for(int j=1;j<=d;j++)
		{
			bool mk=true;
			for(int k=j;k<=n;k+=d)
			{
				if(a[k]==0)
				{
					mk=false;
					break;
				}
			}
			if(mk)
			{
			//	cout<<j<<' '<<d<<endl;
				flag=true;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+20,M=505;
int n,a[N];
bool c[N];
vector<int> v;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	bool flag=false;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			v.push_back(i);
			if(i*i!=n)
				v.push_back(n/i);
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++)
	{
		int d=v[i];
		if(n/d<=2)
			continue;
		int num=1;
		memset(c,true,sizeof(c));
		for(int j=1;j<=n;j++)
		{
			c[num]&=a[j];
			num++;
			if(num>d)
				num=1;
		}
		for(int j=1;j<=d;j++)
		{
			if(c[j])
			{
				flag=true;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+20,M=505;
int n,a[N];
bool c[N];
vector<int> v;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	bool flag=false;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			v.push_back(i);
			if(i*i!=n)
				v.push_back(n/i);
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size()-1;i++)
	{
		int d=v[i];
		if(n/d<=2)
			continue;
		int num=1;
		memset(c,0,sizeof(c));
		for(int j=1;j<=n;j++)
		{
			c[num]&=a[j];
			num++;
			if(num>d)
				num=1;
		}
		for(int j=1;j<=d;j++)
		{
			if(c[j])
			{
				flag=true;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7LL;
const ld EPS = 1e-9;
const ld PI = acos(0.0) * 2;
const ll LOGMAX = 22;

template<typename T>
T Sqr(T x){
    return x * x;
}

ld Sqrt(ld x){
    ld lf = 0.0, rg = x;
    while(rg - lf > EPS){
        ld mid = (lf + rg) / 2.0;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    return lf;
}

template<typename T>
T Sqrt(T x){
    ll lf = 0, rg = x;
    while(rg - lf > 1){
        ll mid = (lf + rg) / 2;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    for(ll i = rg; i >= lf; --i){
        if(i * i <= x){
            return i;
        }
    }
}

ll n, a[maxN];

ll Check(ll x){
    ll f = 0;
    for(ll i = 1; i <= n; ++i){
        ll o = 1;
        for(ll j = i; j <= n; j += x){
            o &= a[j];
        }
        if(o && n / i >= 3){
            return i;
        }
    }
    return 0;
}

int main(){

    cin >> n;
    for(ll i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(ll i = 1; i <= n / 3; ++i){
        if(n % i){
            continue;
        }
        if(Check(i)){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7LL;
const ld EPS = 1e-9;
const ld PI = acos(0.0) * 2;
const ll LOGMAX = 22;

template<typename T>
T Sqr(T x){
    return x * x;
}

ld Sqrt(ld x){
    ld lf = 0.0, rg = x;
    while(rg - lf > EPS){
        ld mid = (lf + rg) / 2.0;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    return lf;
}

template<typename T>
T Sqrt(T x){
    ll lf = 0, rg = x;
    while(rg - lf > 1){
        ll mid = (lf + rg) / 2;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    for(ll i = rg; i >= lf; --i){
        if(i * i <= x){
            return i;
        }
    }
}

ll n, a[maxN], cnt;

ll Check(ll x){
    ll f = 0;
    for(ll i = 1; i <= n; ++i){
        ll o = 1;
        for(ll j = i; j <= n; j += x){
            o &= a[j];
        }
        if(o && n / i >= 3){
            return i;
        }
    }
    return 0;
}

int main(){

    cin >> n;
    for(ll i = 1; i <= n; ++i){
        cin >> a[i];
        cnt += a[i];
    }
    if(cnt < 3){
        cout << "NO";
        return 0;
    }
    for(ll i = 1; i <= n / 3; ++i){
        if(n % i){
            continue;
        }
        if(Check(i)){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7LL;
const ld EPS = 1e-9;
const ld PI = acos(0.0) * 2;
const ll LOGMAX = 22;

template<typename T>
T Sqr(T x){
    return x * x;
}

ld Sqrt(ld x){
    ld lf = 0.0, rg = x;
    while(rg - lf > EPS){
        ld mid = (lf + rg) / 2.0;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    return lf;
}

template<typename T>
T Sqrt(T x){
    ll lf = 0, rg = x;
    while(rg - lf > 1){
        ll mid = (lf + rg) / 2;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    for(ll i = rg; i >= lf; --i){
        if(i * i <= x){
            return i;
        }
    }
}

ll n, a[maxN];

ll Check(ll x){
    ll f = 0;
    for(ll i = 1; i <= n; ++i){
        ll o = 1;
        for(ll j = i; j <= n; j += x){
            o &= a[j];
        }
        if(o && n / i >= 3){
            return i;
        }
    }
    return 0;
}

int main(){

    scanf("%I64d", &n);
    for(ll i = 1; i <= n; ++i){
        scanf("%I64d", &a[i]);
    }
    for(ll i = 1; i <= n / 3; ++i){
        if(n % i){
            continue;
        }
        if(Check(i)){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7LL;
const ld EPS = 1e-9;
const ld PI = acos(0.0) * 2;
const ll LOGMAX = 22;

template<typename T>
T Sqr(T x){
    return x * x;
}

ld Sqrt(ld x){
    ld lf = 0.0, rg = x;
    while(rg - lf > EPS){
        ld mid = (lf + rg) / 2.0;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    return lf;
}

template<typename T>
T Sqrt(T x){
    ll lf = 0, rg = x;
    while(rg - lf > 1){
        ll mid = (lf + rg) / 2;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    for(ll i = rg; i >= lf; --i){
        if(i * i <= x){
            return i;
        }
    }
}

ll n, a[maxN];

bool Check(ll x){
    if(n / x <= 2){
        return false;
    }
    ll f = 0;
    for(ll i = 1; i <= x; ++i){
        ll cnt = 0;
        for(ll j = i; j <= n; j += x){
            cnt += a[j];
        }
        if(cnt == n / x){
            return true;
        }
    }
    return false;
}

int main(){

    scanf("%I64d", &n);
    for(ll i = 1; i <= n; ++i){
        scanf("%I64d", &a[i]);
    }
    for(ll i = 1; i <= n; ++i){
        if(n % i){
            continue;
        }
        if(Check(i)){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll lmaxN = ll(6e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7LL;
const ld EPS = 1e-9;
const ld PI = acos(0.0) * 2;

template<typename T>
T Sqr(T x){
    return x * x;
}

ld Sqrt(ld x){
    ld lf = 0.0, rg = x;
    while(rg - lf > EPS){
        ld mid = (lf + rg) / 2.0;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    return lf;
}

template<typename T>
T Sqrt(T x){
    ll lf = 0, rg = x;
    while(rg - lf > 1){
        ll mid = (lf + rg) / 2;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    for(ll i = rg; i >= lf; --i){
        if(i * i <= x){
            return i;
        }
    }
}

ll n, a[maxN];

int main(){
    cin >> n;
    for(ll i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(ll i = 1; i * i <= n; ++i){
        if(n % i == 0){
            ll f = 0;
            for(ll beg = 1; beg <= n; ++beg){
                for(ll j = beg; j <= n; j += i){
                    if(j > n){
                        break;
                    }
                    f |= (!a[j]);
                }
                if(!f){
                    cout << "YES";
                    return 0;
                }
            }
        }
    }
    cout << "NO";

    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7LL;
const ld EPS = 1e-9;
const ld PI = acos(0.0) * 2;
const ll LOGMAX = 22;

template<typename T>
T Sqr(T x){
    return x * x;
}

ld Sqrt(ld x){
    ld lf = 0.0, rg = x;
    while(rg - lf > EPS){
        ld mid = (lf + rg) / 2.0;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    return lf;
}

template<typename T>
T Sqrt(T x){
    ll lf = 0, rg = x;
    while(rg - lf > 1){
        ll mid = (lf + rg) / 2;
        if(mid * mid <= x){
            lf = mid;
        }
        else{
            rg = mid;
        }
    }
    for(ll i = rg; i >= lf; --i){
        if(i * i <= x){
            return i;
        }
    }
}

ll n, a[maxN];

bool Check(ll x){
    if(n / x <= 2){
        return false;
    }
    ll f = 0;
    for(ll i = 1; i <= n; ++i){
        ll cnt = 0;
        for(ll j = i; j <= n; j += x){
            cnt += a[j];
        }
        if(cnt == n / x){
            return true;
        }
    }
    return false;
}

int main(){

    scanf("%I64d", &n);
    for(ll i = 1; i <= n; ++i){
        scanf("%I64d", &a[i]);
    }
    for(ll i = 1; i <= n; ++i){
        if(n % i){
            continue;
        }
        if(Check(i)){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,m;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        if(n==1&&m==1)
        {
            cout<<"1";
        }
        else if(n%2==0&&m%2==0)
        {
            cout<<(n*m)/2;
        }
        else
        {
            cout<<(n*m)/2+1;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,m;
	cin >> t;
	while(t--){
		cin >> n >> m ;
		//if(n==1 && m==1)cout << 1 << endl;
		//else if(n==2 && m==2) cout << 2 << endl;
		//else
		if(n==1 && m==1)
		cout << 1 << endl;
		else if(n%2==1)
        cout << n/2*m + (m-1) << endl;
        else
        cout << n/2*m << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,m;
	cin >> t;
	while(t--){
		cin >> n >> m ;
		if(n==1 && m==1)cout << 1 << endl;
		else if(n==2 && m==2) cout << 2 << endl;
		else
        cout << n/2*m + (m-1) << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,m;
	cin >> t;
	while(t--){
		cin >> n >> m ;
		//if(n==1 && m==1)cout << 1 << endl;
		//else if(n==2 && m==2) cout << 2 << endl;
		//else
		if(n==1 && m==1)
		cout << 1 << endl;
		else if(n%2==1)
        cout << n/2*m + (m/2+1) << endl;
        else
        cout << n/2*m << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,m;
	cin >> t;
	while(t--){
		cin >> n >> m ;
		//if(n==1 && m==1)cout << 1 << endl;
		//else if(n==2 && m==2) cout << 2 << endl;
		//else
		if(n==1 && m==1)
		cout << 1 << endl;
		else if(m%2==1)
        cout << n/2*m + (m-1) << endl;
        else
        cout << n/2*m << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,m;
	cin >> t;
	while(t--){
		cin >> n >> m ;
		//if(n==1 && m==1)cout << 1 << endl;
		//else if(n==2 && m==2) cout << 2 << endl;
		//else
		if(n==1 && m==1)
		cout << 1 << endl;
		if(m%2==1)
        cout << n/2*m + (m-1) << endl;
        else
        cout << n/2*m << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,m;
	cin >> t;
	while(t--){
		cin >> n >> m ;
        int res = ceil(n*m*0.5);
        cout << res << endl;
	}
}


#include<bits/stdc++.h>
using namespace std ;
#define ulli unsigned long long int
#define ll long long
void solve()
{
    int m,n;
    cin>>n>>m;
    if (m*n%2==0)
        cout<<m*n/2;
    else
        cout<<(m*n/2)+1;
    return ;
}

int main()
{
    cin.tie(0);
	ios_base::sync_with_stdio(false);
    int t ;
    cin>>t ;
    while(t--){
        solve() ;
        cout<<"\n";}
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ulli unsigned long long int
#define ll long long
void solve()
{
    int m,n;
    cin>>m>>n;
    if (m*n%2==0)
        cout<<m*n/2;
    else
        cout<<(m*n/2)+1;
    return ;
}

int main()
{
    cin.tie(0);
	ios_base::sync_with_stdio(false);
    int t ;
    cin>>t ;
    while(t--)
        solve() ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ulli unsigned long long int
#define ll long long
int solve()
{
    int m,n,lights;
    cin>>n>>m;
    if (m*n%2==0)
       { lights=m*n/2;}
    else
        {lights=(m*n/2)+1;}

    return lights ;
}

int main()
{
    cin.tie(0);
	ios_base::sync_with_stdio(false);
    int t ;
    cin>>t ;
    while(t--)
        {solve() ;
            cout<<"\n";}
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ulli unsigned long long int
#define ll long long
int solve()
{
    int m,n,lights;
    cin>>n>>m;
    if (m*n%2==0)
       { lights=m*n/2;}
    else
        {lights=(m*n/2)+1;}

    return lights ;
}

int main()
{
    cin.tie(0);
	ios_base::sync_with_stdio(false);
    int t ;
    cin>>t ;
    while(t--)
        solve() ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ulli unsigned long long int
#define ll long long
void solve()
{
    int m,n,lights;
    cin>>n>>m;
    if (m*n%2==0)
       { lights=m*n/2;}
    else
        {lights=(m*n/2)+1;}

    return lights ;
}

int main()
{
    cin.tie(0);
	ios_base::sync_with_stdio(false);
    int t ;
    cin>>t ;
    while(t--)
        solve() ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
#define ulli unsigned long long int
#define ll long long
void solve()
{
    int m,n;
    cin>>n>>m;
    if (m*n%2==0)
        cout<<m*n/2;
    else
        cout<<(m*n/2)+1;
    return ;
}

int main()
{
    cin.tie(0);
	ios_base::sync_with_stdio(false);
    int t ;
    cin>>t ;
    while(t--)
        solve() ;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;

        if(m>n)
        {
            swap(n,m);
        }
       long r=m%2;
       long m2=m/2;
       long r1=n%2;
       long n2=n/2;
       long ans=m2*n+r*n2+r1;
      // cout<<"m2"<<m2<<"n2"<<n2<<"r"<<r<<"r1"<<r1;
       cout<<ans<<endl;
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>m>>n;
       long r=m%2;
       long m2=m/2;
       long r1=n%2;
       long n2=n/2;
       long ans=m2*n+r*n2+r1;
       cout<<ans<<endl;
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;
       if(m*n%2==0)
       {
cout<<(n*m)/2<<endl;
       }
       else
       {
           cout<<(n*m)/2+1<<endl;
       }

   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;
       if(m==1||n==1)
       {

           int e=max(m,n);
           if(e%2==0)
           {
  cout<<e/2<<endl;
           }
           else
           {
               cout<<e/2+1<<endl;
           }
       }
 else
 {
 if(m>n)

       long r=m%2;
       long m2=m/2;
       long r1=n%2;
       long n2=n/2;
       long ans=m2*n+r*n2+r1;
      // cout<<"m2"<<m2<<"n2"<<n2<<"r"<<r<<"r1"<<r1;
       cout<<ans<<endl;
 }

   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;
       if(m==1||n==1)
       {

           int e=max(m,n);
           if(e%2==0)
           {
  cout<<e/2<<endl;
           }
           else
           {
               cout<<e/2+1<<endl;
           }
       }
 else
 {
 if(m>n)
        {
            swap(n,m);
        }
       long r=m%2;
       long m2=m/2;
       long r1=n%2;
       long n2=n/2;
       long ans=m2*n+r*n2+r1;
      // cout<<"m2"<<m2<<"n2"<<n2<<"r"<<r<<"r1"<<r1;
       cout<<ans<<endl;
 }

   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;
       if(m==1||n==1)
       {

           int e=max(m,n);
           if(e%2==0)
           {
  cout<<e/2<<endl;
           }
           else
           {
               cout<<e/2+1<<endl;
           }
       }
 else
 {

       long r=m%2;
       long m2=m/2;
       long r1=n%2;
       long n2=n/2;
       long ans=m2*n+r*n2+r1;
      // cout<<"m2"<<m2<<"n2"<<n2<<"r"<<r<<"r1"<<r1;
       cout<<ans<<endl;
 }

   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;

       long r=m%2;
       long m2=m/2;
       long r1=n%2;
       long n2=n/2;
       long ans=m2*n+r*n2+r1;
      // cout<<"m2"<<m2<<"n2"<<n2<<"r"<<r<<"r1"<<r1;
       cout<<ans<<endl;
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;
       cout<<ceil((n*m)/double(2))<<endl;
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long n;
   cin>>n;
   while(n--)
   {
       long m,n;
       cin>>n>>m;
       if(m==1||n==1)
       {

           int e=max(m,n);
           if(e%2==0)
           {
  cout<<e/2<<endl;
           }
           else
           {
               cout<<e/2+1<<endl;
           }
       }
 else
 {

       long r=m%2;
       long m2=m/2;
       long r1=n%2;
       long n2=n/2;
       long ans=m2*n+r*n2+r*r1;
       cout<<ans<<endl;
 }

   }
   return 0;
}


#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main() {
    ll t;
    cin >> t;
    while(t--) {
        ll n, m;
        cin >> n >> m;
        if(n < 3) {
            ll z = n * ceil(m * 1.0 / 2.0);
            cout << z << endl;
        } else {
            ll z = n * ceil(m * 1.0 / 2.0);
            if(m % 2 == 0) z++;
            if(n % 2 == 0) z++;
            cout << z - (n / 2) << endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main() {
    ll t;
    cin >> t;
    while(t--) {
        ll n, m;
        cin >> n >> m;
        if(n == 1) {
            cout << ceil(m * 1.0 / 2.0) << endl;
        } else if(n == 2){
            cout << m << endl;
        } else {
            ll z = n * ceil(m * 1.0 / 2.0);
            if(m % 2 == 0) z++;
            if(n % 2 == 0) z++;
            cout << z - (n / 2) << endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main() {
    ll t;
    cin >> t;
    while(t--) {
        ll n, m;
        cin >> n >> m;
        if(n < 3) {
            ll z = n * ceil(m * 1.0 / 2.0);
            cout << z << endl;
        } else {
            ll z = n * ceil(m * 1.0 / 2.0);
            cout << z - (n / 2) << endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main() {
    ll t;
    cin >> t;
    while(t--) {
        ll n, m;
        cin >> n >> m;
        if(n == 1) {
            cout << ceil(m * 1.0 / 2.0) << endl;
        } else if(n == 2){
            cout << m << endl;
        } else {
            if(m == 1) {
                cout << ceil(n * 1.0 / 2.0) << endl;
            } else if(m == 2) {
                cout << n << endl;
            } else {
                ll z = n * ceil(m * 1.0 / 2.0);
                if(m % 2 == 0) z++;
                if(n % 2 == 0) z++;
                cout << z - (n / 2) << endl;
            }
        }
    }
}


#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main() {
    ll t;
    cin >> t;
    while(t--) {
        ll n, m;
        cin >> n >> m;
        if(n > m) {
            ll x = m;
            m = n;
            n = x;
        }
        if(n == 1) cout << (m / 2) + (m % 2) << endl;
        else if(n == 2) cout << m << endl;
        else {
            ll z =  ceil(n * (m * 1.0 / 2.0));
            cout << z << endl;
        }
    }
}


#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main() {
    ll t;
    cin >> t;
    while(t--) {
        ll n, m;
        cin >> n >> m;
        if(n < 3) {
            ll z = n * ceil(m * 1.0 / 2.0);
            cout << z << endl;
        } else {
            ll z = n * ceil(m * 1.0 / 2.0);
            if(m % 2 == 0) z++;
            cout << z - (n / 2) << endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t ;
	cin >> t ;
	while(t--)
	{
		float n , m ;
		cin >> n >> m ;
		float t = (n*m)/2 ;
		cout << ceil(t) << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t ;
	cin >> t ;
	while(t--)
	{
		int n , m ;
		cin >> n >> m ;
		double t = (n*m)/2.0 ;
		cout << ceil(t) << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t ;
	cin >> t ;
	while(t--)
	{
		int n , m ;
		cin >> n >> m ;
		cout << (n*m+1)/2 << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t ;
	cin >> t ;
	while(t--)
	{
		float n , m ;
		cin >> n >> m ;
		int t = (n*m)/2 ;
		cout << ceil(t) << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t ;
	cin >> t ;
	while(t--)
	{
		int n , m ;
		cin >> n >> m ;
		cout << floor((n*m+1)/2) << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t ;
	cin >> t ;
	while(t--)
	{
		int n , m ;
		cin >> n >> m ;
		cout << floor((n*m+1/2)) << endl;
	}
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   int t;

   cin>>t;
   while(t--)
   {
   int n,m;
   cin>>n>>m;
   int c=(n*m)/2+((n%2)*(m%2))%2;

   return c;
   }
	return 0;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   long long int t;

   cin>>t;
   while(t--)
   {
   long long int n,m;
   cin>>n>>m;
   long long int c=((n*m)/2+((n*m)%2));

   cout<<c;
   }
	return 0;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   long long int t;

   cin>>t;
   while(t--)
   {
   long long int n,m;
   cin>>n>>m;
   long long int c=((n*m)/2+((n%2)*(m%2))%2);

   return c;
   }
	return 0;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   int t;

   cin>>t;
   while(t--)
   {
   int n,m;
   cin>>n>>m;
   int c=n*m;
   int f=c%2;
   int g=c/2;
   return (f+g);
   }
	return 0;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   long long int t;

   cin>>t;
   while(t--)
   {
   long long int n,m;
   cin>>n>>m;
   long long int c=((n*m)/2+((n*m)%2));

   cout<<c<<endl;
      }
	return 0;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   long long int t;

   cin>>t;
   while(t--)
   {
   long long int n,m;
   cin>>n>>m;
   long long int c=((n*m)/2+((n*m)%2));

   cout<<c<<endl();
      }
	return 0;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   long long t;

   cin>>t;
   while(t--)
   {
   int n,m;
   cin>>n>>m;
   long long c=(long long)(n*m);
   long long f=c%2+c/2;

   return f;
   }
	return 0;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   long long t;

   cin>>t;
   while(t--)
   {
   long long n,m;
   cin>>n>>m;
   long long c=(n*m);
   long long f=c%2+c/2;

   return f;
   }
	return 0;

}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
//#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    //tc=1;
    cin>>tc;
    while(tc--)
    {
        ll n,m;
        cin>>n>>m;
        cout<< (ll)ceil( (ld)(n*m) / (ld)2 )<<endl;
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
//#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    //tc=1;
    cin>>tc;
    while(tc--)
    {
        ll n,m;
        cin>>n>>m;
        if( n%2==0 )
        {
            cout<<m*(n/2)<<endl;
        }
        else if( m%2==0 )
        {
            cout<<n*(m/2)<<endl;
        }
        else
        {
            ll ans=0;
            ans+= m*((n-1)/2);
            ans+=m/2;
            ans++;
            cout<<ans<<endl;
        }
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
//#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    //tc=1;
    cin>>tc;
    while(tc--)
    {
        ll n,m;
        cin>>n>>m;
        cout<< fixed << ceil( (ld)(n*m) / (ld)2 )<<endl;
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
//#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    //tc=1;
    cin>>tc;
    while(tc--)
    {
        ll n,m;
        cin>>n>>m;
        ll ans=ceil( (ld)(n*m) / (ld)2 );
        cout<< ans <<endl;
    }
 }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
//#define rem 998244353
#define cont continue
const ll INF=(1ll<<60)-1;//ll ans = 3e18 + 5;
////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tc;
    //tc=1;
    cin>>tc;
    while(tc--)
    {
        ll n,m;
        cin>>n>>m;
        cout<< ceil( (ld)(n*m) / (ld)2 )<<endl;
    }
 }


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"

// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };

/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}

ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u);
    while (!q.empty()) {

        int f = q.front();
        q.pop();
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    }

}

// void solve
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int t;
	cin>>t;
	while(t--)
	{
		ll n, m;
		cin>>n>>m;
		if(n < m)
			swap(n, m);
		ll ans;
		if(n==1 or m==1)
		{
			ans = ceil(n/2.0);
		}

		else
		{
			if(n%2==0)
			{
				ans = (n/2)*m;
			}
			else ans = (n/2)*m+(m+1)/2;
			// ans =
			// ans = ceil(n/2.0)+ceil(m/2.0);
		}
			cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"

// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };

/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}

ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u);
    while (!q.empty()) {

        int f = q.front();
        q.pop();
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    }

}

// void solve
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int t;
	cin>>t;
	while(t--)
	{
		ll n, m;
		cin>>n>>m;
		if(n < m)
			swap(n, m);
		ll ans;
		if(n==1 or m==1)
		{
			ans = ceil(n/2.0);
		}

		else
		{
			if(n%2==0)
			{
				ans = (n/2)*m;
			}
			else ans = (n/2)*m+(m-1);
			// ans =
			// ans = ceil(n/2.0)+ceil(m/2.0);
		}
			cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"

// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };

/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}

ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u);
    while (!q.empty()) {

        int f = q.front();
        q.pop();
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    }

}

// void solve
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int t;
	cin>>t;
	while(t--)
	{
		ll n, m;
		cin>>n>>m;
		if(n < m)
			swap(n, m);
		ll ans;
		if(n==1 or m==1)
		{
			ans = ceil(n/2.0);
		}

		else
		{
			// if(n%2==0) ans = (n/2)*m;
			// else if(m%2==0) ans = (m/2)*n;
			if(n%2==0 or m%2==0)
			{
				ans = (n*m)/2;
			}
			else ans = (n/2)*m+(m-1);
			// ans =
			// ans = ceil(n/2.0)+ceil(m/2.0);
		}
			cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define loop(i,n) for(int i=1;i<=n;i++)
using namespace std;
int fun(int a,int b) {
    return a*b/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,m; cin>>n>>m;
        if(n%2==0||m%2==0)
        {
            cout<<fun(n,m)<<"\n";
        }
        else
        {if(n==1&&m==1) cout<<"1\n";
        else
           cout<<min(fun(n-1,m)+m-1,fun(n,m-1)+n-1)<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define loop(i,n) for(int i=1;i<=n;i++)
using namespace std;
int fun(int a,int b) {
    return a*b/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,m; cin>>n>>m;
        if(n%2==0||m%2==0)
        {
            cout<<fun(n,m)<<"\n";
        }
        else
        {if(n==1&&m==1) cout<<"1\n";
        else
           cout<<fun(n-1,m)+m-1<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define loop(i,n) for(int i=1;i<=n;i++)
using namespace std;
int fun(int a,int b) {
    return a*b/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        long long n,m; cin>>n>>m;
        long long ans=ceil((n*m)/2.0);
        cout<<ans<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define loop(i,n) for(int i=1;i<=n;i++)
using namespace std;
int fun(int a,int b) {
    return a*b/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,m; cin>>n>>m;
        long long ans=ceil((n*m)/2);
        cout<<ans<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define loop(i,n) for(int i=1;i<=n;i++)
using namespace std;
int fun(int a,int b) {
    return a*b/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,m; cin>>n>>m;
        if(n%2==0||m%2==0)
        {
            cout<<fun(n,m)<<"\n";
        }
        else
        {if(n==1&&m==1) cout<<"1\n";
        else if(n==1) cout<<m-1<<"\n";
        else if(m==1) cout<<n-1<<"\n";
        else cout<<min(fun(n-1,m)+m-1,fun(n,m-1)+n-1)<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define loop(i,n) for(int i=1;i<=n;i++)
using namespace std;
int fun(int a,int b) {
    return a*b/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,m; cin>>n>>m;
        if(n==1&&m==1) cout<<"1\n";
        else if(n==1) cout<<m-1<<"\n";
        else if(m==1) cout<<n-1<<"\n";
        else if(n%2==0||m%2==0)
        {
            cout<<fun(n,m)<<"\n";
        }
        else
        {
            cout<<min(fun(n-1,m)+m-1,fun(n,m-1)+n-1)<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<ll>
#define pb(x) push_back(x)
#define mp make_pair
#define rep(i,x,y) for(i=x;i<y;i++)
#define lb(arr,n,x) lower_bound(arr,arr+n,x)
#define ub(arr,n,x) upper_bound(arr,arr+n,x)
#define precise(x,y) fixed<<setprecision(y)<<x
#define fi first
#define se second
#define mod 1000000007
#define pi 3.1415926535897932384626433
using namespace std;
const ll N=200005;
vector<ll> adj[N];
ll ans=0;
ll pow(ll a,ll b)
{
    if(b==0)
        return 1;
    ll ans=pow(a,b/2);
    ans=ans*ans;
    if(b%2)
        ans=ans*a;
    return ans;
}
int main()
{
   ll t=1,i,j,k;
   cin>>t;
   while(t--)
   {
      double n,m;
      cin>>n>>m;
      cout<<(n*floor(m/2)+ceil(n/2)*(((ll)m)%2))<<endl;
   }
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<ll>
#define pb(x) push_back(x)
#define mp make_pair
#define rep(i,x,y) for(i=x;i<y;i++)
#define lb(arr,n,x) lower_bound(arr,arr+n,x)
#define ub(arr,n,x) upper_bound(arr,arr+n,x)
#define precise(x,y) fixed<<setprecision(y)<<x
#define fi first
#define se second
#define mod 1000000007
#define pi 3.1415926535897932384626433
using namespace std;
const ll N=200005;
vector<ll> adj[N];
ll ans=0;
ll pow(ll a,ll b)
{
    if(b==0)
        return 1;
    ll ans=pow(a,b/2);
    ans=ans*ans;
    if(b%2)
        ans=ans*a;
    return ans;
}
int main()
{
   ll t=1,i,j,k;
   cin>>t;
   while(t--)
   {
      double n,m;
      cin>>n>>m;
      cout<<(ll)(n*floor(m/2)+ceil(n/2)*(((ll)m)%2))<<endl;
   }
}