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, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
  
def solve():
    N = int(single_input())
    S = [int(s) for s in line_input()]
    DP = [[0 for i in range(N-2)] for k in range(N-2)]
    maxpoint = 0
    for c in range(1, N-2):
        used = set()
        for k in range(1, (N-1)//c + 1):
            if N - 1 - k * c <= c: break
            elif N-1-(k-1)*c not in used and (k-1) * c not in used:
                DP[k][c] = DP[k-1][c] + S[N - 1 - (k-1) * c] + S[(k-1) * c]
                used |= {N-1-(k-1)*c}
                used |= {(k-1)*c}
                maxpoint = max(DP[k][c], maxpoint)
            else: break
    print(maxpoint)

    return 0
  
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N = int(single_input())
    S = [int(s) for s in line_input()]
    DP = [[0 for i in range(N)] for k in range(N)]
    maxpoint = 0
    for c in range(1, N-2):
        used = set()
        for k in range(1, (N-1)//c):
            if N - 1 - k * c <= c: break
            elif N-1-(k-1)*c not in used and (k-1) * c not in used:
                DP[k][c] = DP[k-1][c] + S[N - 1 - (k-1) * c] + S[(k-1) * c]
                used |= {N-1-(k-1)*c}
                used |= {(k-1)*c}
                maxpoint = max(DP[k][c], maxpoint)
    print(maxpoint)

    return 0
  
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
s = inpl()
ans = 0
for C in range(1,N-2):
    S = 0
    m = (N-1) % C
    for a in range(C,N-1,C):
        b = (N-1) - a
        if b <= a and m == 0:
            if b == a:
                S += s[a]
            break
        else:
            S += s[a] + s[b]
        if S > ans:
            ans = S
print(ans)

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
s = inpl()
ans = 0
for C in range(1,N-2):
    S = 0
    m = (N-1) % C
    for a in range(C,N-1,C):
        b = (N-1) - a
        if b <= a and m == 0:
            break
        else:
            S += s[a] + s[b]
        if S > ans:
            ans = S
print(ans)

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
s = inpl()
ans = 0
for C in range(1,N-2):
    S = 0
    m = (N-1) % C
    for a in range(C,N-1,C):
        b = (N-1) - a
        if b <= a and m == 0:
            break
        else:
            S += s[a] + s[b]
            if S < 0:
                S = 0
    if S > ans:
        ans = S
print(ans)

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
s = inpl()
ans = 0
for C in range(1,N-2):
    S = 0
    for a in range(C,N-1,C):
        b = (N-1) - a
        if b <= a:
            break
        else:
            S += s[a] + s[b]
            if S < 0:
                S = 0
    if S > ans:
        ans = S
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

ANS=0

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

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

        #print(SCORE,i,l,s)

print(ANS)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

ANS=0

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

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

        #print(SCORE,i,l,s)

print(ANS)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

ANS=0

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

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

        #print(SCORE,i,l,s)

print(ANS)

Submission status: Wrong Answer

Solution code:
inpl = lambda: list(map(int,input().split()))
N = int(input())
s = inpl()
ans = 0
for C in range(1,N):
    B0 = (N-1) % C
    A0 = B0 + C
    if B0 == 0:
        r = (N-1)//C
        A0 = (r//2+1) * C
        B0 = r//2 * C
    S = 0
    a = C
    b = A0
    c = (N-1) - (B0+C)
    d = (N-1) - C
    while a < c:
        S += s[a] + s[b] + s[c] + s[d]
        if S < 0:
            S = 0
        a += C
        b += C
        c -= C
        d -= C
    if a == c:
        S += s[a] + s[b]
    if S > ans:
        ans = S
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(map(int,input().split()))
ans = 0
for C in range(1,N):
    score = 0
    x = 0
    t = [0 for k in range(N)]
    while True:
        if (N-1)-x*C <= 0 or x*C >= N:
            break
        if (N-1)-x*C <= C or (N-1)-x*C - C <= 0:
            score = 0
            break
        if t[x*C] == 1:
            break
        score += s[x*C]
        t[x*C] = 1
        if t[(N-1)-x*C] == 1:
            score -= s[x*C]
            break
        score += s[(N-1)-x*C]
        t[(N-1)-x*C] = 1
        x += 1
    ans = max(score,ans)
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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()
    slist = intina()

    ans = 0

    for c in range(1, n - 1):
        checked = defaultdict(lambda: False)
        val = 0
        for k in range(1, n - 1):

            #print('c=%d k=%d' % (c, k))

            if k * c >= n - 1:
                break

            #print('c=%d k=%d' % (c, k))

            idx1 = n - 1 - k * c
            idx2 = k * c
            if checked[idx1] or checked[idx2] or (idx1 <= idx2):
                break

            #print('c=%d k=%d' % (c, k))

            checked[idx1] = checked[idx2] = True
            val = val + slist[idx1] + slist[idx2]
            ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

max_ans = ss[-1]

# A - B = C
# A + kC = N − 1 
# B = N - 1 - (k + 1) * C 
# A = N - 1 - k * c

for c in range(1, n):
	k = 1
	sc = ss[-1]
	done = [0 for _ in range(n)]
	while k * c < n - 1:
		if n - 1 - 2 * k * c != 0 and done[n - 1 - k * c] + done[k * c] == 0:
			sc += ss[n - 1 - k * c] + ss[k * c]
			done[n - 1 - k * c] = 1
			#print(k, c, sc, done)
			max_ans = max(max_ans, sc)
			k += 1
		else:
			break

print(max_ans)

Submission status: Wrong Answer

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()
    slist = intina()

    ans = 0

    for c in range(1, n - 1):
        checked = defaultdict(lambda: False)
        val = 0
        for k in range(1, n - 1):

            if k * c >= n - 1:
                break

            idx1 = n - 1 - k * c
            idx2 = k * c
            if checked[idx1] or checked[idx2] or (idx1 == idx2):
                break
            checked[idx1] = checked[idx2] = True
            val = val + slist[idx1] + slist[idx2]
            ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

max_ans = ss[-1]

for c in range(1, n):
	k = 1
	sc = ss[-1]
	done = [0 for _ in range(n)]
	while k * c < n - 1:
		if done[n - 1 - k * c] + done[k * c] == 0:
			sc += ss[n - 1 - k * c] + ss[k * c]
			done[n - 1 - k * c] = 1
			done[k * c] = 1
			#print(k, c, sc)
			max_ans = max(max_ans, sc)
			k += 1
		else:
			break

print(max_ans)

Submission status: Wrong Answer

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()
    slist = intina()

    ans = 0

    for c in range(n - 1):
        checked = defaultdict(lambda: False)
        for k in range(n - 1):

            if k * c >= n - 1:
                break

            if k == 0:
                val = 0
            else:
                idx1 = n - 1 - k * c
                idx2 = k * c
                if checked[idx1] or checked[idx2] or (idx1 == idx2):
                    break
                checked[idx1] = checked[idx2] = True
                val = val + slist[idx1] + slist[idx2]
                ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 % (A - B) != 0 and (N - 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: Wrong Answer

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

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

Submission status: Wrong Answer

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

## Nの正の公約数をリストで返す（ソートしたい場合は#外す）
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    #divisors.sort()
    return divisors

ans = 0
for A in range(1, N):
  AminusB_lst = make_divisors(N-1-A)
  B_lst = list(map(lambda x:-x+A, AminusB_lst))
  for B in B_lst:
    if B >= A:
      continue
    if A % (A-B) == 0:
      cross = A // (A-B)
      if cross*A - (cross-1)*(A-B) < N-1:
        continue
    score = S[A]
    t_goal = (N-1-A) // (A-B)
    for i in range(1,t_goal+1):
      score += S[i*(A-B)] + S[A+i*(A-B)]
    ans = max(ans, score)
    #print((A, B, score))
    
print(ans)

Submission status: Wrong Answer

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

ans = 0

for c in range(1,n-1):
  if (n-1)%c == 0:
    p = ((n-1)//c-1)//2 
  else:
    p = (n-1)//c-2
    if p <= 0:
      break
  if p <= 0:
    continue
  m = 0
  k = 0
  for i in range(1,p+1):
    k += s[c*i] + s[n-1-c*i]
    m = max(m,k)
  ans = max(ans,m)
    
    
print(ans)

Submission status: Wrong Answer

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

ans = 0

for c in range(1,n-1):
  if (n-1)%c == 0:
    p = ((n-1)//c-1)//2 
  else:
    p = (n-1)//c-2
    if p <= 1:
      break
  if p <= 1:
    continue
  m = 0
  k = 0
  for i in range(1,p+1):
    k += s[c*i] + s[n-1-c*i]
    m = max(m,k)
  ans = max(ans,m)
    
    
print(ans)

Submission status: Wrong Answer

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
        ans = max(ans, simulate(a, b))

print(ans)

Submission status: Wrong Answer

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

Solution code:
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):
    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 a%(a-b)==0:
            continue
        elif (N-a-1)%(a-b)!=0:
            continue
        retval=max(score(a,b),retval)
print(retval)

Submission status: Wrong Answer

Solution code:
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):
    place=0
    score=0
    for _ in range(N):
        print(place,score)
        score+=s[place]
        place+=A
        if place==N-1:
            return score
        else:
            score+=s[place]
            place-=B


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

Submission status: Wrong Answer

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)
        if point_max == point:
            print(A, B)

print(point_max)

Submission status: Wrong Answer

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

retval=0#A==N-1

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

def score(A,B):
    place=0
    score=0
    for _ in range(N):
        print(place,score)
        score+=s[place]
        place+=A
        if place==N-1:
            return score
        else:
            score+=s[place]
            place-=B


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

Submission status: Time Limit Exceeded

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

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

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

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

print(ans)