stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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");

	

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
# 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;



}

// Optimized solution to the same problem (faster):
#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");

	

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// 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;

}

// Optimized solution to the same problem (faster):
// 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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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';

}

// Optimized solution to the same problem (faster):
#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';

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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";

}


// Optimized solution to the same problem (faster):
#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 main() {

	cin.tie(0);

	ios_base::sync_with_stdio(0);

	cout<<fixed<<setprecision(10);



	int N;

	cin>>N;

	vector<int> S(N);

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

	

	ll res=0;

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

		ll sum=0;

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

			sum+=S[k*d]+S[N-1-k*d];

			int A=N-1-k*d;

			if (A>d && (A%d!=0 || k<A/d)) res=max(res,sum);

		}

	}



	cout<<res<<"\n";

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <vector>

#include <iostream>

#include <algorithm>

using namespace std;

int N, x, A[50176];

int main() {

	// step #1. read input

	cin.tie(0);

	ios_base::sync_with_stdio(false);

	cin >> N;

	int H = (N >> 1);

	for (int i = 0; i < H; ++i) {

		cin >> A[i];

	}

	if (N % 2 == 1) {

		cin >> x;

	}

	for (int i = H - 1; i >= 0; --i) {

		cin >> x;

		A[i] += x;

	}

	// step #2. calculate the answer

	long long ans = 0;

	for (int i = 1; i < N; ++i) {

		long long sum = 0;

		int pos = i;

		while (pos < H) {

			sum += A[pos];

			ans = max(ans, sum);

			pos += i;

		}

		if ((N - 1) % i != 0) {

			pos = (N - 1) - pos;

			while (pos >= i) {

				sum += A[pos];

				ans = max(ans, sum);

				pos -= i;

			}

		}

	}

	cout << ans << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

int readint() {

	char ch = getchar();

	int res = 0; bool f = false;

	if (ch == '-') {

		f = true;

		ch = getchar_unlocked();

	}

	while ('0' <= ch && ch <= '9') {

		res = res * 10 + ch - '0';

		ch = getchar_unlocked();

	}

	if (f) res = -res;

	return res;

}

int A[50176];

int main() {

	// step #1. read input

	int N = readint();

	int H = (N >> 1);

	for (int i = 0; i < H; ++i) A[i] = readint();

	if (N & 1) readint();

	for (int i = H - 1; i >= 0; --i) A[i] += readint();

	// step #2. calculate the answer

	long long ans = 0;

	for (int i = 1; i < N; ++i) {

		long long sum = 0;

		int pos = i;

		while (pos < H) {

			sum += A[pos];

			ans = std::max(ans, sum);

			pos += i;

		}

		if ((N - 1) % i != 0) {

			pos = (N - 1) - pos;

			while (pos >= i) {

				sum += A[pos];

				ans = std::max(ans, sum);

				pos -= i;

			}

		}

	}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(){

    long long int a,b=1,c;

    cin>>a;

  cout<<pow(a,3)<<endl;



}


// Optimized solution to the same problem (faster):
#include <stdio.h>

int main () {



int n;

scanf ("%d", &n);



int possible;

possible = n*n*n;

printf ("%d",  possible);

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>



using namespace std;

int n, ans;

int main()

{

	cin >> n;

	ans = n * n * n;

	cout << ans << "\n";

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main () {



int n;

scanf ("%d", &n);



int possible;

possible = n*n*n;

printf ("%d",  possible);

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main() {

    int n;

    cin >> n;

    

    cout << n*n*n;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main () {



int n;

scanf ("%d", &n);



int possible;

possible = n*n*n;

printf ("%d",  possible);

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

int main()

{

	int a,b;

	cin>>a;

	b=pow(a,3);

	cout<<b;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main () {



int n;

scanf ("%d", &n);



int possible;

possible = n*n*n;

printf ("%d",  possible);

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

int main()

{

	int n;

	cin>>n;

		cout<<pow(n,3);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main () {



int n;

scanf ("%d", &n);



int possible;

possible = n*n*n;

printf ("%d",  possible);

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

	int  ans;

	int n;

	cin>>n;

	cout<<n*n*n;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main () {



int n;

scanf ("%d", &n);



int possible;

possible = n*n*n;

printf ("%d",  possible);

	

	return 0;

}

// Fastest known solution for this problem: