AtCoder Beginner Contest 128 - Frog Jump

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-----
5
0 2 5 1 0

-----Sample Output-----
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.

Source: atcoder | Difficulty: MEDIUM_HARD


Solutions:
n = int(input())
s = list(map(int, input().split()))
ans = 0
for i in range(1, (n - 1) // 2 + 1):
	res = 0
	(l, r) = (i, n - 1 - i)
	while r > i and l != r and (l != r + i):
		res += s[l] + s[r]
		ans = max(ans, res)
		l += i
		r -= i
print(ans)


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)


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

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

	def max_score(d):
		steps = (scores[i] + scores[-i - 1] for i in range(0, M - d, d))
		cum_scores = cumsum(steps)
		if M % d > 0:
			return max(cum_scores)
		else:
			k = M // d + 1
			return max(cum_scores[:k // 2])
	corner_case = scores[0] + scores[M]
	otherwise = max((max_score(d) for d in range(1, M)))
	return max(corner_case, otherwise)
N = int(input())
scores = [int(a) for a in input().split()]
result = main(N, scores)
print(result)


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


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


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


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


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)


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


import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

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

def read_index():
	return map(lambda x: int(x) - 1, input().split())

def read_list():
	return list(read_values())

def read_lists(N):
	return [read_list() for n in range(N)]

class V:

	def __init__(self, f, v=None):
		self.f = f
		self.v = v

	def __str__(self):
		return str(self.v)

	def ud(self, n):
		if self.v is None:
			self.v = n
		else:
			self.v = self.f(self.v, n)

def main():
	N = int(input())
	S = read_list()
	res = V(max, 0)
	for c in range(1, N):
		r = 0
		t1 = 0
		t2 = N - 1
		a = t2 - c
		while True:
			if a < c:
				break
			if (N - 1) % c == 0 and 2 * a <= N - 1:
				break
			t1 += c
			t2 -= c
			a -= c
			r += S[t1] + S[t2]
			res.ud(r)
	print(res)
main()


n = int(input())
s = list(map(int, input().split()))
t = [0] * n
for i in range(n):
	if i == n - 1 - i:
		continue
	t[i] += s[i] + s[n - 1 - i]
ans = 0
for c in range(1, n // 2):
	num = 0
	s_max = 0
	if (n - 1) % c == 0:
		for k in range(n // 2 // c + 1):
			if n // 2 <= c * k:
				break
			num += t[c * k]
			s_max = max(s_max, num)
	else:
		for k in range((n - 1) // c):
			num += t[c * k]
			s_max = max(s_max, num)
	ans = max(ans, s_max)
print(ans)


import sys

def main():
	input = sys.stdin.readline
	N = int(input())
	S = list(map(int, input().split()))
	ans = 0
	for C in range(1, N // 2):
		n = (N - 1) // C
		point = 0
		for k in range(1, n):
			A = N - 1 - k * C
			if A < C or ((N - 1) % C == 0 and A <= k * C):
				break
			point += S[A] + S[k * C]
			ans = max(ans, point)
	return ans
print(main())


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


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)


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


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)


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)


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


import numpy as np
N = int(input())
S = np.array([int(x) for x in input().split()], dtype=np.int64)
answer = 0
for d in range(1, N):
	cum_left = np.cumsum(S[::d])
	cum_right = np.cumsum(S[::-1][::d])
	score = cum_left + cum_right
	for (L, s) in enumerate(score):
		if answer >= s:
			continue
		A = N - 1 - L * d
		B = A - d
		if A <= 0:
			continue
		if A <= B:
			continue
		if B <= 0:
			continue
		if (N - 1) % d == 0 and 2 * L * d >= N - 1:
			continue
		answer = s
print(answer)


import sys
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

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

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def II():
	return int(sys.stdin.readline())

def SI():
	return input()

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


import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
n = int(input())
s = [int(i) for i in readline().split()]
n -= 1
ans = 0
for d in range(1, n + 1):
	a = n - d
	res = 0
	(p, q) = (n, 0)
	while a >= d:
		if a <= n - a and n % d == 0:
			break
		p -= d
		q += d
		res += s[p] + s[q]
		if res > ans:
			ans = res
		a -= d
print(ans)


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)


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)


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


N = int(input())
S = [int(a) for a in input().split()]
ma = 0
for C in range(1, N - 1):
	s = 0
	for k in range((N - 2) // C):
		A = N - 1 - k * C
		if A % C == 0 and A // C <= k:
			continue
		s += S[k * C] + S[-1 - k * C]
		ma = max(ma, s)
print(ma)


N = int(input())
s = [int(i) for i in input().split()]
ret = 0
for c in range(1, N):
	k = 1
	tmp = 0
	flag = (N - 1) % c == 0
	while c * k < N - 1:
		l = c * k
		r = N - 1 - l
		if flag and r <= l or r <= c:
			break
		tmp += s[l] + s[r]
		ret = max(ret, tmp)
		k += 1
print(ret)


N = int(input())
s = list(map(int, input().split(' ')))
ans = 0
for q in range(1, N - 1):
	k = 0
	a1 = 0
	seen = set()
	p = N - 1 - k * q
	while p > q:
		if k * q in seen:
			break
		seen.add(k * q)
		if p in seen:
			break
		seen.add(p)
		a1 = a1 + s[p] + s[k * q]
		ans = max(ans, a1)
		k += 1
		p = N - 1 - k * q
print(ans)


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):
	nonlocal mod
	return (x + y) % mod

def modmlt(x, y):
	nonlocal 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 list(distance_list.items()):
		if distance > max_distance:
			max_distance = distance
			max_v = v
	return (max_distance, max_v)

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

class UnionFind:

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

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

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

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

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

def __starting_point():
	main()
__starting_point()


import os
import sys
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(2147483647)
INF = float('inf')
N = int(sys.stdin.readline())
S = list(map(int, sys.stdin.readline().split()))

def count_max(diff):
	b = 0
	a = N - 1
	ret = 0
	cumsum = 0
	while diff < a and a != b and (b - a != diff):
		cumsum += S[b] + S[a]
		ret = max(ret, cumsum)
		b += diff
		a -= diff
	return ret
ans = 0
for diff in range(1, N // 2 + 1):
	ans = max(ans, count_max(diff))
print(ans)


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


import sys

def main():
	input = sys.stdin.readline
	N = int(input())
	S = list(map(int, input().split()))
	ans = 0
	for C in range(1, N):
		n = N // C
		dp = [0] * n
		used = set([0])
		for k in range(1, n):
			A = N - 1 - k * C
			if A in used or k * C in used or A == k * C:
				break
			used.add(A)
			used.add(k * C)
			dp[k] = dp[k - 1] + S[A] + S[k * C]
		ans = max(ans, max(dp))
	return ans

def __starting_point():
	print(main())
__starting_point()


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


import itertools
N = int(input())
S = [int(_) for _ in input().split()]
ans = 0
for i in range(1, N - 1):
	maxj = (N - 1) // i
	if (N - 1) % i == 0:
		maxj = ((N - 1) // i + 1) // 2
	dp = itertools.accumulate((x + y for (x, y) in zip(S[:i * maxj:i], S[-1:-1 - i * maxj:-i])))
	ans = max(ans, max(dp))
print(ans)


from itertools import accumulate
(N, *S) = map(int, open(0).read().split())
ans = 0
for dx in range(1, N - 1):
	(k, r) = divmod(N - 1, dx)
	if r == 0:
		k = (k + 1) // 2
	ans = max(ans, max(accumulate((a + b for (a, b) in zip(S[:dx * k:dx], S[N - 1:N - 1 - dx * k:-dx])))))
print(ans)


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


N = int(input())
s = [int(i) for i in input().split()]
ans = 0
for i in range(1, N - 2):
	p = 0
	a = N - 1
	k = 0
	while True:
		k += 1
		a -= i
		b = a - i
		if b > 0 and a != N - 1 - a and (a != N - 1 - a - i):
			p += s[a] + s[N - 1 - a]
			ans = max(ans, p)
		else:
			break
print(ans)


import sys
input = sys.stdin.readline
N = int(input())
S = list(map(int, input().split()))
ANS = 0
for i in range(1, N // 2):
	s = 0
	l = N - 1
	SCORE = 0
	if (N - 1) % i == 0:
		while l > s and l > i:
			SCORE += S[s] + S[l]
			ANS = max(ANS, SCORE)
			s += i
			l -= i
	else:
		while l != s and l > i:
			SCORE += S[s] + S[l]
			ANS = max(ANS, SCORE)
			s += i
			l -= i
print(ANS)


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


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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

def main():
	N = I()
	s = LI()
	ans = 0
	for c in range(1, N):
		score = 0
		hass = set([0, N - 1])
		for k in range(1, (N - 1) // c):
			if k * c in hass or N - 1 - k * c in hass or N - 1 - k * c == k * c:
				score = -inf
				break
			score += s[N - 1 - k * c] + s[k * c]
			hass.add(N - 1 - k * c)
			hass.add(k * c)
			ans = max(ans, score)
	print(ans)
main()


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


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


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)


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)


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


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


n = int(input())
s = tuple(map(int, input().split()))
ans = 0
for b in range(1, (n - 1) // 2):
	point = 0
	count = 0
	for a in range(n - 1 - b, b, -b):
		if (a % b == 0) & (2 * a <= n - 1):
			break
		count += 1
		point += s[b * count] + s[a]
		ans = max(point, ans)
print(ans)


(N,) = map(int, input().split())
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
	a = (N - 1) % k
	for _ in range(1 + (N - 1 - a) // k):
		b = a - k
		n = (N - 1 - a) // k
		if a <= b or a <= k:
			a += k
			continue
		if a % (a - b) == 0:
			if a <= (a - b) * n:
				a += k
				continue
	if a >= N - 1:
		continue
	s1 = a
	s2 = n * (a - b)
	t = xs[s1]
	for i in range(n):
		s1 += a - b
		t += xs[s2]
		t = max(t, 0)
		t += xs[s1]
		s2 -= a - b
	r = max(r, t)
print(r)


import sys

def single_input(F):
	return F.readline().strip('\n')

def line_input(F):
	return F.readline().strip('\n').split()

def solve():
	F = sys.stdin
	N = int(single_input(F))
	S = [int(s) for s in line_input(F)]
	maxpoint = 0
	for c in range(1, N // 2):
		(s, l) = (0, N - 1)
		point = 0
		if (N - 1) % c == 0:
			while l > s and l > c:
				point += S[s] + S[l]
				maxpoint = max(point, maxpoint)
				s += c
				l -= c
		else:
			while l != s and l > c:
				point += S[s] + S[l]
				maxpoint = max(point, maxpoint)
				s += c
				l -= c
	print(maxpoint)
	return 0

def __starting_point():
	solve()
__starting_point()


from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	n = I()
	s = LI()
	ans = 0
	for c in range(1, n + 1):
		K = (n - 1) // c
		dp = 0
		S = set([0, n - 1])
		for k in range(1, K + 1):
			a = i = n - 1 - k * c
			if i in S:
				break
			b = a - c
			if b >= a or b <= 0:
				break
			S.add(i)
			j = k * c
			if j in S:
				break
			S.add(j)
			cost = s[i] + s[j]
			dp += cost
			if ans < dp:
				ans = dp
	print(ans)
	return
solve()


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


N = int(input())
S = list(map(int, input().split()))
ans = 0
for C in range(1, N):
	fkC = 0
	L = 0
	R = N - 1
	if (N - 1) % C == 0:
		while L < R:
			fkC += S[L] + S[R]
			ans = max(ans, fkC)
			L += C
			R -= C
	else:
		while L + C < N - 1:
			fkC += S[L] + S[R]
			ans = max(ans, fkC)
			L += C
			R -= C
print(ans)


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

def examE():

	class SegmentTree:

		def __init__(self, n, ele, segfun):
			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

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


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


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)


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)


N = int(input())
ss = list(map(int, input().split()))
ans = 0
for C in range(1, N):
	score = 0
	for k in range(1, (N - 1) // C + 1):
		if (N - 1) % C == 0 and k * C >= N - 1 - k * C:
			break
		if N - 1 - k * C <= C:
			break
		score += ss[k * C] + ss[N - 1 - k * C]
		ans = max(ans, score)
print(ans)


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)


def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	S = list(map(int, input().split()))
	X = [[0] for _ in range(N)]
	Y = [[0] for _ in range(N)]
	for k in range(1, N):
		for i in range(1, N):
			if i * k >= N:
				break
			X[k].append(X[k][-1] + S[i * k])
	for k in range(1, N):
		for i in range(1, N):
			if i * k >= N:
				break
			Y[k].append(Y[k][-1] + S[-i * k - 1])
	ans = 0
	for k in range(1, N):
		for i in range(N):
			if i * k == N - 1 - i * k:
				break
			if k * (i - 1) == N - 1 - i * k:
				break
			if k * (i + 1) >= N - 1:
				break
			ans = max(ans, X[k][i] + Y[k][i])
	print(ans)
main()


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def resolve():
	n = int(input())
	S = list(map(int, input().split()))
	ans = 0
	for d in range(1, n):
		score = 0
		P = set()
		for x in range(n // d):
			a = n - 1 - x * d
			if a <= d:
				break
			if x * d in P or n - 1 - x * d in P:
				break
			if x * d == n - 1 - x * d:
				break
			score += S[x * d]
			score += S[n - 1 - x * d]
			P.add(x * d)
			P.add(n - 1 - x * d)
			ans = max(ans, score)
	print(ans)
resolve()


from collections import defaultdict
N = int(input())
S = list(map(int, input().split()))
ans = 0
for c in range(1, N):
	now = 0
	for t in range(c, N, c):
		if (N - 1 - t) % c == 0 and N - 1 - t <= t or N - 1 - t - c <= 0:
			break
		now += S[t] + S[N - 1 - t]
		if now > ans:
			ans = now
print(ans)


def main():
	N = int(input())
	S = list(map(int, input().split()))
	ans = 0
	for C in range(1, N // 2 + 1):
		cs = 0
		for k in range(1, (N - 1) // C + 1):
			a = C * k
			b = N - a - 1
			if a >= b and (N - 1) % C == 0:
				break
			if b <= C:
				break
			cs += S[a] + S[b]
			ans = max(cs, ans)
	print(ans)
main()


n = int(input())
s = list(map(int, input().split()))
ans = 0
for d in range(1, n):
	temp = 0
	L = 0
	R = n - 1
	if (n - 1) % d == 0:
		while L < R:
			temp += s[L] + s[R]
			ans = max(ans, temp)
			L += d
			R -= d
	else:
		while L + d < n - 1:
			temp += s[L] + s[R]
			ans = max(ans, temp)
			L += d
			R -= d
print(ans)


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


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)


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


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


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


N = int(input())
s = list(map(int, input().split()))
ans = 0
for c in range(1, N):
	res = 0
	for k in range(1, (N - 1) // c + 1):
		a = N - 1 - c * k
		b = a - c
		res += s[c * k] + s[-c * k - 1]
		if b < 0 or (a % c == 0 and a // c <= k):
			continue
		ans = max(ans, res)
print(ans)


N = int(input())
s = list(map(int, input().split()))
now = [0] * N
ans = [0] * N
for i in range(1, N):
	j = 1
	while j ** 2 <= i:
		if i % j == 0:
			if (N - 1) % j == 0 and 2 + i * 2 > N:
				pass
			elif i + j > N:
				pass
			else:
				now[j] += s[i] + s[N - 1 - i]
				ans[j] = max(ans[j], now[j])
		if i % j == 0 and j ** 2 != i:
			j2 = i // j
			if (N - 1) % j2 == 0 and 2 + i * 2 > N:
				pass
			elif i + j2 > N:
				pass
			else:
				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)


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


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
N = int(readline())
S = list(map(int, read().split()))
answer = 0
for d in range(1, N):
	n = (N - 1) // d
	if (N - 1) % d == 0:
		n = ((N - 1) // d + 1) // 2
	if n <= 1:
		continue
	x = max(itertools.accumulate((x + y for (x, y) in zip(S[d:d * n:d], S[N - 1 - d:N - 1 - d * n:-d]))))
	if answer < x:
		answer = x
print(answer)


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


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


n = int(input())
a = [int(item) for item in input().split()]
ans = 0
for c in range(1, n):
	visited = set([0, n - 1])
	total = 0
	for k in range(1, n):
		odd = n - 1 - k * c
		even = k * c
		if even >= n - 1:
			break
		if odd < c:
			break
		if even in visited:
			break
		visited.add(even)
		if odd in visited:
			break
		visited.add(odd)
		total += a[odd] + a[even]
		ans = max(ans, total)
print(ans)