// Original C++ solution (slower):


#include <cassert>

#include <cstdio>

#include <cstring>

#include <iostream>

#include <vector>

#include <queue>

#include <algorithm>

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

using namespace std;



typedef long long ll;



ll vs[100000+10];

int n;



vector<ll> cs[100000+10];

vector<ll> cs2[100000+10];



vector<int> memoDs[100000+10];

vector<int> calcDs(int v) {

  vector<int> &ds = memoDs[v];

  if(ds.empty()) {

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

      if(v % d == 0) {

        ds.push_back(d);

        if(d*d != v) {

          ds.push_back(v/d);

        }

      }

    }

  }

  return ds;

}



ll calc(int a, int b) {

  if(a <= b) {

    // cerr << "HOGE" <<  " " << a << " " << b << endl;

    return -1;

  }

  if((n-1-b) % (a-b) != 0) {

    // cerr << "HOGE2" <<  " " << a << " " << b << endl;

    return -1;

  }

  ll k = (n-1-b) / (a-b);

  if(b % (a-b) == 0) {

    ll x = b / (a-b) + 1;

    if(x <= k-1) {

      // cerr << "HOGE3" <<  " " << a << " " << b << endl;

      return -1;

    }

  }

  // 落ちずに到着できる。

  ll res = 0;

  res += cs2[a-b][k-1];

  res += cs[a-b][k-1];

  // cerr << ">" << a << " " << b << " " << res << endl;

  return res;

}



int main(void) {

  scanf("%d", &n);

  REP(i, n) {

    scanf("%lld", &vs[i]);

  }

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

    ll cur = 0;

    cs[i].push_back(cur);

    for(int j = i; j < n; j += i) {

      cur += vs[j];

      cs[i].push_back(cur);

    }

  }

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

    ll cur = 0;

    cs2[i].push_back(cur);

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

      cur += vs[j];

      cs2[i].push_back(cur);

    }

  }



  ll res = 0;

  // for(int a = 2; a <= n-1; ++a) {

  //   int rem = (n-1) % a;

  //   if(rem == 0) {

  //     continue;

  //   }

  //   vector<int> ds = calcDs(rem);

  //   for(int d : ds) {

  //     int b = a - d;

  //     ll cur = calc(a, b);

  //     res = max(res, cur);

  //   }

  // }

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

    vector<int> ds = calcDs(n-1-b);

    for(int d : ds) {

      int a = b + d;

      ll cur = calc(a, b);

      res = max(res, cur);

    }

  }

  cout << res << endl;

  return 0;

}


// Optimized solution to the same problem (faster):


#include <cassert>

#include <cstdio>

#include <cstring>

#include <iostream>

#include <vector>

#include <queue>

#include <algorithm>

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

using namespace std;



typedef long long ll;



ll vs[100000+10];

int n;



int visited[100000+10];

// bool isOK1(ll ab, int i) {

//   ll a = n-1 - ab*i;

//   ll b = a - ab;

//   if(a <= 0 || b <= 0) return false;

// }



// int visited2[100000+10];

// int counter2;

// bool isOK2(ll ab, int i) {

//   ++counter2;

//   ll a = n-1 - ab*i;

//   ll b = a - ab;

//   if(a <= 0 || b <= 0) return false;

//   visited2[0] = counter2;

//   for(int pos = 0; ; ) {

//     pos += a;

//     if(pos >= n) return false;

//     if(visited2[pos] == counter2) return false;

//     visited2[pos] = counter2;

//     if(pos == n-1) {

//       return true;

//     }

//     pos -= b;

//     if(pos < 0) return false;

//     if(visited2[pos] == counter2) return false;

//     visited2[pos] = counter2;

//   }

// }



int main(void) {

  scanf("%d", &n);

  REP(i, n) {

    scanf("%lld", &vs[i]);

  }



  ll res = 0;

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

    ll leftSum = 0;

    ll rightSum = 0;

    for(int i = 1; ab*i < n && n-1-ab*i >= 0; ++i) {

      ll a = n-1 - ab*i;

      ll b = a - ab;

      if(a <= 0 || b <= 0) break;

      if(visited[ab*i] == ab) break;

      visited[ab*i] = ab;

      if(visited[n-1-ab*i] == ab) break;

      visited[n-1-ab*i] = ab;

      // bool x1 = isOK1(ab, i);

      // bool x2 = isOK2(ab, i);

      // if(x1 != x2) {

      //   ll a = 

      //   ll b = a - ab;

      //   cerr << "> " << x1 << " " << x2 << " " << ab << " " << i << " " << a << " " << b << " " << ab*i << " " << n-1-ab*i << endl;

      // }

      // if(!x2) break;

      leftSum += vs[ab*i];

      rightSum += vs[n-1-ab*i];

      res = max(res, leftSum + rightSum);

    }

  }

  cout << res << endl;

  return 0;

}


// Fastest known solution for this problem: