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: Wrong Answer

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 i in range(0, N, d):
    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: Wrong Answer

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 - 1):
  s = set()
  t = 0
  for i in range(0, N, d):
    if i in s: break
    s.add(i)
    if N - 1 - i in s: break
    s.add(N - 1 - i)
    if i == N - 1 - i: break
    t += a[i]
    t += a[N - 1 - i]
    res = max(res, t)
print(res)

Submission status: Wrong Answer

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
  if (N - 1) % d:
    for i in range(0, N, d):
      if i in s: break
      s.add(i)
      if N - 1 - i in s: break
      s.add(N - 1 - i)
      t += a[i]
      t += a[N - 1 - i]
      res = max(res, t)
  else:
    for i in range(0, N, d):
      if i + d >= N - 1 - i: break
      t += a[i]
      t += a[N - 1 - i]
      res = max(res, t)
print(res)

Submission status: Wrong Answer

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 i in range(0, N, d):
    if i + d >= N - 1: break
    if i >= N - 1 - i: break
    if i in s: break
    s.add(i)
    if N - 1 - i in s: break
    s.add(N - 1 - i)
    t += a[i]
    t += a[N - 1 - i]
    res = max(res, t)
print(res)

Submission status: Wrong Answer

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
  if (N - 1) % d:
    for i in range(0, N, d):
      if i in s: break
      s.add(i)
      if N - 1 - i in s: break
      s.add(N - 1 - i)
      t += a[i]
      t += a[N - 1 - i]
      res = max(res, t)
  else:
    for i in range(0, N, d):
      if i >= N - 1 - i: break
      t += a[i]
      t += a[N - 1 - i]
      res = max(res, t)
print(res)

Submission status: Wrong Answer

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 i in range(0, N, d):
    if i in s: break
    s.add(i)
    if N - 1 - i in s: break
    s.add(N - 1 - i)
    t += a[i]
    t += a[N - 1 - i]
    res = max(res, t)
print(res)

Submission status: Wrong Answer

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 i in range(0, N, d):
    s.add(i)
    if N - 1 - i in s: break
    t += a[i]
    t += a[N - 1 - i]
    res = max(res, t)
print(res)

Submission status: Wrong Answer

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 i in range(0, N, d):
    t += a[i]
    s.add(i)
  for i in range(N - 1, -1, -d):
    t += a[i]
    if i in s: break
  else: res = max(res, t)
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    s=tuple(map(int,input().split()))
    
    cost=[-INF]*(N+1)
    
    for i in range(1,int((N-1)**0.5)+1):
        if (N-1)%i==0:
            cost[i]*=2
            cost[(N-1)//i]*=2
    
    is_prime = [True] * (N + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(N**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, N + 1, i):
            is_prime[j] = False
    primes=[i for i in range(N + 1) if is_prime[i]]
    
    def get_divprime(n):
        divprime=[]
        for x in primes:
            if n%x==0:
                divprime.append(x)
                while n%x==0:
                    n//=x
            if n==1:
                break
        return divprime
    
    ans=0
    for x in range(N-2,1,-1):
        if cost[x]==-INF*2:
            continue
        if x>N//2:
            tmp=0
            for i in range(x,N-1,x):
                tmp+=s[i]+s[N-1-i]
            cost[x]=tmp
            ans=max(ans,tmp)
            if (N-1)%x==1:
                continue
        elif cost[x]==-INF:
            if (N-1)%x>1:
                tmp=0
                for i in range(x,N-1,x):
                    tmp+=s[i]+s[N-1-i]
                cost[x]=tmp
                ans=max(ans,tmp)
            else:
                tmp=0
                for i in range(x,N-2,x):
                    tmp+=s[i]+s[N-1-i]
                cost[x]=tmp
                ans=max(ans,tmp)
        else:
            tmp=cost[x]
        divprime=get_divprime(x)
        for y in divprime:
            if x==y or cost[x//y]==-INF*2:
                continue
            tmptmp=tmp
            if (N-1)%y>1:
                for i in range(x//y,N-1,x//y):
                    if i%x!=0:
                        tmptmp+=s[i]+s[N-1-i]
            else:
                for i in range(x//y,N-2,x//y):
                    if i%x!=0:
                        tmptmp+=s[i]+s[N-1-i]
            cost[x//y]=tmptmp
            ans=max(ans,tmptmp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 >= 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: Wrong Answer

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(1, n):
    d = c*k
    if d >= 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: Wrong Answer

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(1, (n-2)//c+1):
    d = c*k
    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: Wrong Answer

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(1, (n-2)//c+1):
    d = c*k
    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: Wrong Answer

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(1, (n-2)//c+1):
    d = c*k
    if d in T or n-1-d in T:
      break
    T.add(d)
    T.add(n-1-d)
    temp += S[d]+S[n-1-d]
    ans = max(ans, temp)
print(ans)

Submission status: Wrong Answer

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
  for k in range(n):
    d = c*k
    if d >= n:
      break
    if d < n-1-d and (n-1)%c == 0:
      break
    temp += S[d] + S[n-1-d]
    ans = max(ans, temp)
print(ans)

Submission status: Wrong Answer

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
  for k in range(n):
    d = c*k
    if d >= n-1-d:
      break
    temp += S[d] + S[n-1-d]
    ans = max(ans, temp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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=-10**20
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)
    else:
        l=0;r=n
        tmp=0
        while l<n and r>0:
            tmp+=s[l]+s[r]
            l+=c;r-=c

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

Submission status: Wrong Answer

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=-10**10
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)
    else:
        l=0;r=n
        tmp=0
        while l<n and r>0:
            tmp+=s[l]+s[r]
            l+=c;r-=c

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

Submission status: Wrong Answer

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=-10**10
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)
    else:
        l=0;r=n
        tmp=0
        while l<n-1 and r>0:
            tmp+=s[l]+s[r]
            l+=c;r-=c

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

Submission status: Wrong Answer

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:
            break
        now += s[i] + s[j]
        ans = max(ans, now)
print(ans)

Submission status: Wrong Answer

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:
					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: Wrong Answer

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:
			continue
		var = 0
		left = 0; right = 0
		cnt = 0
		while True:
			if 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)

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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 in visited) or (backward in visited):
                break
            visited.add(forward)
            visited.add(backward)
            dp = dp + s[n - 1 - k * c] + s[k * c]
            ans = max(ans, dp)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
        lim = (n - 1 - c) // (2 * c)
        for k in range(1, lim + 1):
            dp = dp + s[n - 1 - k * c] + s[k * c]
            ans = max(ans, dp)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
        lim = ((n - 1) // c - 1) // 2
        for k in range(1, lim + 1):
            dp = dp + s[n - 1 - k * c] + s[k * c]
            ans = max(ans, dp)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
S = list(map(int, input().split()))
ans = 0
if N%2==0:
    A = N // 2
else:
    A = (N+1) // 2

for a in range(A,N-1):
    s = sum(S[a:])+sum(S[1:N-a])
    if s > ans:
        ans = s

a = N-2
b = N-3
for _ in range(b//2):
    a -= 1
    b -= 2
    x = a
    y = b
    for i in range(2,a):
        if y==0 or i*x-(i-1)*y!=N-1 or (x%2==0 and y%2==0 and y//2<i-1):
            break
        p = 0
        c = 0
        while True:
            if y<=0:
                break
            c += x
            if c==N-1:
                break
            p += S[c]
            c -= y
            p += S[c]
        if p > ans:
            ans = p
        x -= 2
        y -= 2
        
print(ans)

Submission status: Wrong Answer

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:
            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: Wrong Answer

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:
            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: Wrong Answer

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
        if bld in vs:
            break
        vs.add(bld)
        if ld in vs:
            break
        vs.add(ld)
        s += X[ld] + X[bld]
        r = max(s, r)
print(r)

Submission status: Wrong Answer

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:
            break
        vs.add(ld)
        s += X[ld] + X[bld]
        r = max(s, r)
print(r)

Submission status: Wrong Answer

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
        for k in range(1, N):
            t1 += c
            t2 -= c
            if t1 >= N - 1:
                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: Wrong Answer

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
        for k in range(1, N):
            t1 = k * c
            if t1 >= N - 1:
                break
            
            if 2 * t1 == N - 1:
                break

            if (N - 1) % c == 0 and (N - 1) // c <= 2 * k:
                break

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

    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    dp = [[0 for _ in range((N - 1) // c + 1)] for c in range(1, N)]
    res = V(max, 0)
    for c in range(1, N):
        for k in range(1, N):
            t1 = k * c
            t2 = (N - 1) - t1 
            if t1 >= N - 1:
                break
            
            if t1 == t2:
                break

            if (N - 1) % c == 0 and (N - 1) // c <= 2 * k:
                break

            dp[c - 1][k] = dp[c - 1][k - 1] + S[t1] + S[t2]
            res.ud(dp[c - 1][k])

    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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):
        self.f = f
        self.v = None
 
    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 f(N, S, A, L, R, exist=False):
    if S == 0:
        return [[0, L - 1]]

    SS = sum(A[L:R + 1])
    if SS < S:
        return []
    if SS == S:
        return [[L, R]]
    if L == R:
        return []

    T1 = f(N, S, A, L + 1, R, exist)
    T2 = f(N, S - A[L], A, L + 1, R, True)

    if not exist and len(T2) > 0:
        for l in T2:
            l[0] = L
    T1.extend(T2)
    return T1


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

    dp = [[0 for _ in range((N - 1) // c + 1)] for c in range(1, N)]
    res = V(max)
    res.ud(0)
    for c in range(1, N):
        T = set()
        for k in range(1, N):
            t1 = k * c
            t2 = (N - 1) - t1 
            if t1 >= N - 1:
                break
            
            if t1 == t2:
                break

            if t1 in T or t2 in T: 
                break

            dp[c - 1][k] = dp[c - 1][k - 1] + S[t1] + S[t2]
            T.add(t1)
            T.add(t2)
            res.ud(dp[c - 1][k])

    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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):
        self.f = f
        self.v = None
 
    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 f(N, S, A, L, R, exist=False):
    if S == 0:
        return [[0, L - 1]]

    SS = sum(A[L:R + 1])
    if SS < S:
        return []
    if SS == S:
        return [[L, R]]
    if L == R:
        return []

    T1 = f(N, S, A, L + 1, R, exist)
    T2 = f(N, S - A[L], A, L + 1, R, True)

    if not exist and len(T2) > 0:
        for l in T2:
            l[0] = L
    T1.extend(T2)
    return T1


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

    dp = [[0 for _ in range(N)] for __ in range(N)]
    res = V(max)
    res.ud(0)
    for c in range(1, N):
        T = set()
        for k in range(N):
            t1 = (k + 1) * c
            t2 = (N - 1) - t1 
            if t1 >= N - 1:
                break
            
            if t1 == t2:
                break

            if t1 in T or t2 in T: 
                break
        
            dp[c][k + 1] = dp[c][k] + S[t1] + S[t2]
            T.add(t1)
            T.add(t2)
            res.ud(dp[c][k + 1])

    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc128/tasks/abc128_f

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

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

"""

N = int(input())

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

for i in range(1,N//2):

    j = 1

    while j ** 2 <= i:

        if i % j == 0:

            if (N-1) % j == 0 and 2+i*2 > 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
            else:
                #print (i,j2)
                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 (ans)
print (pra)

Submission status: Wrong Answer

Solution code:
"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc128/tasks/abc128_f

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

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

"""

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
            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
            else:
                #print (i,j2)
                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)

Submission status: Wrong Answer

Solution code:
"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc128/tasks/abc128_f

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

"""

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

        j+=1

    #print (now)
print (max(ans))

Submission status: Wrong Answer

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 2*i*k >= N-1:
                break
            ans = max(ans, X[k][i] + Y[k][i])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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