Problem:


Score : 600 points

Problem Statement

There is an infinitely large pond, which we consider as a number line.
In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1.
On the lotus at coordinate i, an integer s_i is written.

You are standing on the lotus at coordinate 0. You will play a game that proceeds as follows:

1. Choose positive integers A and B. Your score is initially 0.

2. Let x be your current coordinate, and y = x+A. The lotus at coordinate x disappears, and you move to coordinate y.

If y = N-1, the game ends.

If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y.

If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends.

3. Let x be your current coordinate, and y = x-B. The lotus at coordinate x disappears, and you move to coordinate y.

If y = N-1, the game ends.

If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y.

If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends.

4. Go back to step 2.

You want to end the game with as high a score as possible.
What is the score obtained by the optimal choice of A and B?

Constraints

3 \leq N \leq 10^5

-10^9 \leq s_i \leq 10^9

s_0=s_{N-1}=0

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
s_0 s_1 ...... s_{N-1}

Output

Print the score obtained by the optimal choice of A and B.

Sample Input 1

5
0 2 5 1 0

Sample Output 1

3

If you choose A = 3 and B = 2, the game proceeds as follows:

Move to coordinate 0 + 3 = 3. Your score increases by s_3 = 1.

Move to coordinate 3 - 2 = 1. Your score increases by s_1 = 2.

Move to coordinate 1 + 3 = 4. The game ends with a score of 3.

There is no way to end the game with a score of 4 or higher, so the answer is 3. Note that you cannot land the lotus at coordinate 2 without drowning later.

Sample Input 2

6
0 10 -7 -4 -13 0

Sample Output 2

0

The optimal strategy here is to land the final lotus immediately by choosing A = 5 (the value of B does not matter).

Sample Input 3

11
0 -4 0 -99 31 14 -15 -39 43 18 0

Sample Output 3

59



Sample input:
5
0 2 5 1 0


Sample output:
3

Submission status: Accepted

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

    """
    A+kC=N-1
    A=N-1-kC
    0,A     ,C, A+C       ,2C,A+2C      ,3C,A+3C      =N-1
    0,N-1-kC,C, N-1-(k-1)C,2C,N-1-(k-2)C,3C,N-1-(k-3)C=N-1
    """

    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
            #print(N - 1 - (k * c), k*c)
            score += s[N - 1 - (k * c)] + s[k * c]
            hass.add(N - 1 - (k * c))
            hass.add(k * c)

            # print(score)
            ans = max(ans, score)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
  
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f_frog_jump(N, S):
    ans = 0
    for c in range(1, N):
        # k=0のとき、スタートからゴールへ飛ぶしかない(得点0)ので、k=1から始める
        current_ans, k = 0, 1
        while k * c < N - 1:
            a = N - 1 - k * c
            b = a - c
            # k, 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
    # 参考: http://sigma1113.hatenablog.com/entry/2019/05/27/181729

N = int(input())
S = [int(i) for i in input().split()]
print(f_frog_jump(N, S))

Submission status: Accepted

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>i:

            SCORE+=S[s]+S[l]
            ANS=max(ANS,SCORE)
            s+=i
            l-=i
        #print(SCORE,i,l,s)
    else:
        while l!=s and l>i:

            SCORE+=S[s]+S[l]
            ANS=max(ANS,SCORE)
            s+=i
            l-=i

        #print(SCORE,i,l,s)

print(ANS)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力
N = int(input())
s = list(map(int, input().split()))

M = N - 1
opt = 0
# 各 A - D について解候補を全探索する
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
import sympy

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 sympy.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)

Submission status: Runtime Error

Solution code:
def examA():
    A, P = LI()
    ans = (A*3+P)//2
    print(ans)
    return

def examB():
    N = I()
    SP = [[]for _ in range(N)]
    for i in range(N):
        SP[i] = LSI()
        SP[i][1] = int(SP[i][1])
        SP[i].append(i)
#    print(SP)
    SP = sorted(SP,key = lambda x:x[1], reverse = True)
    SP = sorted(SP,key = lambda x:x[0])
#    print(SP)
    for v in SP:
        print(v[2]+1)
    return

def examC():
    N, M = LI()
    S = [LI() for _ in range(M)]
    P = LI()
    ans = 0
    loop = 2**N
    for i in range(loop):
        flag = True
        d = defaultdict(bool)
        for j in range(N):
            if i&(1<<j)==(1<<j):
                d[j+1] = True
        for l,j in enumerate(S):
            cur = 0
            for k in range(1,j[0]+1):
                if d[j[k]]:
                    cur +=1
            if cur%2!=P[l]:
#                print(cur,l,i)
                flag = False
                break
        if flag:
            ans +=1
    print(ans)

    return

def examE():
    # 区間加算、上書き、一点取得
    class SegmentTree:
        def __init__(self, n, ele, segfun):
            #####単位元######要設定0or1orinf
            self.ide_ele = ele
            self.segfun = segfun
            ####################
            self.n = n
            self.N0 = 1 << n.bit_length()
            self.data = [self.ide_ele] * (self.N0 * 2)

        def update_add(self, l, r, val):
            l += self.N0
            r += self.N0
            while l < r:
                if l & 1:
                    self.data[l] += val
                    l += 1
                if r & 1:
                    self.data[r - 1] += val
                    r -= 1
                l //= 2
                r //= 2

        def update(self, l, r, val):
            l += self.N0
            r += self.N0
            while l < r:
                if l & 1:
                    self.data[l] = self.segfun(self.data[l], val)
                    l += 1
                if r & 1:
                    self.data[r - 1] = self.segfun(self.data[r - 1], val)
                    r -= 1
                l //= 2
                r //= 2

        def query(self, i):
            i += len(self.data) // 2
            ret = self.data[i]
            while i > 0:
                i //= 2
                ret = self.segfun(ret, self.data[i])
            return ret
    N, Q = LI()
    X = [LI() for _ in range(N)]
    D = [I() for _ in range(Q)]
    S = SegmentTree(Q+N,inf,lambda a, b: min(a,b))
    QD = []
    for s,t,x in X:
        QD.append([max(0,s-x),t-x,x,0])
    for d in D:
        QD.append([d,1])
    QD.sort(key = lambda x:x[0])
    print(QD)
    ans = []
    for l in QD:
        if l[-1]==0:
            S.update(l[0],l[1],l[2])
        else:
            ans.append(S.query(l[0]))
    for v in ans:
        if v==inf:
            print(-1)
            continue
        print(v)
    return

# 解説AC
def examF():
    def judge(a,c,k):
        if math.gcd(a,c)==c:
            if c*k>=a:
                return False
        return True
    N = I()
    S = LI()
    ans = -inf
    N -= 1
    F = [defaultdict(int)for _ in range(N)]
    for c in range(1,N):
        K = (N-1)//c
        for k in range(K):
            F[c][k+1] = F[c][k] + S[N-k*c] + S[k*c]
            #print(S[N-k*c], S[k*c])
            a = N - (k+1)*c + c
            cur = F[c][k+1]
            if judge(a,c,k):
                if ans<cur:
                    ans = cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examF()

Submission status: Runtime Error

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) + 1)] for c in range(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][k] = dp[c][k - 1] + S[t1] + S[t2]
            T.add(t1)
            T.add(t2)
            res.ud(dp[c][k])

    print(res)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7
mod = 998244353

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: Runtime Error

Solution code:
N, = map(int, input().split())
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
    a = (N-1) % k
    if a <= k:
        a += k
    if a <= k:
        a += k

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

print(r)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
S = np.array(read().split(),np.int64)

def F(d):
    # 公差を固定
    L = S[::d].cumsum()
    R = S[::-d].cumsum()
    if (N-1)%d == 0:
        n = (N-1)//d
        x = np.arange(1,n+2)
        bl = (x+x <= n+1)
        L = L[bl]; R = R[bl]
    return (L+R).max()

def G(n):
    # 項数n+1を固定
    D = (N-1)//n
    L = np.zeros(D+1,np.int64)
    R = np.zeros(D+1,np.int64)
    for i in range(1,n+1):
        L += S[:i*(D+1):i]
        R += S[::-1][:i*(D+1):i]
    ok = np.ones(D+1,np.bool)
    overlap = (np.arange(D+1) * (n+n) >= N-1)
    overlap[1:] &= ((N-1)%np.arange(1,D+1) == 0)
    x = L+R
    x[overlap] = 0
    return x.max()

L = (N-1)**.5 + 10
L = min(N-1,L)

x = max(F(n) for n in range(1,L+1))
y = max(F(n) for n in range(1,L+1))
answer = max(x,y)
print(answer)

Submission status: Runtime Error

Solution code:
ans = S[-1]*1
for C in range(1, N-1):
    tmp = S[-1]*1
    div, mod = divmod(N-1, C)
    if mod == 0:
        X = (div-1)//2
    else:
        X = -(-(N-1)//(2*C))
    for c in range(C, (X+1)*C, C):
        if N-1-c - C < 0:
            break
        if N-1-c <= c:
            break
        tmp += S[N-1-c] + S[c]
        ans = max(ans, tmp)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N = int( input())
S = list( map( int, input().split()))

ans = 0
for c in range(1,N):
    now = 0
    k = 1
    for _ in range(1,N):
        if k*2 + 1 > N-2:
            break
        if k*c >= N-1:
            break
        if (N-1-k*c)%c <= k:
            break
        now += S[k*c] + S[N-1-k*c]
        d[k*c] = 1
        d[N-1-k*c] = 1
        if now > ans:
            ans = now
        k += 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
N = int( input())
S = list( map( int, input().split()))

ans = 0
for c in range(1,N):
    now = 0
    k = 1
    for _ in range(1,N):
        if k*2 + 1 > N-2:
            break
        if k*c >= N-1:
            break
        if k*c >= N-1-k*c:
            break
        now += S[k*c] + S[N-1-k*c]
        H[k*c] = 1
        H[N-1-k*c] = 1
        if now > ans:
            ans = now
        k += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
S = np.array([int(x) for x in input().split()],dtype=np.int64)

# 右移動着地点：等差数列、ゴール含む
# 左移動着地点：等差数列、スタート含む

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


print(answer)

Submission status: Runtime Error

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

ans = 0
for c in range(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:
        for i in range(1, (N-1)//(2*c)):
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np


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


n = int(input())
sss = list(map(int, input().split()))
sss.extend([0] * n)
sss = np.array(sss, dtype=np.int64)

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

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

N, Q = [int(c) for c in input().split()]

M = [10**10]*Q

STX = []
for n in range(N):
    s,t,x = [int(c) for c in input().split()]
    STX.append((s,t,x))

D = [int(input()) for q in range(Q)]

for s,t,x in STX:
    d_l = bisect_left(D, s-x)
    d_r = bisect_left(D[d_l:], t-x)+d_l
    for d in range(d_l, d_r):
        M[d] = min(x,M[d])

for q in range(Q):
    m = -1 if M[q] == 10**10 else M[q]
    print(m)

Submission status: Runtime Error

Solution code:
import bisect
from  heapq import *

kl, ql = tuple(map(int,input().split()))

ks = []
for ki in range(kl):
    a,b,x = tuple(map(int,input().split()))
    #a..b-1 nioite x ha tuukou dome
    ahx, bhx = a-x, b-x
    ks.append((ahx,bhx,x))

ds = []
for qi in range(ql):
    d = int(input())
    ds.append(d)


notyetKs = sorted(ks, key=lambda k:k[0])
workingKs = []

for t in ds:
    while len(notyetKs)>0:
        ahx,bhx,x = notyetKs[0]
        if ahx <= t:
            if t < bhx:
                heappush(workingKs,(bhx,(ahx,bhx,x)))
            notyetKs.pop(0)
        else:
            break
    while len(workingKs)>0:
        ahx,bhx,x = workingKs[0][1]
        if bhx <= t:
            heappop(workingKs)
        else:
            break

    #print(t, notyetKs,workingKs,doneKs)

    if len(workingKs)==0:
        print(-1)
    else:
        print(min(workingKs, key=lambda k:k[1][2])[1][2])

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N, Q = map(int, input().split(" "))
check_points = [list(map(int, input().split(" "))) for _ in range(N)]
querys = sorted([int(input()) for i in range(Q)])
time = {}
for q in querys:
    time[q] = 0

check_parsed = []
for s, f, x in sorted(check_points, key=itemgetter(2)):
    start, end = [max(0, s-x), max(0, f-x)]
    for q in querys:
        if q < start:
            pass
        elif start <= q < end:
            if time[q] == 0:
                time[q] = x+1
            else:
                pass
        else:
            break

for q in querys:
    print(time[q]-1)