stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,a,b,c,d;

	cin>>n>>a>>b>>c>>d;

	string s;

	cin>>s;

	for(int i=a;i<c;i++){

		if(s[i]=='#'&&s[i-1]=='#'){

			cout<<"No"<<endl;

			return 0;

		}

	}

	for(int i=b;i<d;i++){

		if(s[i]=='#'&&s[i-1]=='#'){

			cout<<"No"<<endl;

			return 0;

		}

	}

	s+="##";

	if(c<d){

		cout<<"Yes"<<endl;

		return 0;

	}

	else{

		for(int i=max(0,b-2);i<d-1;i++){

			if(s.substr(i,3)=="..."){

				cout<<"Yes"<<endl;

				return 0;

			}

		}

	}

	cout<<"No"<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.346976674356836x):
#include<cstdio>



using namespace std;



char s[200002];

int main(){

	int n,a,b,c,d;

	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s+1);

	int r1=a,r2=b;

	for(;;){

		if(r1<n&&s[r1+1]!='#')r1++;

		else if(r1<n-1&&s[r1+2]!='#')r1+=2;

		else if(r2<n&&s[r2+1]!='#')r2++;

		else if(r2<n-1&&s[r2+2]!='#')r2+=2;

		else break;

	}

	if(!(c<=r1)||!(d<=r2)){

		printf("No\n");

		return 0;

	}

	if(c>d){

		bool ok=1;

		for(int i=b-1;i+1<=d;i++)

			if(i+2<=r1&&s[i]!='#'&&s[i+1]!='#'&&s[i+2]!='#')

				ok=0;

		if(ok){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define FRU freopen("out.txt","w",stdout)

#define FRO freopen("in.txt","r",stdin)

#define pb push_back

#define mp make_pair

#define ff first

#define ss second

#define mem(ara,n) memset(ara,n,sizeof ara)

#define loop(i,j,n) for(i=j;i<n;i++)

#define rloop(i,j,n) for(i=n;i>=j;i--)

#define INF 2147483647

#define ll long long

#define pii pair<int,int>

#define eps 1e-9

#define mii map<int,int>

#define vi vector<int>

#define all(n) n.begin(),n.end()

#define inf INF

#define INFLL 9223372036854775807

using namespace std;

int main()

{

    int n,m,cnt=0,i,j,k;

    string s="-",s1;

    int a,b,c,d;

    cin>>n>>a>>b>>c>>d;

    cin>>s1;

    s+=s1;

    int ara[200005]={0};

    if(c>d)

    {

        int flag=0,flag1=0;

        for(i=a;i<=c;i++)

        {

            if(s[i]=='#'&& s[i-1]=='#')flag1=1;

        }

        if(s[b-1]=='.')ara[b-1]=1;

        for(i=b;i<=d;i++)

        {

            if(s[i]=='.')ara[i]=ara[i-1]+1;

            if(ara[i]>=3)flag=1;

        }

        if(s[d+1]=='.'&& ara[d]>1)flag=1;

        if(flag&& !flag1)cout<<"Yes\n";

        else cout<<"No\n";

    }

    else

    {

        int flag=0;

        for(i=a;i<=c;i++)

        {

            if(s[i]=='#'&& s[i-1]=='#')flag=1;

        }

        for(i=b;i<=d;i++)

        {

            if(s[i]=='#'&& s[i-1]=='#')flag=1;

        }

        /*if(c>b&& c<d)

        {

            if(s[c-1]=='#'|| s[c+1]=='#')flag=1;

        }*/

        if(!flag)cout<<"Yes\n";

        else cout<<"No\n";

    }



}


// Faster C++ solution for the same problem (measured speedup: 9.569311561369116x):
#include<cstdio>



using namespace std;



char s[200002];

int main(){

	int n,a,b,c,d;

	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s+1);

	int r1=a,r2=b;

	for(;;){

		if(r1<n&&s[r1+1]!='#')r1++;

		else if(r1<n-1&&s[r1+2]!='#')r1+=2;

		else if(r2<n&&s[r2+1]!='#')r2++;

		else if(r2<n-1&&s[r2+2]!='#')r2+=2;

		else break;

	}

	if(!(c<=r1)||!(d<=r2)){

		printf("No\n");

		return 0;

	}

	if(c>d){

		bool ok=1;

		for(int i=b-1;i+1<=d;i++)

			if(i+2<=r1&&s[i]!='#'&&s[i+1]!='#'&&s[i+2]!='#')

				ok=0;

		if(ok){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	

}
// Slower C++ solution:
# include <bits/stdc++.h>

using namespace std;

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define pii pair<int,int>

typedef long long ll;



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n,a,b,c,d;

    string s;

    cin>>n>>a>>b>>c>>d;

    cin>>s;

    int cnt=0;

    for(int i=a;i<=c;i++){

        if(s[i-1]=='#') cnt++;

        else cnt=0;

        if(cnt==2){

            cout<<"No"<<endl;

            return 0;

        }

    }

    cnt=0;

    for(int i=b;i<=d;i++){

        if(s[i-1]=='#') cnt++;

        else cnt=0;

        if(cnt==2){

            cout<<"No"<<endl;

            return 0;

        }

    }

    if(c<d){

        cout<<"Yes"<<endl;

        return 0;

    }

    else{

        for(int i=b-1;i<=(d-1);i++){

            if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') {

                cout<<"Yes"<<endl;

                return 0;

            }

        }

    }

    cout<<"No"<<endl;



}

// Faster C++ solution for the same problem (measured speedup: 5.388933061228911x):
#include<cstdio>



using namespace std;



char s[200002];

int main(){

	int n,a,b,c,d;

	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,s+1);

	int r1=a,r2=b;

	for(;;){

		if(r1<n&&s[r1+1]!='#')r1++;

		else if(r1<n-1&&s[r1+2]!='#')r1+=2;

		else if(r2<n&&s[r2+1]!='#')r2++;

		else if(r2<n-1&&s[r2+2]!='#')r2+=2;

		else break;

	}

	if(!(c<=r1)||!(d<=r2)){

		printf("No\n");

		return 0;

	}

	if(c>d){

		bool ok=1;

		for(int i=b-1;i+1<=d;i++)

			if(i+2<=r1&&s[i]!='#'&&s[i+1]!='#'&&s[i+2]!='#')

				ok=0;

		if(ok){

			printf("No\n");

			return 0;

		}

	}

	printf("Yes\n");

	

}
// Slower C++ solution:
#include<iostream>

#include <string.h>

using namespace std;

int main() {

  string s;

  getline(cin,s);

  if (s[0] == 'S') {

    cout << "Cloudy";

  } else if (s[0] == 'C') {

    cout << "Rainy";

  } else {

    cout << "Sunny";

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.357960005194131x):
#include <stdio.h>

using namespace std;

int main() {

  char a[7];

  scanf("%s",a);

  if (a[0] == 'S') {

    printf("Cloudy");

  } else if (a[0] == 'C') {

    printf("Rainy");

  } else {

    printf("Sunny");

  }

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



//世界は天才だなぁ



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N;

	cin >> N;

	int S[100000];

	rep(i, N) cin >> S[i];



	ll kotae = 0;

	rep1(ab, N / 2 - 1) {

		int n = ab;

		ll kari = 0;

		bool yoyuu = (N - 1) % n;

		while (n < N - 1 - ab && (yoyuu || n * 2 < N - 1)) {

			kari += S[n] + S[N - 1 - n];

			kotae = max(kotae, kari);

			n += ab;

		}

	}

	co(kotae);







	Would you please return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.219541683449205x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	int pn = 1;

	if (ci - cn + 16 > cm) {

		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }

		A = ct - '0';

		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

	else {

		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }

		A = ct - '0';

		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint();

	int S[100000];

	rep(i, N) S[i] = getint();



	ll kotae = 0;

	rep1(ab, N / 2 - 1) {

		int n = ab;

		ll kari = 0;

		if ((N - 1) % n) {

			while (n + ab < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

		else {

			while (n + n < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

	}

	printf("%lld", kotae);



	Would you please return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



//世界は天才だなぁ



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	int pn = 1;

	if (ci - cn + 16 > cm) {

		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }

		A = ct - '0';

		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

	else {

		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }

		A = ct - '0';

		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N = getint();

	int S[100000];

	rep(i, N) S[i] = getint();



	ll kotae = 0;

	rep1(ab, N / 2 - 1) {

		int n = ab;

		ll kari = 0;

		bool yoyuu = (N - 1) % n;

		while (n < N - 1 - ab && (yoyuu || n * 2 < N - 1)) {

			kari += S[n] + S[N - 1 - n];

			kotae = max(kotae, kari);

			n += ab;

		}

	}

	co(kotae);







	Would you please return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.207840261866048x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	int pn = 1;

	if (ci - cn + 16 > cm) {

		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }

		A = ct - '0';

		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

	else {

		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }

		A = ct - '0';

		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint();

	int S[100000];

	rep(i, N) S[i] = getint();



	ll kotae = 0;

	rep1(ab, N / 2 - 1) {

		int n = ab;

		ll kari = 0;

		if ((N - 1) % n) {

			while (n + ab < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

		else {

			while (n + n < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

	}

	printf("%lld", kotae);



	Would you please return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	int pn = 1;

	if (ci - cn + 16 > cm) {

		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }

		A = ct - '0';

		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

	else {

		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }

		A = ct - '0';

		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N = getint();

	int S[100000];

	rep(i, N) S[i] = getint();



	ll kotae = 0;

	rep1(ab, N / 2 - 1) {

		int n = ab;

		ll kari = 0;

		if ((N - 1) % n) {

			while (n + ab < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

		else {

			while (n + n < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

	}

	co(kotae);



	Would you please return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.209823544504827x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	int pn = 1;

	if (ci - cn + 16 > cm) {

		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }

		A = ct - '0';

		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

	else {

		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }

		A = ct - '0';

		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint();

	int S[100000];

	rep(i, N) S[i] = getint();



	ll kotae = 0;

	rep1(ab, N / 2 - 1) {

		int n = ab;

		ll kari = 0;

		if ((N - 1) % n) {

			while (n + ab < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

		else {

			while (n + n < N - 1) {

				kotae = max(kotae, (kari += S[n] + S[N - 1 - n]));

				n += ab;

			}

		}

	}

	printf("%lld", kotae);



	Would you please return 0;

}
// Slower C++ solution:
// 2020-07-17 00:56:53

#include<bits/stdc++.h>

#ifdef LOCAL

#include "lib/debug.hpp"

#else

#define debug(...) 1

#endif

#define ALL(a) (a).begin(), (a).end()

#define rep(i, n) REP(i, 0, (n))

#define repc(i, n) REPC(i, 0, (n))

#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)

#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)

#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)

using namespace std;

using ll = long long;

using ld = long double;

using pr = pair<ll, ll>;

using vll = vector<ll>;

using vpr = vector<pr>;

template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }



int used[100005];

void answer() {

  int n;

  cin >> n;

  vector<ll> s(n);

  rep(i, n) cin >> s[i];

  ll ans = 0;

  REP(c, 1, n/2) {

    memset(used, 0, sizeof used);

    ll cur = 0;

    int l = 0, r = n-1;

    for(;;) {

      if(used[l] || used[r] || l == r || r < c) break;

      used[l] = used[r] = 1;

      cur += s[l] + s[r];

      chmax(ans, cur);

      l += c, r -= c;

    }

  }

  cout << ans << '\n';

}

int main() {

  std::ios::sync_with_stdio(false);

  std::cin.tie(0);

  answer();

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.5001704797314486x):
// 2020-07-17 00:56:53

#include<bits/stdc++.h>

#ifdef LOCAL

#include "lib/debug.hpp"

#else

#define debug(...) 1

#endif

#define ALL(a) (a).begin(), (a).end()

#define rep(i, n) REP(i, 0, (n))

#define repc(i, n) REPC(i, 0, (n))

#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)

#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)

#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)

using namespace std;

using ll = long long;

using ld = long double;

using pr = pair<ll, ll>;

using vll = vector<ll>;

using vpr = vector<pr>;

template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }



void answer() {

  int n;

  cin >> n;

  vector<ll> s(n);

  rep(i, n) cin >> s[i];

  ll ans = 0;

  REP(c, 1, n/2) {

    ll cur = 0;

    int l = 0, r = n-1;

    for(;;) {

      l += c, r -= c;

      bool ok = [&]() {

        if((n-1) % c) {

          return l < n-1 && c <= r;

        } else {

          return l < r;

        }

      }();

      if(!ok) break;

      cur += s[l] + s[r];

      chmax(ans, cur);

    }

  }

  cout << ans << '\n';

}

int main() {

  std::ios::sync_with_stdio(false);

  std::cin.tie(0);

  answer();

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn = 100001;

int n, val[maxn];

bool used[maxn];

long long ans;

int main(){

	ios_base::sync_with_stdio(0), cin.tie(0);

	cin >> n;

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

	--n;

	for(int c = 1;c < n;++c){

		long long sum = 0;

		for(int k = 1;(k + 1) * c < n and !used[c * k] and !used[n - c * k] and (((c * k) << 1) != n);++k){

			ans = max(sum += val[c * k] + val[n - c * k], ans);

			used[c * k] = used[n - c * k] = true;

		}

		for(int k = 1;k * c < n and (used[c * k] || used[n - c * k]);++k){

			used[c * k] = used[n - c * k] = false;

		}

		memset(used, 0, sizeof(used));

	}

	cout << ans << '\n';

}

// Faster C++ solution for the same problem (measured speedup: 1.1735691858484332x):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 100001;

int n, val[maxn];

bool used[maxn];

long long ans;

int main(){

	ios_base::sync_with_stdio(0), cin.tie(0);

	cin >> n;

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

	--n;

	for(int c = 1;c < n;++c){

		long long sum = 0;

		for(int k = 1;(k + 1) * c < n and !used[c * k] and !used[n - c * k] and (((c * k) << 1) != n);++k){

			ans = max(sum += val[c * k] + val[n - c * k], ans);

			used[c * k] = used[n - c * k] = true;

		}

		for(int k = 1;k * c < n and (used[c * k] || used[n - c * k]);++k){

			used[c * k] = used[n - c * k] = false;

		}

	}

	cout << ans << '\n';

}
// Slower C++ solution:
#include<stdio.h>

#include<map>

using namespace std;

#define fo(i,a,b) for(int i=a;i<=b;i++)

#define fd(i,a,b) for(int i=a;i>=b;i--)

int n,s[110000],A,B;

long long ans,sum;

map<int,bool> vis;

int main(){

	scanf("%d",&n);

	fo(i,0,n-1) scanf("%d",&s[i]);

	fo(C,1,n-2){

		vis.clear();

		sum=0;//!!!! 

		for(int kC=C;kC<n-1;kC+=C){

			A=n-1-kC;

			B=A-C;

			if (A<=B||B<=0) break;

			if (A==kC||vis[A]||vis[kC]) break;

			sum+=s[A]+s[kC];

			vis[A]=1;vis[kC]=1;

			if (sum>ans) ans=sum;

		}

	}

	printf("%lld\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.84068969783111x):
#include<stdio.h>

#include<map>

using namespace std;

#define fo(i,a,b) for(int i=a;i<=b;i++)

#define fd(i,a,b) for(int i=a;i>=b;i--)

int n,s[110000],A,B,vis[110000],clo;

long long ans,sum;

//map<int,bool> vis;

int main(){

	scanf("%d",&n);

	fo(i,0,n-1) scanf("%d",&s[i]);

	fo(C,1,n-2){

//		vis.clear();

		clo++;

		sum=0;//!!!! 

		for(int kC=C;kC<n-1;kC+=C){

			A=n-1-kC;

			B=A-C;

			if (A<=B||B<=0) break;

			if (A==kC||vis[A]==clo||vis[kC]==clo) break;

			sum+=s[A]+s[kC];

			vis[A]=clo;vis[kC]=clo;

			if (sum>ans) ans=sum;

		}

	}

	printf("%lld\n",ans);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define sz(c)      int(c.size())

#define rep(i,a,b) for (int i=a; i<(b); ++i)

#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)

using namespace std;

using ll = long long;



int const MAXN=110000;

int N;

int S[MAXN];



map<pair<int,int>,ll> f[MAXN];



ll get_sum_naive(int s,int d,int k) {

	if (f[s].count({d,k})) return f[s][{d,k}];

	ll sum=0;

	rep(i,0,k+1) sum+=S[s+i*d];

	f[s][{d,k}]=sum;

	return sum;

}



ll check_naive(int A,int d) {

	if (A<=d) return 0;

	int k=(N-1-A)/d;

	if (A%d==0 && k>=A/d) return 0;

	return get_sum_naive(0,d,k) + get_sum_naive(A,d,k);

}



int main() {

	cin.tie(0);

	ios_base::sync_with_stdio(0);

	cout<<fixed<<setprecision(10);



	cin>>N;

	rep(i,0,N) cin>>S[i];

	

	ll res=0;

	for (int d=1; d*d<=N; ++d) {

		vector<vector<ll>> sums(d);

		rep(i,0,N) {

			ll v=S[i];

			if (!sums[i%d].empty()) v+=sums[i%d].back();

			sums[i%d].push_back(v);

		}

		

		rep(A,1,N-1) if ((N-1-A)%d==0) {

			int k=(N-1-A)/d;

			res=max(res,check_naive(A,k));

			

			if (A<=d || (A%d==0 && k>=A/d)) continue;

			

			ll sum=sums[0][k];

			sum+=sums[A%d][A/d+k];

			if (A/d>0) sum-=sums[A%d][A/d-1];

			res=max(res,sum);

		}

	}

		

	cout<<res<<"\n";

}


// Faster C++ solution for the same problem (measured speedup: 6.759773897817318x):
#include <bits/stdc++.h>

#define sz(c)      int(c.size())

#define rep(i,a,b) for (int i=a; i<(b); ++i)

#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)

using namespace std;

using ll = long long;



int const MAXN=110000;

int N;

int S[MAXN];



ll get_sum_naive(int s,int d,int k) {

	ll sum=0;

	rep(i,0,k+1) sum+=S[s+i*d];

	return sum;

}



ll check_naive(int A,int d) {

	if (A<=d) return 0;

	int k=(N-1-A)/d;

	if (A%d==0 && k>=A/d) return 0;

	return get_sum_naive(0,d,k) + get_sum_naive(A,d,k);

}



int main() {

	cin.tie(0);

	ios_base::sync_with_stdio(0);

	cout<<fixed<<setprecision(10);



	cin>>N;

	rep(i,0,N) cin>>S[i];

	

	ll res=0;

	for (int d=1; d*d<=N; ++d) {

		vector<vector<ll>> sums(d);

		rep(i,0,N) {

			ll v=S[i];

			if (!sums[i%d].empty()) v+=sums[i%d].back();

			sums[i%d].push_back(v);

		}

		

		rep(A,1,N-1) if ((N-1-A)%d==0) {

			int k=(N-1-A)/d;

			res=max(res,check_naive(A,k));

			

			if (A<=d || (A%d==0 && k>=A/d)) continue;

			

			ll sum=sums[0][k];

			sum+=sums[A%d][A/d+k];

			if (A/d>0) sum-=sums[A%d][A/d-1];

			res=max(res,sum);

		}

	}

		

	cout<<res<<"\n";

}