Problem:
 Score : 600 points    Problem Statement There is an infinitely large pond, which we consider as a number line.
In this pond, there are N lotuses floating at coordinates 0 , 1 , 2 , ..., N-2 and N-1 .
On the lotus at coordinate i , an integer s_i is written.  You are standing on the lotus at coordinate 0 . You will play a game that proceeds as follows:   1 . Choose positive integers A and B . Your score is initially 0 .  2 . Let x be your current coordinate, and y = x+A . The lotus at coordinate x disappears, and you move to coordinate y .  If y = N-1 , the game ends.  If y \neq N-1 and there is a lotus floating at coordinate y , your score increases by s_y .  If y \neq N-1 and there is no lotus floating at coordinate y , you drown. Your score decreases by 10^{100} points, and the game ends.    3 . Let x be your current coordinate, and y = x-B . The lotus at coordinate x disappears, and you move to coordinate y .  If y = N-1 , the game ends.  If y \neq N-1 and there is a lotus floating at coordinate y , your score increases by s_y .  If y \neq N-1 and there is no lotus floating at coordinate y , you drown. Your score decreases by 10^{100} points, and the game ends.    4 . Go back to step 2 .   You want to end the game with as high a score as possible.
What is the score obtained by the optimal choice of A and B ?      Constraints  3 \leq N \leq 10^5  -10^9 \leq s_i \leq 10^9  s_0=s_{N-1}=0  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  s_0  s_1  ......  s_{N-1}       Output Print the score obtained by the optimal choice of A and B .        Sample Input 1 5
0 2 5 1 0      Sample Output 1 3  If you choose A = 3 and B = 2 , the game proceeds as follows:   Move to coordinate 0 + 3 = 3 . Your score increases by s_3 = 1 .  Move to coordinate 3 - 2 = 1 . Your score increases by s_1 = 2 .  Move to coordinate 1 + 3 = 4 . The game ends with a score of 3 .   There is no way to end the game with a score of 4 or higher, so the answer is 3 . Note that you cannot land the lotus at coordinate 2 without drowning later.       Sample Input 2 6
0 10 -7 -4 -13 0      Sample Output 2 0  The optimal strategy here is to land the final lotus immediately by choosing A = 5 (the value of B does not matter).       Sample Input 3 11
0 -4 0 -99 31 14 -15 -39 43 18 0      Sample Output 3 59

Solution (Python):
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())
s = list(map(int, input().split()))

D = [[]]
for i in range(1, N):
  DD = []
  T = [0]
  for j in range(i, N, i):
    T.append(T[-1] + s[j])
  DD.append(T)
  T = [0]
  start = (N - 1) % i
  if start == 0: start += i
  for j in range(start, N, i):
    T.append(T[-1] + s[j])
  DD.append(T)
  D.append(DD)

ans = s[-1]
cnt = 0
for n in range(2, N - 1):
  end = N - 1 - n
  for m in make_divisors(end):
    if n <= m: break
    if n % m == 0 and end >= n: continue
    k = end // m
    a = D[m][0][k]
    l = len(D[m][1])
    b = D[m][1][-1] - D[m][1][l - k - 2]
    ans = max(ans, a + b)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = 0
for d in range(1, N):
  s = set()
  t = 0
  for k in range(N):
    i = d * k
    if i + d >= N: break
    if i in s: break
    if N - 1 - i in s: break
    if i == N - 1 - i: break
    s.add(i)
    s.add(N - 1 - i)
    t += a[i]
    t += a[N - 1 - i]
    res = max(res, t)
print(res)

Solution (Python):
N = int(input())
S = list(map(int,input().split()))

ans = 0
for d in range(1,N):
    max_now = 0
    if (N-1) % d == 0:
        now = 0

        i, j = 0, N-1
        while i < j:
            now += S[i] + S[j]
            max_now = max(now, max_now)
            i += d
            j -= d
    else:
        now = 0

        i, j = 0, N-1
        while i < N-1 and j > d:
            now += S[i] + S[j]
            max_now = max(now, max_now)
            i += d
            j -= d
    
    ans = max(max_now, ans)

print(ans)

Solution (Python):
N = int(input())
S = list(map(int,input().split()))

ans = 0
for d in range(1,N):
    max_now = 0
    if (N-1) % d == 0:
        now = 0

        i, j = 0, N-1
        while i < j:
            now += S[i] + S[j]
            max_now = max(now, max_now)
            i += d
            j -= d
    else:
        now = 0

        i, j = 0, N-1
        while i < N-1 and j > d:
            now += S[i] + S[j]
            max_now = max(now, max_now)
            i += d
            j -= d
    
    ans = max(max_now, ans)

print(ans)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
max_val = 0
for diff in range(1, n):
    visited = set()

    j = n - 1 - diff
    i = diff

    val = 0
    while i < n - 1 - diff and j > diff :
        if j in visited or i in visited or j == i:
            break
        visited.add(j)
        visited.add(i)
        val += s[j] + s[i]
        i += diff
        j -= diff
        if max_val < val:
            max_val = val
print(max_val)

Solution (Python):
N=int(input())
s=list(map(int,input().split()))

ans=0
for a in range(1,N):
    Sf=0
    Sb=0
    used=[False]*((N-1)//a+1)
    for j in range((N-2)//a):
        Sf+=s[a*j]
        Sb+=s[N-1-a*j]
        if used[j]:
            break
        else:
            used[j]=True
        if (N-1-a*j)%a==0:
            if used[(N-1-a*j)//a]:
                break
            else:
                used[(N-1-a*j)//a]=True
        temp=Sf+Sb
        ans=max(ans,temp)

print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, input().split()))

ans = 0
for d in range(1, N//2):
    tmp = 0
    checked = set()
    for t in range(N//d):
        ind = d*t
        if ind + d >= N-1 or ind in checked or ind == N - 1 - ind: break
        tmp += A[ind] + A[-ind-1]
        checked.add(N-1-ind)
        ans = max(ans, tmp)
print(ans)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
def examA():
    A, P = LI()
    ans = (A*3+P)//2
    print(ans)
    return

def examB():
    N = I()
    SP = [[]for _ in range(N)]
    for i in range(N):
        SP[i] = LSI()
        SP[i][1] = int(SP[i][1])
        SP[i].append(i)

    SP = sorted(SP,key = lambda x:x[1], reverse = True)
    SP = sorted(SP,key = lambda x:x[0])

    for v in SP:
        print(v[2]+1)
    return

def examC():
    N, M = LI()
    S = [LI() for _ in range(M)]
    P = LI()
    ans = 0
    loop = 2**N
    for i in range(loop):
        flag = True
        d = defaultdict(bool)
        for j in range(N):
            if i&(1<<j)==(1<<j):
                d[j+1] = True
        for l,j in enumerate(S):
            cur = 0
            for k in range(1,j[0]+1):
                if d[j[k]]:
                    cur +=1
            if cur%2!=P[l]:

                flag = False
                break
        if flag:
            ans +=1
    print(ans)

    return

def examE():
    
    class SegmentTree:
        def __init__(self, n, ele, segfun):
            
            self.ide_ele = ele
            self.segfun = segfun
            
            self.n = n
            self.N0 = 1 << n.bit_length()
            self.data = [self.ide_ele] * (self.N0 * 2)

        def update_add(self, l, r, val):
            l += self.N0
            r += self.N0
            while l < r:
                if l & 1:
                    self.data[l] += val
                    l += 1
                if r & 1:
                    self.data[r - 1] += val
                    r -= 1
                l //= 2
                r //= 2

        def update(self, l, r, val):
            l += self.N0
            r += self.N0
            while l < r:
                if l & 1:
                    self.data[l] = self.segfun(self.data[l], val)
                    l += 1
                if r & 1:
                    self.data[r - 1] = self.segfun(self.data[r - 1], val)
                    r -= 1
                l //= 2
                r //= 2

        def query(self, i):
            i += len(self.data) // 2
            ret = self.data[i]
            while i > 0:
                i //= 2
                ret = self.segfun(ret, self.data[i])
            return ret
    N, Q = LI()
    X = [LI() for _ in range(N)]
    D = [I() for _ in range(Q)]
    S = SegmentTree(Q+N,inf,lambda a, b: min(a,b))
    QD = []
    for s,t,x in X:
        QD.append([max(0,s-x),t-x,x,0])
    for d in D:
        QD.append([d,1])
    QD.sort(key = lambda x:x[0])
    print(QD)
    ans = []
    for l in QD:
        if l[-1]==0:
            S.update(l[0],l[1],l[2])
        else:
            ans.append(S.query(l[0]))
    for v in ans:
        if v==inf:
            print(-1)
            continue
        print(v)
    return


def examF():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    def judge(a,c,k):
        if gcd(a,c)==c:
            if c*k>=a:
                return False
        return True
    N = I()
    S = LI()
    ans = -inf
    N -= 1
    F = [defaultdict(int)for _ in range(N)]
    for c in range(1,N):
        K = (N-1)//c
        for k in range(K):
            F[c][k+1] = F[c][k] + S[N-k*c] + S[k*c]
            
            a = N - (k+1)*c + c
            cur = F[c][k+1]
            if judge(a,c,k):
                if ans<cur:
                    ans = cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examF()

Solution (Python):




n=int(input())
*s,=map(int, input().split())
n-=1
tmp=0
ans=0
for c in range(1,n+1):
    if n%c==0:
        l=0;r=n
        tmp=0
        while l<r:
            tmp+=s[l]+s[r]
            l+=c;r-=c
            ans=max(tmp,ans)

        ans=max(tmp,ans)
    else:
        l=0;r=n
        tmp=0
        while l<n and r>c:
            tmp+=s[l]+s[r]
            l+=c;r-=c
            ans=max(tmp,ans)

        ans=max(tmp,ans)
print(ans)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))

ans = 0
for step in range(1, n):
    now = 0
    for i, j in zip(range(0, n, step), range(n - 1, -1, -step)):
        if i == j or i - j == step or j < step:
            break
        now += s[i] + s[j]
        ans = max(ans, now)
print(ans)

Solution (Python):
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	S = getlist()
	ans = 0
	for i in range(1, N):
		if (N - 1) % i == 0:
			var = 0
			left = 0; right = 0
			cnt = 0
			while True:
				if 2 * i * cnt >= N - 1:
					break
				left += S[i * cnt]
				right += S[N - 1 - i * cnt]
				var = max(var, left + right)
				cnt += 1

			ans = max(ans, var)

		else:
			var = 0
			left = 0; right = 0
			cnt = 0
			while True:
				if i * cnt > N - 1 - i:
					break
				left += S[i * cnt]
				right += S[N - 1 - i * cnt]
				var = max(var, left + right)
				cnt += 1

			ans = max(ans, var)

	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
N = int(input())
s = list(map(int,input().split()))

ans = 0
for c in range(1,N-1):
    ltor = [0]
    for p in s[::c]:
        ltor.append(ltor[-1] + p)
    rtol = [0]
    for p in s[N-1::-c]:
        rtol.append(rtol[-1] + p)
    A = N-1-c
    while c < A:
        if A % c == 0 and A + c * (A//c-1) < N-1:
            break
        ind = (N-1-A)//c+1
        temp = ltor[ind] + rtol[ind]
        ans = max(temp,ans)
        A -= c

print(ans)

Solution (Python):
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()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
S = list(map(int, input().split()))
N -= 1
ans = 0
for d in range(1,N+1):
    a = N-d
    res = 0
    p,q = N,0
    while a >= d:
        if a <= N-a and N%d == 0:
            break
        p -= d
        q += d
        res += S[p] + S[q]
        if res > ans:
            ans = res
        a -= d
    
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))

ans = 0
for c in range(1,n):
    now = 0
    pas = set()
    for k in range(1,n):
        if k * c > n-1 or n-1-k*c <= c:
            break
        if n-1-k*c in pas or k*c in pas or n-1 == 2*k*c:
            break 
        now += l[n-1-k*c] + l[k*c]
        pas.add(n-1-k*c)
        pas.add(k*c)
        ans = max(ans,now)
        
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))

ans = 0
for c in range(1,n):
    now = 0
    pas = set()
    for k in range(1,n):
        if k * c > n-1 or n-1-k*c <= c:
            break
        if n-1-k*c in pas or k*c in pas or n-1 == 2*k*c:
            break 
        now += l[n-1-k*c] + l[k*c]
        pas.add(n-1-k*c)
        pas.add(k*c)
        ans = max(ans,now)
        
print(ans)

Solution (Python):
n = int(input()) - 1
s = list(map(int, input().split()))
ans = 0
for i in range(1,(n+1)//2):
  tmp = 0
  if (n % i):
    for a,b in zip(s[n-i:i:-i],s[i::i]):
      tmp += a+b
      ans = max(ans,tmp)
  else:
    for k,(a,b) in enumerate(zip(s[n-i::-i],s[i::i]),1):
      if n <= 2*k*i:
        break
      tmp += a+b
      ans = max(ans,tmp)
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    s = list(map(int, rl().split()))
    
    ans = 0
    for c in range(1, N):
        cur = 0
        tmp = 0
        i, j = 0, N - 1
        if (N - 1) % c == 0:
            while i < j:
                cur += s[i] + s[j]
                tmp = max(tmp, cur)
                i += c
                j -= c
        else:
            while i < N - 1 and c < j:
                cur += s[i] + s[j]
                tmp = max(tmp, cur)
                i += c
                j -= c
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
N, = map(int, input().split())
X = list(map(int, input().split()))
r = 0
for d in range(1, N):
    s = 0
    vs = set([0, N-1])
    for ld in range(d, N-d, d):
        bld = N-ld-1
        vs.add(bld)
        if ld in vs:
            break
        s += X[ld] + X[bld]
        r = max(s, r)
print(r)

Solution (Python):
N, = map(int, input().split())
X = list(map(int, input().split()))
r = 0
for d in range(1, N):
    s = 0
    vs = set([0, N-1])
    for ld in range(d, N-d, d):
        bld = N-ld-1
        vs.add(bld)
        if ld in vs:
            break
        vs.add(ld)
        s += X[ld] + X[bld]
        r = max(s, r)
print(r)

Solution (Python):
N, = map(int, input().split())
X = list(map(int, input().split()))
r = 0
for d in range(1, N):
    s = 0
    vs = set([0, N-1])
    for ld in range(d, N, d):
        bld = N-ld-1
        vs.add(bld)
        if ld in vs or bld < d:
            break
        vs.add(ld)
        s += X[ld] + X[bld]
        r = max(s, r)
print(r)

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    N = int(input())
    S = read_list()

    res = V(max, 0)
    for c in range(1, N):
        r = 0
        t1 = 0
        while True:
            t1 += c
            if t1 > N - 1 - c:
                break
            
            if (N - 1) % c == 0 and 2 * t1 >= N - 1:
                break

            r += S[t1] + S[N - 1 - t1]
            res.ud(r)

    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    N = int(input())
    S = read_list()

    res = V(max, 0)
    for c in range(1, N):
        r = 0
        t1 = 0
        t2 = N - 1
        while True:
            t1 += c
            t2 -= c
            if t2 < c:
                break
            
            if (N - 1) % c == 0 and 2 * t2 <= N - 1:
                break

            r += S[t1] + S[t2]
            res.ud(r)

    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    N = int(input())
    S = read_list()

    res = V(max, 0)
    for c in range(1, N):
        r = 0
        t1 = 0
        t2 = N - 1
        a = t2 - c
        while True:
            if a < c:
                break
            
            if (N - 1) % c == 0 and 2 * a <= N - 1:
                break

            t1 += c
            t2 -= c
            a -= c
            r += S[t1] + S[t2]
            res.ud(r)

    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc128/tasks/abc128_f

左端から一定個数おきにおいていく(好きな個数だけ)。
これを中心に対して反転したときに、重ならないならば、反転してor演算したものは構成可能
あとは、1～N-1に関して約数を探索するので計算量は
O(N√N)

コーナーケースっぽいwa!!
→うーんなんだろう？
→半分以上に関しては不可能なので、0にしておくべき？

左から並べたやつの右端より右に少なくとも1つの右が必要
"""

N = int(input())

s = list(map(int,input().split()))
now = [0] * N
ans = [0] * N

for i in range(1,N):

    j = 1

    while j ** 2 <= i:

        if i % j == 0:

            if (N-1) % j == 0 and 2+i*2 > N:
                pass
            elif i + j > N:
                pass
            else:
                
                now[j] += s[i] + s[N-1-i]
                ans[j] = max(ans[j],now[j])

        if i % j == 0 and j**2!=i:

            j2 = i // j

            if (N-1) % j2 == 0 and 2+i*2 > N:
                pass
            elif i+j2 > N:
                pass
            else:
                
                now[j2] += s[i] + s[N-1-i]
                ans[j2] = max(ans[j2],now[j2])

        j+=1
    

pra = 0
for i in range(0,N//2):
    pra = max(pra,ans[i])


print (pra)

Solution (Python):
n = int(input())
s = tuple(map(int,input().split()))



ans = 0
for b in range(1,(n-1)//2):
    point = 0
    count = 0
    for a in range((n-1-b), b, -b):
        if( a%b == 0)&( 2*a <= n-1):
            break
        count += 1
        point += s[b*count] + s[a]
        ans = max(point, ans)

print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = list(map(int, input().split()))

    X = [[0] for _ in range(N)]
    Y = [[0] for _ in range(N)]
    for k in range(1, N):
        for i in range(1, N):
            if i*k >= N:
                break
            X[k].append(X[k][-1] + S[i*k])
    for k in range(1, N):
        for i in range(1, N):
            if i*k >= N:
                break
            Y[k].append(Y[k][-1] + S[-i*k-1])
    ans = 0
    for k in range(1, N):
        for i in range(N):
            if i*k == N-1-i*k:
                break
            if k*(i-1) == N-1-i*k:
                break
            if k*(i+1) >= N-1:
                break
            ans = max(ans, X[k][i] + Y[k][i])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    s = LI()
    ans = 0
    for c in range(1,n+1):
        K = (n-1)//c
        dp = 0
        S = set([0,n-1])
        for k in range(1,K+1):
            a = i = n-1-k*c
            if i in S:
                break
            b = a-c
            if b >= a or b <= 0:
                break
            S.add(i)
            j = k*c
            if j in S:
                break
            S.add(j)
            cost = s[i]+s[j]
            dp += cost
            if ans < dp:
                ans = dp
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
s = [int(i) for i in input().split()]
ans = 0
for i in range(1, N-2):
    p = 0
    a = N-1
    k = 0
    while True:
        k += 1
        a -= i
        b = a-i
        if b>0 and a!= N-1-a and a!=N-1-a-i:
            p += (s[a] + s[N-1-a])
            ans = max(ans, p)
        else:
            break
print(ans)

Solution (Python):
from itertools import accumulate

N, *S = map(int, open(0).read().split())

ans = 0
for dx in range(1, N - 1):

    k, r = divmod(N - 1, dx)
    if r == 0:
        k = (k + 1) // 2

    ans = max(ans, max(accumulate(a + b for a, b in zip(S[:dx * k:dx], S[N - 1:(N - 1) - dx * k:-dx]))))

print(ans)

Solution (Python):
N, = map(int, input().split())
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
    a = (N-1) % k
    for _ in range(1+(N-1-a)//k):
        b = a - k
        n = (N-1-a)//k
        if a <= b or a <= k:
            a += k
            continue
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                a += k
                continue
    if a >= N-1:
        continue
    s1 = a
    s2 = n * (a-b)
    t = xs[s1]
    for i in range(n):
        s1 += a-b
        t += xs[s2]
        t = max(t,0)
        t += xs[s1]
        s2 -= a-b
    r = max(r, t)
print(r)

Solution (Python):
N, = map(int, input().split())
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
    a = (N-1) % k
    b = a - k
    n = (N-1-a)//k
    if a <= k:
        a += k
    if a <= k:
        a += k

    for _ in range((N-1-a)//k):
        b = a - k
        n = (N-1-a)//k
        if a <= b:
            a += k
            continue
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                a += k
                continue
    if a <= b or a >= N-1:
        continue
    s1 = a
    s2 = n * (a-b)
    t = xs[s1]
    ps = [(s1,t)]
    for i in range(n):
        s1 += a-b
        t += xs[s2]
        t = max(t,0)
        t += xs[s1]
        ps.append((s2,xs[s2]))
        ps.append((s1,xs[s1]))
        s2 -= a-b
    
    r = max(r, t)

print(r)

Solution (Python):
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)

Solution (Python):
N = int(input())
S = [int(a) for a in input().split()]
ma = 0
for C in range(1, N-1):
    s = 0
    for k in range((N-2) // C):
        A = N-1-k*C
        if A % C == 0 and A//C <= k: continue
        s += S[k*C] + S[-1-k*C]
        ma = max(ma, s)

print(ma)

Solution (Python):
N = int(input())
s = list(map(int, input().split()))
ans = 0
for c in range(1, N):
    res = 0
    for k in range(1, (N-1)//c+1):
        a = N-1-c*k
        b = a-c
        res+=s[c*k]+s[-c*k-1]
        if b<0 or (a%c==0 and a//c<=k) :
            continue
        ans = max(ans, res)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    S=list(map(int,input().split()))
    ans=0
    for d in range(1,n):
        score=0
        P=set()
        for x in range(n//d):
            a=(n-1)-x*d
            if(a<=d): break
            if((x*d in P) or (n-1-x*d in P)): break
            if(x*d==n-1-x*d): break
            score+=S[x*d]
            score+=S[n-1-x*d]
            P.add(x*d)
            P.add(n-1-x*d)
            ans=max(ans,score)
    print(ans)
resolve()

Solution (Python):
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)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
S = np.array(read().split(),np.int64)

answer = 0
for d in range(1,N):
    n = (N-1)//d
    if (N-1)%d == 0:
        n = ((N-1)//d+1)//2
    if n <= 1:
        continue
    x = (S[d:d*n:d] + S[N-1-d:N-1-d*n:-d]).cumsum().max()
    if answer < x:
        answer = x

print(answer)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

N = int(readline())
S = list(map(int,read().split()))

answer = 0
for d in range(1,N):
    n = (N-1)//d
    if (N-1)%d == 0:
        n = ((N-1)//d+1)//2
    if n <= 1:
        continue
    x = max(itertools.accumulate(x+y for x,y in zip(S[d:d*n:d],S[N-1-d:N-1-d*n:-d])))
    if answer < x:
        answer = x

print(answer)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
S = np.array(read().split(),np.int64)

def F(d):
    
    L = S[:-d:d].cumsum()
    R = S[::-1][:-d:d].cumsum()
    if (N-1)%d == 0:
        n = (N-1)//d
        x = np.arange(1,n+1)
        bl = (x+x <= n+1)
        L = L[bl]; R = R[bl]
    return (L+R).max()

def G(n):
    
    D = (N-1-n)//n
    L = np.zeros(D+1,np.int64)
    R = np.zeros(D+1,np.int64)
    for i in range(1,n+1):
        L += S[:i*(D+1):i]
        R += S[::-1][:i*(D+1):i]
    ok = np.ones(D+1,np.bool)
    overlap = (np.arange(D+1) * (n+n) >= N-1)
    overlap[1:] &= ((N-1)%np.arange(1,D+1) == 0)
    x = L+R
    x[overlap] = 0
    return x.max()

L = int((N-1)**.5 + 10)
L = min(N-1,L)

x = max(F(n) for n in range(1,L+1))
y = max(G(n) for n in range(1,L+1))
answer = max(x,y)
print(answer)

Solution (Python):
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]
        
        ans = max(ans, a1)

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

print(ans)

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

n = int(input())
s = [int(i) for i in readline().split()]

n -= 1
ans = 0

for d in range(1,n+1):
    a = n-d
    res = 0
    p,q = n,0
    while a >= d:
        if a <= n-a and n%d == 0: break
        p -= d
        q += d
        res += s[p] + s[q]

        if res > ans: ans = res
        a -= d
    
print(ans)

Solution (Python):
def main():
    N = int(input())
    S = list(map(int, input().split()))
    ans = 0
    for C in range(1, N//2+1):
        cs = 0
        for k in range(1, (N-1)//C+1):
            a = C*k
            b = N - a - 1
            if a >= b and (N-1) % C == 0:
                break
            if b <= C:
                break
            cs += S[a] + S[b]
            ans = max(cs, ans)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
ss = list(map(int, input().split()))

ans = 0
for C in range(1, N):
    score = 0
    for k in range(1, (N-1)//C+1):
        if (N-1)%C == 0 and k*C >= N-1-k*C: break
        if N-1-k*C <= C: break
        score += ss[k*C] + ss[N-1-k*C]
        ans = max(ans, score)

print(ans)

Solution (Python):
n = int(input())
a = [int(item) for item in input().split()]

ans = 0
for c in range(1, n):
    visited = set([0, n-1])
    total = 0
    for k in range(1, n):
        odd = n - 1 - k*c
        even = k * c
        if even >= n - 1:
            break
        if odd < c:
            break
        if even in visited:
            break
        visited.add(even)
        if odd in visited:
            break
        visited.add(odd)
        total += a[odd] + a[even]
        ans = max(ans, total)
        
        
print(ans)