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: Time Limit Exceeded

Solution code:
import numpy as np
from time import time
N = int(input())
s = list(map(int,input().split()))
s = np.array(s).astype(np.int64)

start = time()
ans = 0
for c in range(1,N-1):
    ltor = np.cumsum(s[::c])
    rtol = np.cumsum(s[N-1::-c])

    cand = np.array([A for A in range(N-1-c,c,-c) if A % c != 0 or 2*A-c >= N-1])
    if cand.size > 0:
        indexes = (N-1-cand)//c
        temp = ltor[indexes] + rtol[indexes]
        ans = max(ans,np.max(temp))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
s = list(map(int,input().split()))
s = np.array(s)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, = map(int, input().split())
xs = list(map(int, input().split()))
r = 0
for a in range(1, N-1):
    for b in range(1, N-2):
        if a <= b:
            continue
        if (N-1-a)%(a-b):
            continue
        n = (N-1-a)//(a-b)
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                continue
        s = a
        t = xs[a]
        vs = set([a])
        for i in range(n):
            #t = max(0, t)
            s -= b
            t += xs[s]
            vs.add(s)
            s += a
            vs.add(s)
            t += xs[s]
        #print("k:%d, A:%d, B:%d"%(a-b,a,b))
        #print(vs, t)
        r = max(r, t)

print(r)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
slist = list(map(int, input().split()))
ans = 0
for C in range(1,N-1,1):
    flg = [False for i in range(N)]
    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: Time Limit Exceeded

Solution code:
N = int(input())
slist = list(map(int, input().split()))
ans = 0
for C in range(1,N-1,1):
    flg = [False for i in range(N)]
    score = 0
    for k in range((N-1)//C):
        if flg[k*C] or flg[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)
        flg[k*C] = True
        flg[N-1-k*C] = True
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for C in range(1, n):
    a2 = a[:]
    f = 0
    for k in range(int((n-1)/C)):
        if f == -float("inf") or k * C == (n - 1) - k * C:
            break
        f += a2[k * C] + a2[(n - 1) - k * C]
        a2[k * C], a2[(n - 1) - k * C] = -float("inf"), -float("inf")
        ans = max(ans, f)

print(ans)

Submission status: Time Limit Exceeded

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

ret = 0
for i in range(2, N - 1) :
    for j in range(1, i) :
        if (i % (i - j) == 0 and 2 * i < N) or (N - 1 - i) % (i - j) != 0 :
            continue
        
        ret = max(ret, sum(s[i::i-j]) + sum(s[i-j:-j-1:i-j]))

print(max(ret, 0))

Submission status: Time Limit Exceeded

Solution code:
def main():
	import sys
	inputs = sys.stdin.readline
	N = int(inputs())
	S = tuple(map(int,inputs().split()))
	C = []
	for a in range(2,N):
		#if N%a == 0:
		#	continue
		for b in range(1,a):
			C.append((a,b))
	C =tuple(C)
	ans = 0
	wa = 0
	leaf = 0
	leaves = {0}
	for c in C:
		leaves = {0}
		leaf = 0
		while(True):
			leaf += c[0]
			leaves.add(leaf)
			if leaf == N-1:
				for l in leaves:
					wa += S[l]
				ans = max(wa,ans)
				wa = 0
				break
			elif leaf > N-1:
				break
			leaf -= c[1]
			if {leaf} & leaves:
				break
			else:
				leaves.add(leaf)
	print(ans)
main()

Submission status: Time Limit Exceeded

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

ans = s[n-1]

for c in range(1, n-1):
    dp = s[n-1]
    for k in range(n-1):
        if (k+1) * c >= n-1:
            break
        else:
            dp += s[n - 1 - k * c] + s[k * c]
            if dp > ans:
                if k <= 1:
                    ans = dp
                else:
                    a = n - 1 - k * c
                    b = a - c
                    if a > 2 * b:
                        ans = dp
                    elif a < 2 * b:
                        d = [0] * n
                        t = 0
                        while 1:
                            t += a
                            if t == n-1:
                                ans = dp
                                break
                            elif t > n-1:
                                break
                            d[t] = 1
                            t -= b
                            if d[t] == 1:
                                break
                            else:
                                d[t] = 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = s[n-1]

def f(k, c):
    p = [0] * n
    a = n-1-k*c
    b = a - c
    #print(k, c, a, b)
    temp = 0
    while 0 <= temp <= n-1:
        if p[temp] == 1:
            return -1
        p[temp] = 1
        temp += a
        if p[temp] == 1:
            return -1
        p[temp] = 1
        if temp > n-1:
            return -1
        elif temp == n-1:
            return 0
        temp -= b
    return -1

for c in range(1, n-1):
    dp = s[n-1]
    for k in range(n-1):
        if (k+1) * c >= n-1:
            break
        else:
            dp += s[n - 1 - k * c] + s[k * c]
            if dp > ans:
                #print(k, c, dp, ans, 'dp')
                if f(k, c) == 0:
                    ans = dp

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for c in range(1, N):
    a = 0
    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)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main(N, scores):
    M = N - 1
    def max_score(d):
        even_steps = [scores[i] for i in range(0, M - d, d)]
        odd_steps = [scores[i] for i in range(M, d, -d)]
        scores_at_even_steps = np.cumsum(even_steps)
        scores_at_odd_steps = np.cumsum(odd_steps)
        cum_scores = scores_at_even_steps + scores_at_odd_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)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
sss = list(map(int, input().split()))
sss = np.array(sss, dtype=np.int64)


def score(cache, sss, a, ab, d):
    mat = cache[ab]
    if mat is None:
        mat = cache[ab] = np.cumsum(np.resize(sss, ((n - 1) // ab + 1, ab)).T, axis=1)
    mat_a = mat[a % ab]
    # print(a, ab, d, mat[0][d] + mat_a[-1] - mat_a[-d - 2], mat[0][d], mat_a[-1], mat_a[-d - 2])
    # print(mat)
    return mat[0][d] + mat_a[-1] - mat_a[-d - 2]


cache = [None] * n
ans = 0
for a in range(3, n - 1):
    remain = n - a - 1
    for ab in range(1, min(a, int(remain ** 0.5) + 1)):
        d, m = divmod(remain, ab)
        if m != 0:
            continue
        if remain < a:
            ans = max(ans, score(cache, sss, a, ab, d))
            if ab != d:
                ans = max(ans, score(cache, sss, a, d, ab))
        else:
            if a % ab > 0:
                ans = max(ans, score(cache, sss, a, ab, d))
            if a > d and ab != d and a % d > 0:
                ans = max(ans, score(cache, sss, a, d, ab))
print(ans)

Submission status: Time Limit Exceeded

Solution code:

from copy import deepcopy

def solve():
    N = int(raw_input())
    s = [int(_) for _ in raw_input().split()]
    ans = 0
    for A in range(1, N - 1):
        for B in range(1, A):
            if (N - 1) % (A - B) != 0 and (N - 1 - A) % (A - B) != 0:
                continue
            tmp_sum = 0
            pos = 0
            cnt = 0
            succ = True
            tmp_s = deepcopy(s)
            while pos < N - 1:
                if tmp_s[pos] is None:
                    succ = False
                    break
                else:
                    tmp_sum += tmp_s[pos]
                    tmp_s[pos] = None
                if cnt % 2 == 0:
                    pos += A
                else:
                    pos -= B
                cnt += 1
            if succ and pos == (N - 1):
                ans = max(ans, tmp_sum)
    print ans

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

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

def fact(n):
    S = set()
    for m in range(1, int(sqrt(n)) + 2):
        if n % m == 0:
            S.add(n // m)
            S.add(m)

    return S

def simulate(a, b):
    score = 0
    cur = 0
    visited = set()
    for i in range(n):
        if cur >= n - 1:
            break
        if i % 2 == 0:
            cur += a
            if cur in visited:
                return 0
            visited.add(cur)
            score += S[cur]
        else:
            cur -= b
            if cur in visited:
                return 0
            visited.add(cur)
            score += S[cur]

    return score if cur == n - 1 else 0

ans = 0

for a in range(1, n):
    D = fact(n - 1 - a)
    for d in D:
        b = a - d
        if b >= a:
            continue
        if b <= 0:
            continue
        ans = max(ans, simulate(a, b))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
N=int(input())
_s=[int(i) for i in input().split(" ")]

retval=0#A==N-1

#A%(A-B)!=0
#N>A>B>0
#N-1==k*(A-B)+A  (N-A-1)%(A-B)==0

def score(A,B):
    s=copy.copy(_s)
    place=0
    score=0
    for _ in range(N):
        score+=s[place]
        s[place]=-1*(10**100)
        place+=A
        if place==N-1:
            return score
        else:
            score+=s[place]
            s[place]=-1*(10**100)
            place-=B


for a in range(N-1):
    for b in range(1,a):
        if (N-a-1)%(a-b)!=0:
            continue
        retval=max(score(a,b),retval)
print(retval)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env pypy3

#import numpy as np
#import scipy, scipy.special

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5
from fractions import gcd

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return list(map(conv, inp().split(sep = sep)))

################################################################################

N = int(input())
S = input_ints()

# A and B s.t. lcm(A,B) >= N and A > B and C = A - B and C | N-1 and A <= 1e5

point_max = -inf
for A in range(2, N):
    for B in range(1, A):
        C = A - B
        if (N - 1 - A) % C != 0:
            continue
        point = 0
        done = [False for i in range(N)]
        idx0 = A
        idx1 = C
        while True:
            if idx0 == N - 1:
                break
            if done[idx0]:
                point = -inf
                break
            done[idx0] = True
            point += S[idx0]
            if done[idx1]:
                point = -inf
                break
            done[idx1] = True
            point += S[idx1]
            idx0 += C
            idx1 += C
        point_max = max(point_max, point)

print(point_max)

Submission status: Time Limit Exceeded

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

ans = 0

for k in range(1,n):
  for c in range(1,n):
    a = (n-1) - c*k
    if a <= c:
      break
      #書き足す
    if a%c == 0 and a//c <= k:
      continue
    p = sum(s[a:a+k*c+1:c]) + sum(s[c:k*c+1:c])
    # print(a,c,k,p, sum(s[a:a+k*c+1:c]) , sum(s[c:k*c+1:c]) )
    ans = max(p,ans)
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
#    print(SP)
    SP = sorted(SP,key = lambda x:x[1], reverse = True)
    SP = sorted(SP,key = lambda x:x[0])
#    print(SP)
    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]:
#                print(cur,l,i)
                flag = False
                break
        if flag:
            ans +=1
    print(ans)

    return

def examE():
    # 区間加算、上書き、一点取得
    class SegmentTree:
        def __init__(self, n, ele, segfun):
            #####単位元######要設定0or1orinf
            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

# 解説AC
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]
            #print(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()

Submission status: Accepted

Solution code:
# 解説は動的計画法がわからなかった
# https://drken1215.hatenablog.com/entry/2019/06/15/202200 参照
# 可能なパターンの必要条件として、c=a-bとして、左右からcごとに取る,途中打ち切りも可
#「この必要条件が十分条件」(以下のl<rとなるrの最小値をaとする,n-1がcで割れたら例外)
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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