Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
#n,m,x,i,j,l,money,k,o
books = []
for i in range(n):
    books.append(list(map(int, input().split())))
books = sorted(books, reverse=False)
print(books)#

ans = 10 ** 6
import itertools
for i in range(n+1):
    for j in itertools.combinations(books, i):#j:組み合わせ
#        print(j)#
        l = [0] * n #理解度
        money = 0
        for k in j:#k:組み合わせの中の１冊
#            print(k)#
            money += k[0]  #費用
#            print(money)#
            for o in range(1, m + 1):
                l[o-1] += k[o]  #lが理解度、kが本
#        print(money,l)
        if all(a >=x for a in l):
            if money < ans:
                ans = money

if ans == 10 ** 6:
    print(-1)
else:
    print(ans)

Fixed submission:
n, m, x = map(int, input().split())
#n,m,x,i,j,l,money,k,o
books = []
for i in range(n):
    books.append(list(map(int, input().split())))
books = sorted(books, reverse=False)
#print(books)#

ans = 10 ** 10000
import itertools
for i in range(n+1):
    for j in itertools.combinations(books, i):#j:組み合わせ
#        print(j)#
        l = [0] * m #理解度
        money = 0
        for k in j:#k:組み合わせの中の１冊
#            print(k)#
            money += k[0]  #費用
#            print(money)#
            for o in range(1, m + 1):
                l[o-1] += k[o]  #lが理解度、kが本
#        print(money,l)#
        if all(a >=x for a in l):
            if money < ans:
                ans = money

if ans == 10 ** 10000:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

B = [0] * N
C = 0
D = 0
E = []
for i in range(K):
    if i == 0:
        B[i] += 1
        C = A[0]
        D += 1
        E.append(C)
        #print(i, C)
        #print(B)
    else:
        if B[C - 1] == 0:
            B[C - 1] += 1
            C = A[C - 1]
            D += 1
            #E.append(C)
            #print(i, C)
            #print(B)
        else:
            #print("２回目")
            #print(D, K % D)
            #print(E)
            print(E[K % D])
            exit()

print(C)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))

mrk = [0] * n
plc = a[0] - 1
rp = 0 #ループに入った場所
rpc = -1#ループに入ってから
prc = 0#ループに入る前
for i in range(1, k + 1):
#    logging.debug(i)
    if rpc >= 0:
        rpc += 1
        if plc == rp:
#            logging.debug("prc{},rpc{}".format(prc,rpc))
            k = (k - prc) % rpc
#            logging.debug("k{},plc{}".format(k,plc))
            for i in range(k):
                plc = a[plc] - 1
#                logging.debug(plc)
            print(plc + 1)
            exit()
    if rpc == -1:
        prc += 1
    if mrk[plc] == 1 and rpc == -1:
        rp = plc
        rpc = 0
    mrk[plc] += 1
    if i < k:
        plc = a[plc] - 1
#    logging.debug("{},next{},{},roop{}".format(mrk,plc,prc,rpc))

print(plc + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int,input().split())
query = []
for i in range(q):
    query.append(list(map(int, input().split())))

#print(query)

import itertools
cnbr = []  #組み合わせ
for i in range(m+1):
    for j in itertools.combinations_with_replacement(range(m), n):
        cnbr.append(j)

#print(cnbr)
points = [0] * len(cnbr)

for _ in range(len(cnbr)):
    for a,b,c,d in query:
        if cnbr[_][b - 1] - cnbr[_][a - 1] == c:
            points[_] += d

print(max(points))

Fixed submission:
N, M, Q = map(int, input().split())  #数字
Q = [list(map(int, input().split())) for i in range(Q)]  #数字複数列、複数行

A = []
for i in range(1,M+1):
    A.append(i)

B = []
import itertools
for i in itertools.combinations_with_replacement(A,N):
    B.append(i)

C = []
for i in range(len(B)):
    score = 0
    for j in range(len(Q)):
        if B[i][Q[j][1]-1] - B[i][Q[j][0]-1] == Q[j][2]:
            score += Q[j][3]
        C.append(score)

print(max(C))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())  #数字

import math
D = []
for x in range(1, N+1):
    D.append((A * (x % B) - A * (x % B) % B)/B)

print(int(max(D)))

Fixed submission:
A, B, N = map(int, input().split())  #数字

def X(x):
    return (A * (x % B) - A * (x % B) % B)/B

if N < B - 1:
    print(int(X(N)))
else:
    print(int(X(B-1)))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())  #数字

B=[]
for i in range(N + 1):
    B.append(i)

D = []
import itertools
for i in range(K,len(B)+1):
    for j in itertools.combinations(B, i):
        D.append(j)

E = []
F = []
G = 0
for i in range(K, len(D[-1])+1):
    for j in range(G,len(D)):
        if len(D[j]) == i:
            E.append(sum(D[j]))
        if len(D[j]) > i:
            G = j
            break
    F.append(set(E))
    E = []
        
H = 0
for i in range(len(F)):
    for j in range(len(F[i])):
        H += 1
print(H)

Fixed submission:
N, K = map(int, input().split())  #数字
MOD = 10 ** 9 + 7

ans = 0
for i in range(K, N + 2):
    A = (i - 1) * i // 2
    B = N * (1 + N) // 2 - (N + 1 - i - 1) * (N + 1 - i) // 2
    ans += B - A + 1

print(ans % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())  #数字

B=[]
for i in range(N + 1):
    B.append(i)

D = []

import itertools
for i in range(K,len(B)+1):
    for j in itertools.combinations(B, i):
        D.append(j)

#print(D)
E = []
F = []
G = 0
for i in range(K, len(D[-1])):
    if G == 1:
        G = 0
    for j in range(len(D)):
        if len(D[j]) == i:
            E.append(sum(D[j]))
#            print(E)
        if len(D[j]) > i:
            G = 1
            break
    F.append(set(E))
    E = []
        
#print(F)
H = 0
for i in range(len(F)):
    for j in range(len(F[i])):
        H += 1
print(H+1)

Fixed submission:
N, K = map(int, input().split())  #数字
MOD = 10 ** 9 + 7

ans = 0
for i in range(K, N + 2):
    A = (i - 1) * i // 2
    B = N * (1 + N) // 2 - (N + 1 - i - 1) * (N + 1 - i) // 2
    ans += B - A + 1

print(ans % MOD)
Buggy python submission (verdict: Runtime Error):
N = int(input())  #スペース抜きの複数行,１文字ずつ
 
A = []
for i in range(1,N):
#    print(i)
    if i % 3 == 0:
        A.append(0)
    elif i % 5 == 0:
		A.append(0)
    else:
        A.append(i)
 
print(sum(A))

Fixed submission:
n = int(input())  #スペース抜きの複数行,１文字ずつ
A = []

for i in range(1, n + 1):
    if i % 15 == 0:
        A.append(0)
    elif i % 3 == 0:
        A.append(0)
    elif i % 5 == 0:
        A.append(0)
    else:
        A.append(i)

print(sum(A))
Buggy python submission (verdict: Runtime Error):
from math import gcd

def main():
    K=int(input())
    ans=0
    for a in range(1,K+1):
        for b in range(1,K+1):
            p=gcd(a,b)
            if p==1:
                ans+=p*K
            else:
                for c in range(1,K+1):
                    ans+=gcd(p,c)

print(ans)

Fixed submission:
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A = []
for i in range(1, K + 1):
    for j in range(i, K+1):
        for k in range(j, K + 1):
            if i == j and j == k and k == i:
                #print(i,j,k)
                A.append(gcd_list([i, j, k]))
            elif i != j and j != k and k != i:
                A.append(gcd_list([i, j, k])*6)
            else:
                #print(i,j,k)
                A.append(gcd_list([i, j, k])*3)           

print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A = []
A.append((K-1)*3)
A.append(((K-1)**2)*3)
A.append(1)
#print(A)
for i in range(2, K+1):
    for j in range(2, K+1):
        for k in range(2, K + 1):
#            if i != 1 and j != 1 and k != 1:
                #print(i, j, k)
                #print(gcd_list([i, j, k]))
                A.append(gcd_list([i, j, k]))

#print(A)
print(sum(A))

Fixed submission:
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A = []
for i in range(1, K + 1):
    for j in range(i, K+1):
        for k in range(j, K + 1):
            if i == j and j == k and k == i:
                #print(i,j,k)
                A.append(gcd_list([i, j, k]))
            elif i != j and j != k and k != i:
                A.append(gcd_list([i, j, k])*6)
            else:
                #print(i,j,k)
                A.append(gcd_list([i, j, k])*3)           

print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A = []
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #print(i, j, k)
            #print(gcd_list([i, j, k]))
            A.append(gcd_list([i, j, k]))

print(sum(A))

Fixed submission:
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A = []
for i in range(1, K + 1):
    for j in range(i, K+1):
        for k in range(j, K + 1):
            if i == j and j == k and k == i:
                #print(i,j,k)
                A.append(gcd_list([i, j, k]))
            elif i != j and j != k and k != i:
                A.append(gcd_list([i, j, k])*6)
            else:
                #print(i,j,k)
                A.append(gcd_list([i, j, k])*3)           

print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb

n = int(input())
a = list(map(int, input().split()))
l = [0] * (max(a))

for i in a:
    l[i-1] += 1
    #logging.debug(a)

ans = 0
for i in a:
    l[i-1] -= 1
    for j in l:
        ans += comb(j,2, exact=True)
    print(ans)
    ans = 0
    l[i-1] += 1

Fixed submission:
n=int(input())
a=list(map(int,input().split()))

import collections
C = collections.Counter(a)

#logging.debug(C)

sum=0
for v in list(C.values()):
	sum+=v*(v-1)//2
 
for k in range(n):
	x = C[a[k]]
	print(sum-(x*(x-1)//2)+((x-1)*(x-2)//2))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())#数字
A = list(map(int, input().split()))

ans = 0
for i in range(1, N + 1):
    B = A[: i - 1] + A[i:]
    #print(B)
    for j in set(B):
        C = B.count(j)
        if C >= 2:
            ans += C * (C - 1) / 2
    print(int(ans))
    ans = 0

Fixed submission:
n=int(input())
a=list(map(int,input().split()))

import collections
C = collections.Counter(a)

#logging.debug(C)

sum=0
for v in list(C.values()):
	sum+=v*(v-1)//2
 
for k in range(n):
	x = C[a[k]]
	print(sum-(x*(x-1)//2)+((x-1)*(x-2)//2))
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = list(map(int, input().split()))

C = N // (A + B) * A
D = N % (A + B)

E = 0
for i in range(D):
    if 0 < (i + 1) % (A + B) <= A:
        E += 1
        
print(C+E)

Fixed submission:
N, A, B = list(map(int, input().split()))

C = N // (A + B) * A
D = N % (A + B)

if 0 <= D and D <= A:
    print(C + D)
else:
    print(C + A)

Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = list(map(int, input().split()))
C=0
for i in range(N):
    if 0 < (i + 1) % (A + B) <= A:
        C += 1
print(C)

Fixed submission:
N, A, B = list(map(int, input().split()))

C = N // (A + B) * A
D = N % (A + B)

if 0 <= D and D <= A:
    print(C + D)
else:
    print(C + A)
Buggy python submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))

P = A / 0.08
PX = (A+1) / 0.08

PP = B / 0.1
PPX = (B+1) /0.1 

if PP <= P and P < PPX: round(print(P))
elif P <= PP and PP < PX: round(print(PP))
elif 
else:print(-1)

Fixed submission:
A, B = map(int, input().split())  #数字

import math
x = math.ceil(A / 0.08)
#print(x)

y = math.ceil(B / 0.1)
#print(y)

if x == y:
    print(int(x))
    exit()

if y < x:
#    print("y < x")
    while y < x:
        y += 1
        z = y * 0.1
    if z >= B + 1:
        print(-1)
        exit()
    else:
        print(int(x))
        exit()

if y > x:
#    print("y > x")
    while y > x:
        x += 1
        z = x * 0.08
    if z >= A + 1:
        print(-1)
        exit()
    else:
        print(int(y))
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input() for i in range(N))  #スペース抜きの単語を複数行

import collections
A = collections.Counter(S)

C = [i for i in A if A[i] == max(A.values())]
C = sorted(C)
 
for i in C:
    print(i)

Fixed submission:
N = int(input())
S = list(input() for i in range(N))  #スペース抜きの単語を複数行

A = {}
for i in S:
    A.setdefault(i, 1)
    A[i] += 1

B = max(A.values())
C = [i for i in A if A[i] == B]
C = sorted(C)

for i in C:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input() for i in range(N))  #スペース抜きの単語を複数行

import collections
A = collections.Counter(S)

max_k_list = [kv[0] for kv in A.items() if kv[1] == max(A.values())]
max_k_list = sorted(max_k_list)

for i in max_k_list:
    print(i)

Fixed submission:
N = int(input())
S = list(input() for i in range(N))  #スペース抜きの単語を複数行

A = {}
for i in S:
    A.setdefault(i, 1)
    A[i] += 1

B = max(A.values())
C = [i for i in A if A[i] == B]
C = sorted(C)

for i in C:
    print(i)
Buggy python submission (verdict: Runtime Error):
N,X = list(map(int, input().split()))
L = list(map(int, input().split()))


cou = 0
BP = 0
for i in range(0, N + 1):
    if BP <= X:
        cou += 1
        BP += L[i]
    else:
        print(cou)
        exit()
print(cou)

Fixed submission:
N,X = list(map(int, input().split()))
L = list(map(int, input().split()))
L.insert(0,0)
cou = 0
BP = 0
for i in range(N + 1):
    BP += L[i]
    if BP <= X:
        cou += 1
    else:
        print(cou)
        exit()
print(cou)
Buggy python submission (verdict: Runtime Error):
N,L = map(int, input().split())
S = list((input() for i in range(N))
S = sorted(S)
print(''.join(S))

Fixed submission:
N,L = map(int, input().split())
S = list(input() for i in range(N))
S = sorted(S)
print(''.join(S))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,K = inputMap()
	A = inputList()

	ans = 1
	ans_old = 1
	mae = 0
	for i,val in enumerate(A):
		if i < K:
			ans_old *= val
			continue

		mae = A[i-K]
		ans = ans_old
		ans = ans / mae * val
		if ans > ans_old:
			print("Yes")
		else:
			print("No")
		ans_old = ans


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,K = inputMap()
	A = inputList()

	ans = 1
	ans_old = 1
	mae = 0
	for i,val in enumerate(A):
		if i < K:
			continue
		tmp = A[i-K]
		if val > tmp:
			print("Yes")
		else:
			print("No")



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	A.sort()

	for i,val in enumerate(A):
		if i == 0:
			continue
		if val == A[i-1]:
			print("NO")
			sys.exit()

	print("YES")

if __name__ == "__main__":
	main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	ST = input()
	ST = ST[:-1]
	STS = ST.split()
	A,B = inputMap()
	U = input()
	U = U[:-1]

	if U == STS[0]:
		A -= 1
	else:
		B -= 1

	print("{} {}".format(A,B))

if __name__ == "__main__":
	main()
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	to = 0
	for i in A:
		to += i

	to = t0 // 2
	to1 = 0
	to2 = 0

	toto = 0
	for i in A:
		if to1 >= to:
			to2 += i
		else:
			to1 += i

	ans = abs(to1-to2)


if __name__ == "__main__":
	main()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	to = 0
	for i in A:
		to += i

	to = to // 2
	manaka = 0
	tmp = 0
	for i,val in enumerate(A):
		tmp += val
		if tmp >= to:
			manaka = i
			break

	#print(to)
	#print(manaka)

	to1 = 0
	to11 = 0
	to2 = 0
	to22 = 0

	to111 = 0
	to222 = 0

	for i,val in enumerate(A):
		if i >= manaka+1:
			to2 += val
		else:
			to1 += val

		if i >= manaka-1:
			to22 += val
		else:
			to11 += val

		if i >= manaka:
			to222 += val
		else:
			to111 += val

	ans = min(abs(to1-to2),abs(to11-to22),abs(to111-to222))
	print(ans)


if __name__ == "__main__":
	main()