In a game, you start at coordinate 0 on a number line with lotuses at various coordinates. Each lotus has a value written on it. You can move forward or backward by choosing positive integers A and B. If you land on a lotus, your score increases by the value on that lotus. If you reach the end without landing on a lotus, you lose a huge number of points. The goal is to maximize your score. Given N lotuses and their values, find the maximum score achievable. Constraints: 3 ≤ N ≤ 10^5, -10^9 ≤ si ≤ 10^9, s0 = sN-1 = 0. Input format: N followed by N values. Output the maximum score. Example: Input: 5, 0 2 5 1 0. Output: 3.

# Buggy version:
import sys
input = sys.stdin.readline

n = int(input())
S = tuple(map(int, input().split()))
ans = 0
for c in range(1, n-1):
  temp = 0
  T = set()
  for k in range(1, (n-2)//c+1):
    d = c*k
    if d in T or n-1-d in T:
      break
    T.add(d)
    T.add(n-1-d)
    temp += S[d]+S[n-1-d]
    ans = max(ans, temp)
print(ans)

# Fixed version:
import sys
input = sys.stdin.readline

n = int(input())
S = tuple(map(int, input().split()))
ans = 0
for c in range(1, n-1):
  temp = 0
  T = set()
  for k in range(n):
    d = c*k
    if d+c >= n:
      break
    if d == n-1-d or d in T or n-1-d in T:
      break
    T.add(d)
    T.add(n-1-d)
    temp += S[d]+S[n-1-d]
    ans = max(ans, temp)
print(ans)

# Buggy version:
import sys
import time

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    s = list(map(int, readline().split()))
    ans = 0

    for c in range(1, n):
        dp = 0
        visited = set()
        for k in range(1, (n - 1) // c):
            forward = k * c
            backward = n - 1 - k * c
            if (forward in visited) or (backward in visited):
                break
            visited.add(forward)
            visited.add(backward)
            dp = dp + s[n - 1 - k * c] + s[k * c]
            ans = max(ans, dp)

    print(ans)


if __name__ == '__main__':
    main()


# Fixed version:
import sys
import time

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    s = list(map(int, readline().split()))
    ans = 0

    for c in range(1, n):
        dp = 0
        visited = set()
        for k in range(1, (n - 1) // c):
            forward = k * c
            backward = n - 1 - k * c
            if forward == backward:
                break
            if (forward or backward) in visited:
                break
            visited.add(forward)
            visited.add(backward)
            dp = dp + s[n - 1 - k * c] + s[k * c]
            ans = max(ans, dp)

    print(ans)


if __name__ == '__main__':
    main()

# Buggy version:
n=int(input())
s=list(map(int,input().split()))
t=[0]*n
for i in range(n):
    if i==n-1-i:
        continue
    t[i]+=s[i]+s[n-1-i]
ans=0
for c in range(1,n//2):
    num=0
    s_max=0
    if (n-1)%c!=0:
        for k in range((n-1)//c+1):
            num+=t[c*k]
            s_max=max(s_max,num)
    ans=max(ans,s_max)

print(ans)

# Fixed version:
n=int(input())
s=list(map(int,input().split()))
t=[0]*n
for i in range(n):
    if i==n-1-i:
        continue
    t[i]+=s[i]+s[n-1-i]
ans=0
for c in range(1,n//2):
    num=0
    s_max=0
    if (n-1)%c==0:
        for k in range((n//2)//c+1):
            if n//2<=c*k:
                break
            num+=t[c*k]
            s_max=max(s_max,num)
    else:
        for k in range((n-1)//c):
            num+=t[c*k]
            s_max=max(s_max,num)
    ans=max(ans,s_max)

print(ans)

# Buggy version:
import itertools
N = int(input())
S = [int(_) for _ in input().split()]

ans = 0
for i in range(1, N):
    if (N - 1) % i:
        maxj = N // i + 1
    else:
        maxj = N // i // 2 + 1
    if maxj < 1:
        continue
    ans = max(
        ans,
        max(
            itertools.accumulate([
                x + y for x, y in zip(S[-1:-1 - i * maxj:-i], S[:i * maxj:i])
            ])))
print(ans)


# Fixed version:
import itertools
N = int(input())
S = [int(_) for _ in input().split()]

ans = 0
for i in range(1, N - 1):
    maxj = (N - 1) // i
    if (N - 1) % i == 0:
        maxj = ((N - 1) // i + 1) // 2
    dp = itertools.accumulate(
        x + y for x, y in zip(S[:i * maxj:i], S[-1:-1 - i * maxj:-i]))
    ans = max(ans, max(dp))
print(ans)

# Buggy version:
N = int(input())
s = list(map(int, input().split(" ")))

ans = 0
for q in range(2, N):
    k = 0
    a1 = 0
    seen = set()

    p = N - 1 - k * q
    while p > 1:
        if p in seen:
            break
        seen.add(p)
        if k * q in seen:
            break
        seen.add(k * q)

        a1 = a1 + s[p] + s[k * q]
        ans = max(ans, a1)

        k += 1
        p = N - 1 - k * q

print(ans)


# Fixed version:
N = int(input())
s = list(map(int, input().split(" ")))

ans = 0
for q in range(1, N - 1):
    k = 0
    a1 = 0
    seen = set()

    p = N - 1 - k * q
    while p > q:
        if k * q in seen:
            break
        seen.add(k * q)
        if p in seen:
            break
        seen.add(p)

        a1 = a1 + s[p] + s[k * q]
        # print(p, p - q,  a1)
        ans = max(ans, a1)

        k += 1
        p = N - 1 - k * q

print(ans)

# Buggy version:
from collections import defaultdict
N = int( input())
S = list( map( int, input().split()))

ans = 0
for c in range(1,N):
    now = 0
    for t in range(c ,N, c):
        if ((N-1-t)%c == 0 and N-1-t <= t):
            break
        now += S[t] + S[N-1-t]
        print(now, t)
        if now > ans:
            ans = now
print(ans)

# Fixed version:
from collections import defaultdict
N = int( input())
S = list( map( int, input().split()))

ans = 0
for c in range(1,N):
    now = 0
    for t in range(c ,N, c):
        if ((N-1-t)%c == 0 and N-1-t <= t) or N-1-t - c <=0:
            break
        now += S[t] + S[N-1-t]
        if now > ans:
            ans = now
print(ans)

# Buggy version:
n = int(input())
s = list(map(int, input().split()))
ans = 0
for i in range(1, (n-1)//2+1):
	if i > 1 and (n-1)%i == 0:
		continue
	res = 0
	l, r = i, n-1-i
	while r > i and l != r:
		res += s[l] + s[r]
		ans = max(ans, res)
		l += i
		r -= i
print(ans)

# Fixed version:
n = int(input())
s = list(map(int, input().split()))
ans = 0
for i in range(1, (n-1)//2+1):
	res = 0
	l, r = i, n-1-i
	while r > i and l != r and l != r+i:
		res += s[l] + s[r]
		ans = max(ans, res)
		l += i
		r -= i
print(ans)

# Buggy version:
n = int(input())
s = list(map(int,input().split()))

ans = 0

for c in range(1,n-1):
  if (n-1)%c == 0:
    p = ((n-1)//c-1)//2 
  else:
    p = (n-1)//c-2
    if p <= 1:
      break
  if p <= 1:
    continue
  m = 0
  k = 0
  for i in range(1,p+1):
    k += s[c*i] + s[n-1-c*i]
    m = max(m,k)
  ans = max(ans,m)
    
    
print(ans)

# Fixed version:
n = int(input())
s = list(map(int,input().split()))

ans = 0

for c in range(1,n-1):
  if (n-1)%c == 0:
    p = ((n-1)//c-1)//2 
  else:
    p = (n-1)//c-1
    if p <= 0:
      break
  if p <= 0:
    continue
  m = 0
  k = 0
  for i in range(1,p+1):
    k += s[c*i] + s[n-1-c*i]
    m = max(m,k)
  ans = max(ans,m)
    
    
print(ans)