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):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()
    alist = intina()

    ans = 0

    for i in range(1, n//2):
        lsum = 0
        for j in range(1, n):
            down = n - i * j - 1
            up = i * j
            if (down <= up and down % i == 0):
                break
            if (down <= i):
                break
            if (n - 1 - up <= i):
                break
            lsum += alist[down]
            lsum += alist[up]
            ans = max(ans, lsum)

    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0

for d in range(1, n):
    temp = 0
    L = 0
    R = n-1
    if (n-1) % d == 0:
        while L < R:
            temp += s[L] + s[R]
            ans = max(ans, temp)
            L += d
            R -= d
    else:
        while L + d < n-1:
            temp += s[L] + s[R]
            ans = max(ans, temp)
            L += d
            R -= d

print(ans)

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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


def count_max(diff):
    
    b = 0
    a = N - 1
    ret = 0
    cumsum = 0
    while diff < a and a != b and b - a != diff:
        cumsum += S[b] + S[a]
        ret = max(ret, cumsum)
        b += diff
        a -= diff
    return ret


ans = 0
for diff in range(1, N // 2 + 1):
    ans = max(ans, count_max(diff))
print(ans)

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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


def count_max(diff):
    
    b = 0
    a = N - 1
    ret = 0
    cumsum = 0
    while diff < a and a != b and b - a != diff:
        cumsum += S[b] + S[a]
        ret = max(ret, cumsum)
        b += diff
        a -= diff
    return ret


ans = 0
for diff in range(1, N // 2 + 1):
    ans = max(ans, count_max(diff))
print(ans)

Solution (Python):
N=int(input())
s=[int(i) for i in input().split()]
ans=0
for c in range(1,N):
  k=0
  Score=0
  while k*c<N-1:
    a=N-1-k*c
    if ((N-1)%c==0 and k*c>=a) or a<=c:
      break
    Score+=s[k*c]+s[a]
    
    ans=max(Score,ans)
    k+=1
print(ans)

Solution (Python):
N = int(input())
slist = list(map(int, input().split()))
ans = 0
for C in range(1,N-1,1):
    score = 0
    for k in range((N-1)//C):
        if (k-1)*C == N-1-k*C: 
            break
        if 2*k*C == N-1: 
            break
        score += slist[k*C]+slist[N-1-k*C]
        ans = max(ans, score)
print(ans)

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

ans = 0
for C in range(1, n):
    f = 0
    for k in range([int(((n - 1) / C + 1) / 2), int((n - 1) / C)][(n - 1) % C != 0]):
        f += a[k * C] + a[(n - 1) - k * C]
        ans = max(ans, f)
print(ans)

Solution (Python):
def solve2():
    N = int(raw_input())
    s = [int(_) for _ in raw_input().split()]
    ans = 0
    pass_set = set()
    for C in range(1, N - 1):
        pass_set.clear()
        maxK = (N - 1) / C
        score = 0 
        for k in range(1, maxK+1):
            if N - 1 - k*C < C:
                break
            if (N-1-k*C) in pass_set or k*C in pass_set or (N-1-k*C) == k*C:
                break
            else:
                score += s[N-1-k*C] + s[k*C] 
                pass_set.add(N-1-k*C)
                pass_set.add(k*C)
            ans = max(ans, score)
    print ans

if __name__ == '__main__':
    solve2()

Solution (Python):
N=int(input())
S=[int(i) for i in input().split()]
T=[set() for i in range(N)]
dp=[0]*(N)
ans=0
mod=10**17
for k in range(1,N):
    for c in range(1,N):
        if k*c>=N-1:
            break
        dp[c]=dp[c]+S[N-1-k*c]+S[k*c]
        a=(N-1-k*c)
        b=a-c
        if b<=0 or (N-1-k*c==k*c) or (N-1-k*c in T[c]) or (k*c in T[c]) :
            dp[c]=-mod
        T[c].add(N-1-k*c)
        T[c].add(k*c)
        ans=max(ans,dp[c])
    
print(ans)

Solution (Python):
n,*s=map(int,open(0).read().split());a=0
for i in range(1,n):
 t=0
 for j in range(0,[n//2,n+~i][(n-1)%i>0],i):t+=s[j]+s[~j];a=max(a,t)
print(a)

Solution (Python):
N = int(input())
s = list(map(int, input().split()))
ans = 0
for C in range(1,N):
    t = 0
    for x in range(C, N-1-C if (N-1)%C != 0 else N//2, C):
        t += s[x] + s[-x-1]
        ans = max(ans, t)
print(ans)

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

ans = 0
for C in range(1,N):
    dp = 0
    for k in range((N-1)//C):
        if (2*k-1)*C == N-1 or 2*k*C == N-1:
            break
        dp += S[N-1-C*k]+S[C*k]
        ans = max(ans,dp)

print(ans)

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

ans = 0
for C in range(1,N):
    dp = 0
    for k in range((N-1)//C):
        if (2*k-1)*C == N-1 or 2*k*C == N-1:
            break
        dp += S[N-1-C*k]+S[C*k]
        ans = max(ans,dp)

print(ans)

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

Solution (Python):

n = int(input())
s = list(map(int, input().split()))
ans = 0
for d in range(1, n - 1):
    ten = 0
    passed = set([0, n - 1])
    l = 0
    r = n - 1
    for _ in range((n - 1) // d):
        l += d
        r -= d
        if l in passed or r in passed or l==r or r < d:
            break
        ten += s[l]
        ten += s[r]
        passed.add(l)
        passed.add(r)
        if ten > ans:
            ans = ten
print(ans)

Solution (Python):
N = int(input())
s = [int(i) for i in input().split()]

ret = 0
for c in range(1, N) :
    k = 1
    tmp = 0
    flag = (N - 1) % c == 0
    while c * k < N - 1 :
        l = c * k
        r = N - 1 - l

        if (flag and r <= l) or r <= c:
            break

        tmp += s[l] + s[r]
        ret = max(ret, tmp)
        k += 1

print(ret)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))

    ans = 0
    
    for C in range(1, N//2):
        n = (N-1) // C
        point = 0
        for k in range(1, n):
            A = N-1 - k*C

            
            
            
            
            
            
            
            if A < C or ((N-1) % C == 0 and A <= k*C):
                break

            point += S[A] + S[k*C]
            ans = max(ans, point)

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    S = LI()
    S = S[:-1]
    ans = 0
    for C in range(1, N):
        tmp = 0
        L = 0
        lim = (N - 1 - C) if (N - 1) % C else (N // 2)
        while L < lim:
            tmp += S[L] + S[-L]
            ans = max(ans, tmp)
            L += C
    return ans

print(main())

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    S = LI()
    ans = 0
    for C in range(1, N):
        tmp = 0
        L = 0
        lim = (N - 1 - C) if (N - 1) % C else (N // 2)
        while L < lim:
            tmp += S[L] + S[-1 - L]
            ans = max(ans, tmp)
            L += C
    return ans

print(main())

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    S = LI()
    ans = 0
    for C in range(1, N):
        tmp = 0
        L = 0
        R = N - 1
        lim = (N - 1 - C) if (N - 1) % C else (N // 2)
        while L < lim:
            tmp += S[L] + S[R]
            ans = max(ans, tmp)
            L += C
            R -= C
    return ans

print(main())

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))

    ans = 0
    for C in range(1, N//2):
        n = N // C
        point = 0
        used = set([0])
        for k in range(1, n):
            A = N - 1 - k*C

            if A in used or k*C in used or A == k*C:
                break
            used.add(A)
            used.add(k*C)

            point += S[A] + S[k*C]
            ans = max(ans, point)

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))

    ans = 0
    for C in range(1, N):
        n = N // C
        dp = [0] * n
        used = set([0])
        for k in range(1, n):
            A = N - 1 - k*C
            if A in used or k*C in used or A == k*C:
                break
            used.add(A)
            used.add(k*C)

            dp[k] = dp[k-1] + S[A] + S[k*C]

        ans = max(ans, max(dp))

    return ans


if __name__ == '__main__':
    print(main())

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

ans = 0
for C in range(1, N):
    fkC = 0
    L = 0
    R = N-1
    if ((N-1) % C == 0):
        while L < R:
            fkC += S[L] + S[R]
            ans = max(ans, fkC)
            L += C
            R -= C
    else:
        while L+C < N-1:
            fkC += S[L] + S[R]
            ans = max(ans, fkC)
            L += C
            R -= C

print(ans)

Solution (Python):
import numpy as np

N = int(input())
S = np.array([int(x) for x in input().split()],dtype=np.int64)




answer = 0
for d in range(1,N):
  
  cum_left = np.cumsum(S[::d])
  cum_right = np.cumsum(S[::-1][::d])
  score = cum_left + cum_right 
  
  for L,s in enumerate(score):
    if answer >= s:
      continue
    
    A = N-1-L*d
    B = A-d
    if A <= 0:
      continue
    if A<=B:
      continue
    if B<=0:
      continue
    
    
    
    if (N-1)%d == 0 and 2*L*d >= N-1:
      continue
    answer = s

print(answer)

Solution (Python):
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    s = LI()

    """
    A+kC=N-1
    A=N-1-kC
    0,A     ,C, A+C       ,2C,A+2C      ,3C,A+3C      =N-1
    0,N-1-kC,C, N-1-(k-1)C,2C,N-1-(k-2)C,3C,N-1-(k-3)C=N-1
    """

    ans = 0
    for c in range(1, N):
        score = 0
        hass = set([0, N-1])

        for k in range(1, (N - 1) // c):
            if k * c in hass or N - 1 - (k * c) in hass or N - 1 - (k * c) == k * c:
                score = -inf
                break
            
            score += s[N - 1 - (k * c)] + s[k * c]
            hass.add(N - 1 - (k * c))
            hass.add(k * c)

            
            ans = max(ans, score)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
s=[int(i) for i in input().split()]
ans=0
for C in range(1,N):
    fkC=0
    L=0;R=N-1
    if ((N-1)%C==0):
        while(L<R):
            fkC+=s[L]+s[R]
            ans=max(ans,fkC)
            L+=C
            R-=C
    else:
        while(L+C<N-1):
            fkC+=s[L]+s[R]
            ans=max(ans,fkC)
            L+=C
            R-=C
print(ans)

Solution (Python):
import sys
def single_input(F): return F.readline().strip("\n")
def line_input(F): return F.readline().strip("\n").split()
  
def solve():
    F = sys.stdin
    N = int(single_input(F))
    S = [int(s) for s in line_input(F)]
    
    maxpoint = 0
    for c in range(1, N//2):
        s, l = 0, N-1
        point = 0
        if (N-1) % c == 0:
            while l > s and l > c:
                point += S[s] + S[l]
                maxpoint = max(point, maxpoint)
                s += c
                l -= c
        else:
            while l != s and l > c:
                point += S[s] + S[l]
                maxpoint = max(point, maxpoint)
                s += c
                l -= c
    print(maxpoint)
    return 0
  
if __name__ == "__main__":
    solve()

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

ans = 0
for c in range(1, N):
    a = 0
    if (N-1) % c:
        for i in range(1, (N-1)//c):
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
    else:
        se = set(list(range(N)))
        for i in range(1, (N-1)//c):
            if i*c not in se or N-1-i*c not in se or i*c == N-1-i*c:
                break
            se.remove(i*c)
            se.remove(N-1-i*c)
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
print(ans)

Solution (Python):
n,*s=map(int,open(0).read().split())
m=0
for i in range(1,n):
    t=0
    for j in range(0,n,i):
        k=n-1-j
        if k<i or k%i<1 and k<=j:break
        t+=s[j]+s[k]
        if t>m:m=t
print(m)

Solution (Python):
n,*s=map(int,open(0).read().split())
m=0
for i in range(1,n):
    t=0
    for j in range(0,n,i):
        k=n-1-j
        if k<i or k%i<1 and k<=j:break
        t+=s[j]+s[k]
        if t>m:m=t
print(m)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
MINUS_INF = -float("inf")
ans = 0
for c in range(1, n):
    k = 1
    tmp_ans = 0
    while k * c < n - 1:
        a = (n - 1) - k * c
        b = a - c
        if a <= b or b <= 0:
            tmp_ans = MINUS_INF
        if a % c == 0 and a // c <= k:
            tmp_ans = MINUS_INF
        tmp_ans += s[n-1-k*c] + s[k*c]
        ans = max(ans, tmp_ans)    
        k += 1    
print(ans)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
ans = 0
for i in range(1, n):
  l = 0
  r = n-1
  cur = 0
  while True:
    l += i
    r -= i
    if l>=n or r<=i or (r%i==0 and r<=l):
      break
    cur += s[l] + s[r]
    ans = max(ans, cur)
print(ans)

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

ans = 0
for d in range(1, (n-1)//2+1):
    ans_cur = 0
    l, r = 0, n-1
    while r > d and l != r and l != r+d:
        ans_cur += s[l]+s[r]
        ans = max(ans, ans_cur)
        l += d
        r -= d
print(ans)

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

Solution (Python):
def f_frog_jump(N, S):
    ans = 0
    for c in range(1, N):
        
        current_ans, k = 0, 1
        while k * c < N - 1:
            a = N - 1 - k * c
            b = a - c
            
            
            if not (a <= b or b <= 0 or (a % c == 0 and a <= k * c)):
                current_ans += S[N - 1 - k * c] + S[k * c]
                ans = max(ans, current_ans)
            k += 1
    return ans
    

N = int(input())
S = [int(i) for i in input().split()]
print(f_frog_jump(N, S))

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

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

ANS=0

for i in range(1,N//2):
    s=0
    l=N-1
    SCORE=0

    if (N-1)%i==0:
        while l>s and l>i:

            SCORE+=S[s]+S[l]
            ANS=max(ANS,SCORE)
            s+=i
            l-=i
        
    else:
        while l!=s and l>i:

            SCORE+=S[s]+S[l]
            ANS=max(ANS,SCORE)
            s+=i
            l-=i

        

print(ANS)

Solution (Python):
def cumsum(itr):
    arr = []
    val = 0
    for x in itr:
        val += x
        arr.append(val)
    return arr


def main(N, scores):
    M = N - 1

    def max_score(d):
        steps = (scores[i] + scores[-i - 1] for i in range(0, M - d, d))
        cum_scores = cumsum(steps)

        if M % d > 0:
            return max(cum_scores)
        else:
            k = M // d + 1
            return max(cum_scores[: k // 2])

    corner_case = scores[0] + scores[M]
    otherwise = max(max_score(d) for d in range(1, M))
    return max(corner_case, otherwise)


N = int(input())
scores = [int(a) for a in input().split()]
result = main(N, scores)

print(result)

Solution (Python):
n=int(input())
S=tuple(map(int,input().split()))
ans=0
for c in range(1,n-1):
    k=1
    tmp=0
    while c*k<n-1:
        a=n-1-k*c
        if a<=c or (a<=k*c and a%c==0):
            break
        tmp+=S[n-1-k*c]+S[k*c]
        k+=1
        ans=max(ans,tmp)
print(ans)

Solution (Python):

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

M = N - 1
opt = 0

for d in range(1, M // 2 + 1):
    U = {0, M}
    q = M // d
    r = M % d
    acc = 0
    for i in range(1, M // d):
        x = i * d
        y = (q - i) * d + r
        if x == y or x in U or y in U:
            break
        U.add(x)
        U.add(y)
        acc += s[x] + s[y]
        opt = max(opt, acc)

ans = opt

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
S = list(map(int, input().split()))
ans = 0
d = defaultdict(int)
for c in range(1, N):
    tmp = 0
    k = 0
    while (k + 1) * c < N - 1:
        if k * c == N - 1 - k * c:
            break
        if d[k * c] == c or d[N - 1 - k * c] == c:
            break
        d[k * c] = c
        d[N - 1 - k * c] = c
        tmp += S[k * c] + S[N - 1 - k * c]
        ans = max(ans, tmp)
        k += 1

print(ans)

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

ans = 0
for c in range(1, n // 2):
    a = n - 1 - c
    k = c
    tmp = 0
    while a > c and a != k and a + c != k:
        tmp += sss[a] + sss[k]
        ans = max(ans, tmp)
        a -= c
        k += c
print(ans)

Solution (Python):
N = int(input())
S = list(map(int, input().split()))
L = 0;  R = N-1
ans = 0
for i in range(1, (N+1)//2):
    r = R
    l = L
    j = 1
    a = 0
    Closed = set()
    while True:
        l += i
        Closed.add(l)
        r -= i
        if r in Closed:
            break
        Closed.add(r)
        if r < i:
            break
        a += S[l] + S[r]
        ans = max(ans, a)
        j += 1
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
*S, = map(int, input().split())

ans = 0
c = 0
memo = defaultdict(int)
for a in range(N-1, 0, -1):
    d = 1
    m = min(N-1-a, a*a)
    while d*d <= m:
        if (N-1-a) % d == 0:
            e = (N-1-a) // d
            if a > d and (a % d > 0 or N-1 < 2*a):
                memo[a, d] = s = memo[a+d, d] + S[a] + S[N-1-a]
                ans = max(ans, s)
            if a > e and (a % e > 0 or N-1 < 2*a):
                k = (N-1-a) // e
                memo[a, e] = s = memo[a+e, e] + S[a] + S[N-1-a]
                ans = max(ans, s)
        d += 1
print(ans)

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

ans = 0
for d in range(1, N):
    r = k = 0
    while k*d <= N-1:
        a = N-1-k*d
        if a <= d or (a <= k*d and a % d == 0):
            break
        r += S[N-1-k*d] + S[k*d]
        k += 1
        ans = max(ans, r)
print(ans)

Solution (Python):
n=int(input())
v=list(map(int, input().split()))
ans=0
for k in range(1,n):
	p,s=k,0
	while p<n:
		r=n-p-1
		if r<=k:
			break
		s+=v[p]+v[n-1-p]
		if r%k!=0 or p<r:
			ans=max(ans,s)
		p+=k
print(ans)

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

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
ans = 0
for k in range(1, n):
	p, s = k, 0
	while p < n:
		r = n - p - 1
		if r <= k:
			break
		s += v[p] + v[n - 1 - p]
		if r % k != 0 or p < r:
			ans = max(ans, s)
		p += k
print(ans)