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



Sample input:
5
0 2 5 1 0


Sample output:
3

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
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:
                #print (i,j)
                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:
                #print (i,j2)
                now[j2] += s[i] + s[N-1-i]
                ans[j2] = max(ans[j2],now[j2])

        j+=1
    #print (now)

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

#print (ans)
print (pra)

Submission status: Accepted

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

# a = A
# b = A-B
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
    #print(ps, t)
    r = max(r, t)

print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):
    # 項数n+1を固定
    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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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]
#        print(d,a,res)
        if res > ans: ans = res
        a -= d
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(c, k, total)
        # print(visited)
print(ans)

Submission status: Accepted

Solution code:
###############################################################################

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):
    # 左右対称に 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)

Submission status: Accepted

Solution code:
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]
    #print(c,k,Score)
    ans=max(Score,ans)
    k+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 # when k = 0: 0 -> (N - 1)
        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] # DP
                pass_set.add(N-1-k*C)
                pass_set.add(k*C)
            ans = max(ans, score)
    print ans

if __name__ == '__main__':
    solve2()

Submission status: Accepted

Solution code:
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(dp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# youtube
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

            # Check A and B are positive integer, and S_i is not used twice.
            #
            # B = A - C and B >= 0, so A must be over C (A > C).
            #
            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1
            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than
            # or equal kC, the A's value is already used by kC.
            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())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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):
  # d = A-B
  cum_left = np.cumsum(S[::d])
  cum_right = np.cumsum(S[::-1][::d])
  score = cum_left + cum_right # 等差数列の長さ-1 -> 得点
  # あとは、その経路がルール内で実現できるかどうか
  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
    # 同じ場所を取っていないかの確認
    # kd = N-1-ldとなるとまずい
    # 約数のとき、Ld >= N-Ldだとまずい
    if (N-1)%d == 0 and 2*L*d >= N-1:
      continue
    answer = s

print(answer)