peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
MOD = 10 ** 9 + 7

S = int(input())
dp = [0] * (S + 1)
dp[0] = 1
for i in range(1, S + 1):
    dp[i] = sum(dp[:max(0, i - 2)]) % MOD

print(dp[-1] % MOD)
# Judge status: Accepted
x=int(input())
a=x//100
b=x%100
if a*5>=b:
    print(1)
else:
    print(0)
# Judge status: Accepted
n,a=int(input()),float("inf")
for i in range(1,5*10**6+1):
	if n%i==0:j=n//i;a=min(a,i+j-2)
print(a)
# Judge status: Accepted
s = input()
k = int(input())
v = list(s)
n = len(s)
a = [0 for i in range(n)]

for i in range(n):
  a[i] = (123 - ord(s[i]))%26
  if k == 0:
    break
  if k >= a[i]:
    v[i] = 'a'
    k -= a[i]

if k > 0:
  k %= 26
  v[n-1] = chr(ord(v[n-1])+k)
print (''.join(v))
# Judge status: Accepted
N=input()

if N[0]==N[1]==N[2] or N[3]==N[1]==N[2]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
# https://atcoder.jp/contests/agc036/tasks/agc036_a

S = int(input())
x1 = 0
y1 = 0
x2 = 1000000000
y2 = 1
v = 1000000000
x = (v - S % v) % v
y = (S + x) // v

print("{} {} {} {} {} {}".format(x1, y1, x2, y2, x, y))
# Judge status: Accepted
N,M=list(map(int, input().split()))
if N!=1 and M!=1:
    print((N-2)*(M-2))
elif N==M==1:
    print(1)
elif N==1 and M!=1:
    print(M-2)
else:
    print(N-2)
# Judge status: Wrong Answer
x = int(input())
if x == 3 or x == 5 or x == 7:
	print('Yes')
else:
	print('No')
# Judge status: Accepted
import collections
N=int(input())
lst=input().split()
s=0
dic=collections.Counter(lst)
for i in dic.values():
    s+=(i*i-i)//2
for i in lst:
    print(s+1-dic[i])
# Judge status: Accepted
n,m = map(int,input().split())
A = {}
for i in range (1,n+1):
    a,b = map(int,input().split())
    A[i] = [a,b]

B = {}
for i in range(1,m+1):
    c,d = map(int,input().split())
    B[i] = [c,d]

for v in A.values():
    t = float('inf')
    ans = 0
    for x,w in B.items():
        if abs(v[0]-w[0])+abs(v[1]-w[1]) < t:
            t = abs(v[0]-w[0])+abs(v[1]-w[1])
            ans = x
    print (ans)
# Judge status: Accepted
n = int(input())
s = input()
e = [0] * (n + 1)
w = [0] * (n + 1)

for i in range(len(s)):
    if s[i] == "E":
        e[i+1] = e[i] + 1
        w[i+1] = w[i]
    else:
        w[i+1] = w[i] + 1
        e[i+1] = e[i]

ans = 10 ** 9
for i in range(0, n+1):
    t = w[i] + e[n] - e[i]
    ans = min(ans, t)

print(ans)
# Judge status: Accepted
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
for y in range(n-m+1):
    for z in range(n-m+1):
        count = 0
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count += 1
                if count == m:
                    print("Yes")
                    exit()
            else:
                count = 0
print("No")
# Judge status: Accepted
N=int(input())
for i in range(26):
  for j in range(15):
    if 4*i + 7*j == N:
      print('Yes')
      exit()
print('No')
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**7)
def is_ok(m, n):
    return m*(m+1)//2>=n
def meguru_bisect(ng, ok, n):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, n):
            ok = mid
        else:
            ng = mid
    return ok
def f(n):
    if n>0:
        m = meguru_bisect(0,10**7, n)
        print(m)
        f(n-m)
N = int(input())
f(N)
# Judge status: Wrong Answer
A=int(input())
B=int(input())
if A==1 and B==2:
    print(3)
elif A==2 and B==3:
    print(1)
elif A==3 and B==1:
    print(2)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

cash = 1000

for buy, sell in zip(a, a[1:]):
    if buy >= sell:
        continue
    stock, cash = divmod(cash, buy)
    cash += stock * sell

print(cash)
# Judge status: Accepted
x=int(input())
kai=x//11
amari=x%11

if 1<=amari<=6:
  print(2*kai+1)
elif 7<=amari<=10:
  print(2*kai+2)
else:
  print(2*kai)
# Judge status: Accepted
n,k=map(int,input().split())
r=n%k
print(min(r,k-r))
# Judge status: Accepted
# https://atcoder.jp/contests/agc015/tasks/agc015_a
# 最小と最大は必ず一つは存在するのか
n, a, b = map(int, input().split())
if b < a or (n == 1 and a != b):  # コーナーケース
    print(0)
    exit()
ma = b * (n - 1) + a
mi = a * (n - 1) + b
print((ma - mi + 1))
# Judge status: Wrong Answer
# https://atcoder.jp/contests/abc079/tasks/abc079_c
import random
import sys

str = input()
print(str)


def retop():
    if(random.uniform(0, 1) > 0.5):
        return "+"
    return "-"


for i in range(100):
    formula = (str[0] + retop() + str[1] + retop() + str[2] + retop() + str[3])
    if eval(formula) == 7:
        print(formula + "=7")
        sys.exit()
# Judge status: Wrong Answer
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))

A.sort(reverse=True)

all_ =sum(A)
th = all_//(4*M)

ans='No'
if A[M-1] >= th:
    ans='Yes'
    
print(ans)
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    AB, BC, CA = map(int, input().split())
    print(AB * BC // 2)
    
if __name__ == '__main__':
    main()
# Judge status: Accepted
n = list(map(int, input()))
if (sum(n)%9 == 0):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
from collections import Counter

N = int(input())
S = input()
count = Counter(S)
mod = 10**9+7
ans = 1
for k, v in count.items():
    ans = ans * (v+1) % mod
print(ans-1)
# Judge status: Accepted
N, K = map(int, raw_input().split())
S = raw_input()

x = 0
for i in range(N):
  if (S[i]=="L" and 0<i and S[i-1]=="L" or
      S[i]=="R" and i<N-1 and S[i+1]=="R"):
    x += 1
print min(x+2*K, N-1)
# Judge status: Accepted
a=int(input())
print(800*a-(a//15)*200)
# Judge status: Accepted
def solve():
    N, W = map(int, input().split())
    w, v = [0] * N, [0] * N
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    
    dp = [0] * (W + 1)
    for i in range(N):
        for j in range(W - w[i], -1, -1):
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i])
    print(dp[W])


if __name__ == '__main__':
    solve()
# Judge status: Accepted
txt = list(input())
a = txt[0]
count = 1
i = 1
while(i < len(txt)):
  #print(temp)
  if a != txt[i]:
    a = txt[i]
    i += 1
    count += 1
  else:
    if (len(txt)-i) >= 2:
      a = txt[i:i+1]
      i += 2
      count += 1
    else:
      break
print(count)
# Judge status: Accepted
N = int(input())
Array = []
for i in range(N):
  Array.append(tuple(map(int,input().split())))

res = 0
for i in reversed(range(N)):
  a,b = Array[i]
  a+=res
  res+= ((b-a%b)%b)
print(res)
# Judge status: Accepted
import math
n = int(input())
rg = range(1, n + 1)
k = 0
for a in rg:
    for b in rg:
        g1 = math.gcd(a,b)
        for c in rg:
            g2 = math.gcd(g1,c)
            k += g2
print(k)
# Judge status: Accepted
# -*- coding: utf-8 -*-

def main(N, A_list):
    total_list = []
    total = 0
    for i in range(len(A_list)):
        total += A_list[i]
        total_list.append(total)

    num = 0
    for i in range(len(A_list)-1):
        num += A_list[i] * (total_list[len(A_list)-1]-total_list[i])

    val = num % ((10 ** 9) + 7)
    print(val)


N = int(input())
A_list = list(map(int, input().split()))
main(N, A_list)
# Judge status: Wrong Answer
import sys
s = list(input())
s.sort()
alp = list('abcdefghijklmnopqrstuvwxyz')

for s_,alp_ in zip(s,alp):
    if s_ != alp_ :
        print(alp_)
        sys.exit()

print('None')
# Judge status: Wrong Answer
import collections
N = int(input())
A = [int(x) for x in input().split()]
c = collections.Counter(A)
cc = {k:v for k, v in c.items() if v>1}
ccc = sorted(list(cc.keys())[-2:])
if len(ccc)==2:
    print(ccc[0] * ccc[1])
else:
    print(0)
# Judge status: Accepted
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
S = [0] * N
S[0] = 0
 
for i in range(1, N):
    value = S[i - 1] + abs(h[i] - h[i - 1])
    maxStep = min(K, i)
    for step in range(1, maxStep + 1):
        value = min(value, S[i - step] + abs(h[i] - h[i - step]))
    S[i] = value
print(S[N - 1])
# Judge status: Accepted
a = input()
b = input()
if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
K, A, B = map(int, input().split())
add = B - A
c = 1
if add > 2:
    K -= A-1
    c += A-1
    c += add * (K//2) + K%2
else:
    c += K
print(c)
# Judge status: Accepted
n =int(input())
print(int(((n**(0.5))//1)**2))
# Judge status: Accepted
S = input()
if len(S) % 2!=0:
    print("No")
else:
    for i in range(6):
        if "hi" * i == S:
            print("Yes")
            exit()
    print("No")
# Judge status: Accepted
S = input()

if 'N' in S:
  if not 'S' in S:
    print('No')
    exit()
if 'S' in S:
  if not 'N' in S:
    print('No')
    exit()
if 'E' in S:
  if not 'W' in S:
    print('No')
    exit()
if 'W' in S:
  if not 'E' in S:
    print('No')
    exit()
print('Yes')
# Judge status: Wrong Answer
H,W = map(int,input().split())
if (H*W)%2 == 1:
    print(H*W//2+1)
else:
    print(H*W//2)
# Judge status: Accepted
n = int(input())
s = input()
c = s.count('R') * s.count('G') * s.count('B')
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = j + (j - i)
        if k >= n:
            continue
        if s[i] == s[j] or s[j] == s[k] or s[k] == s[i]:
            continue
        c -= 1
print(c)
# Judge status: Accepted
from itertools import*
_, *a = map(int, open(0))
print(sum(sum(l)//2 for _, l in groupby(a, key=lambda x:x>0)))
# Judge status: Accepted
a,b,c=map(int,input().split())
print("Yes"if a+b==c or a+c==b or a==b+c else "No")
# Judge status: Wrong Answer
k, x = map(int, input().split())
for i in range(-k + 1, k):
  print(i, end=" ")
# Judge status: Wrong Answer
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
for i in A:
    if i != 0:
        print(2**(N-1))
        exit()
if P ==0:
    print(2**N)
else:
    print(0)
# Judge status: Wrong Answer
import collections
def main():
    N = int(input())
    S = input()

    cc = collections.Counter(S)
    output = 1
    for k in cc.keys():
        output *= (cc[k] + 1)
    print(output-1)
    return

if __name__ == '__main__':
    main()
# Judge status: Accepted
#!/usr/bin/env python3
import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    S = IS(str)
    print(S[:3])


solve()
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

cnt = 0
while True:
    test = [a_%2 for a_ in a]
    if 1 in test:
        break
    else:
        cnt += 1
        a = [a_/2 for a_ in a]
        
print(cnt)
# Judge status: Accepted
import numpy as np
N, W = map(int, input().split())
dp = np.zeros(W+1)
for i in range(N):
  w, v = map(int, input().split())
  dp[w:] = np.maximum(dp[:-w]+v, dp[w:])
print(int(dp[-1]))
# Judge status: Accepted
from functools import reduce
from fractions import gcd

def lcm(x, y):
    return x * y // gcd(x, y)

N, M = map(int, input().split())
A = [int(x)//2 for x in input().split()]
B = [0] * N
for i in range(N):
    a = A[i]
    cnt = 0
    while a % 2 == 0:
        cnt += 1
        a //= 2
    B[i] = cnt

if len(set(B)) != 1:
    print(0)
    exit()

c = reduce(lcm, A)

if (M // c) % 2 == 0:
    print(M // c // 2)
else:
    print(M // c // 2 + 1)
# Judge status: Accepted
ls = input().split(" ")

a = int(ls[0])
b = int(ls[1])

c = a * b

if c % 2 == 1:
  print("Odd")
else:
  print("Even")
# Judge status: Wrong Answer
n = int(input())
k = int(input())
x = int(input())
y = int(input())
print(x*n + y*(n-k) if n > k else x*n)
# Judge status: Accepted
print(6-sum(map(int, open(0).read().split())))
# Judge status: Wrong Answer
a,b,c,d=map(int,input().split())
if b>0 and  d>0:
    print(b*d)
else:
    if b<=0 and d<=0:
        print(min(a,b)*min(c,d))
    elif a<=0 or b<=0:
        print(max(a,b)*min(c,d))
    else:
        print(min(a,b)*max(c,d))
# Judge status: Wrong Answer
import math
x = int(input())

mod = x%100
quo = x//100

print(mod,quo)

if mod==0:
  print("1")
elif quo>=math.ceil(mod/5):
  print("1")
else:
  print("0")
# Judge status: Accepted
from collections import defaultdict

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

ans = 0
ma = defaultdict(int)

for i in range(N):
    ans += ma[i - A[i]]
    ma[i + A[i]] += 1

print(ans)
# Judge status: Accepted
a, b, c, x, y = map(int, input().split())
ans = 0
if a+b >= c*2:
    ans = min(x,y)*c*2
    if x>y:
        if a > c*2:
            ans += c*2*(x-y)
        else:
            ans += a*(x-y)
    else:
        if b > c*2:
            ans += c*2*(y-x)
        else:
            ans += b*(y-x)

else:
    ans = a*x+b*y
print(ans)
# Judge status: Accepted
N,A,B = list(map(int,input().split()))
MIN = A*(N-1)+B
MAX = A+B*(N-1)
print(max(MAX-MIN+1,0))
# Judge status: Wrong Answer
def gcd(a, b):
    return b if a % b == 0 else gcd(b, a % b)


n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(k)
a.sort()
d = [0] * (n)
for i in range(n):
    d[i] = a[i + 1] - a[i]

ans = d[0]
for j in range(1, len(d)):
    ans = gcd(ans, d[i])

print(ans)
# Judge status: Wrong Answer
N=int(input())
d=[input().split() for i in range(N)]
name=[]
for i in range(N):
    d[i].append(i+1)
    name.append(d[i][0])
Name=list(set(name))
Name.sort()
d.sort()
for i in range(len(Name)):
    li=[]
    for j in range(N):
        if Name[i]==d[j][0]:
            li.append([d[j][1],d[j][2]])
        else:
            continue
    li.sort()
    Li=li[::-1]
    for k in range(len(li)):
        print(Li[k][1])
# Judge status: Accepted
x = input()
#tのラストとsの最初を知りたい
n = len(x)
a = []
for i in range(n):
  if x[i]=="S":
    a.append(x[i])
  else:
    if len(a)!=0 and a[-1]=='S' :
      a.pop()
    else:
      a.append(x[i])
print(len(a))
# Judge status: Wrong Answer
N, M = map(int, input().split())

res = 0
res += min(N, M//2)
M -= N*2

res += M//4

print(res)
# Judge status: Wrong Answer
N=int(input())
tl=[]
xl=[]
yl=[]
al=[]
bl=[]
cl=[]
dl=[]

for i in range(N):
 t,x,y=map(int,input().split())
 tl.append(t)
 xl.append(x)
 yl.append(y)
 al.append((x+y)%2)
 bl.append(t%2)
 print(x)
for i in range(N):
 c=abs((xl[i]+yl[i])-(xl[i-1]+yl[i-1]))
 d=tl[i]-tl[i-1]
 cl.append(c)
 dl.append(d)

if al==bl and (xl+yl)<=tl and cl<=dl:
 print("Yes")
else :
  print("No")
# Judge status: Accepted
A = int(input())
B = int(input())
C = int(input())

X = int(input())

ans = 0

for a_num in range(A+1):
	for b_num in range(B+1):
		for c_num in range(C+1):
			if (500 * a_num) + (100 * b_num) + (50 * c_num) == X:
				ans += 1

print(ans)
# Judge status: Wrong Answer
N = int(input())
alp = "zabcdefghijklmnopqrstuvwxy"
L = ""
while(True):
    ind = int(N%26)
    N = (N-ind)/26
    L = alp[ind] + L
    if (N==0):
        break
print(L)
# Judge status: Wrong Answer
n = int(input())
a = [int(input()) for _ in range(n)]

ans, tmp = 0, 0
for ai in a:
    ans += (ai + tmp) // 2
    tmp = 0
    if ai == 0:
        tmp = (ai + tmp) % 2
print(ans)
# Judge status: Accepted
A, B = map(int, input().split())
S = input().split("-")

if len(S[0]) == A and len(S[1]) == B:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
from collections import defaultdict
n=int(input())
A=[int(i) for i in input().split()]
d=defaultdict(int)

b=[A[i] - (i+1) for i in range(n)]
c=[A[i] + (i+1) for i in range(n)]

l=[]
ans=0
d=defaultdict(int)
for i in range(1,n)[::-1]:
    d[c[i]]+=1
    d[b[i]]+=1
    ans+= d[-c[i-1]]
print(ans)
# Judge status: Accepted
s = input()
r = 0
b = 0

for i in range(len(s)):
  if s[i] == '0':
    r += 1
  else:
    b += 1
if r > b:
  print(b*2)
else:
  print(r*2)
# Judge status: Accepted
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x = int(readline())

    for a in range(-120, 120):
        for b in range(-120, 120):
            if a**5 - b**5 == x:
                print(a, b)
                exit()


if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
luca = [2, 1]
for i in range(n-1):
    luca.append(luca[-2] + luca[-1])

ans = luca[-1]
print(ans)
# Judge status: Wrong Answer
s=input()
t=input()
s=sorted(s)
t=sorted(t)
if (s==t):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a,b = map(int,input().split())
s = input()
for i in range(a):
    if s[i] == '-':
        print('No')
        exit(0)

if s[a] != '-':
    print('No')
    exit(0)

for i in range(a+1,a+b):
    if s[i] == '-':
        print('No')
        exit(0)

print('Yes')
# Judge status: Accepted
def cmb(n, r, mod):
    c=1
    for i in range(1, r+1):
        c = (c * (n-i+1) * pow(i, mod-2, mod)) % mod
    return c

n, a, b = map(int, input().split())
MOD = 10**9 + 7
print((pow(2, n, MOD) - cmb(n, a, MOD) - cmb(n, b, MOD) - 1) % MOD)
# Judge status: Accepted
X = int(input())
dp = [0]*(X+1)
dp[0] = 1

for i in range(100, X+1):
    dp[i] = dp[i-100] or dp[i-101] or dp[i-102] or dp[i-103] or dp[i-104] or dp[i-105]

print(dp[X])
# Judge status: Wrong Answer
import sys
A,B,C = map(int,input().split())
ln = 100//A+1
for i in range(1,ln+1):
    if (A*i-C)% B == 0:
        print('YES')
        sys.exit()
print('NO')
# Judge status: Wrong Answer
N, x = map(int, input().split())
a=list(map(int, input().split()))

count=0
for i in range(1, N):
    if a[i]+a[i-1] > x:
        count += min(a[i] + a[i - 1] - x, a[i])
        a[i]=max(0, x-a[i-1])
if a[0]+a[1] > x:
    count+=a[0]-x
    a[0]=x
print(a)
print(count)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))+[0]
ans=0
bn,ba=0,0
for i in a:
    ans+=b[i-1]
    if bn+1==i:
        ans+=ba
    bn=i
    ba=c[i-1]
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3

def main():
    N, S = map(str, open(0).read().split())
    N = int(N)

    S_rep = []
    for i in range(0, len(S)):
        n = ord(list(S)[i])
        if (n + N < 91):
            S_rep.append(chr(n + N))
        else:
            S_rep.append(chr(n + N + 6))
    
    S_rep = ''.join(S_rep)
    print(S_rep.upper())



main()
# Judge status: Accepted
h1, m1, h2, m2, k = [int(x) for x in input().split()]

ans = (h2 * 60 + m2) - (h1*60 + m1) - k

print(max(0, ans))
# Judge status: Accepted
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort(reverse=True)

    ans = 0
    for i in range(1, 2*N, 2):
        ans += A[i]

    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input())
d = list(map(int,input().split()))
d_sorted = sorted(d, reverse = False)

count = d_sorted[(N-1) //2 + 1] - d_sorted[(N-1) // 2]
print(count)
# Judge status: Accepted
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    colors = [0] * 9
    for aa in a:
        index = -1
        for i in range(8):
            if 400 * i <= aa < 400 * (i + 1):
                index = i
        colors[index] += 1
    answer = 0
    for i in range(8):
        if colors[i] > 0:
            answer += 1
    print(max(answer, 1), answer + colors[-1])


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
from fractions import gcd

def lcm(a, b):
	return a * b // gcd(a, b)


N, M = map(int, input().split())
A = list(map(int, input().split()))

A = list(set(A))

t = 1
for a in A:
    t = lcm(t, a)

if t // 2 > M:
    print(0)
else:
    print((M - t // 2) // t + 1)
# Judge status: Accepted
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500*a + 100*b + 50*c == X :
        ans += 1
print(ans)
# Judge status: Accepted
import sys

N = int(input())

# n 円を引き出すための最小の引き出し回数

table = [i for i in range(0, N  + 1)]  # 1円ずつ引き出した場合

for base in (6, 9):  
  unit = base  # 引き出し単位
  while unit <= N:
    for i in range(unit, N + 1):
      table[i] = min(
        table[i],
        table[i - unit] + 1
      )
    
    unit *= base

print(table[N])
# Judge status: Accepted
n = int(input())
as_ = [int(input()) - 1 for _ in range(n)]

visited = [0] * n

index = 0
num_push = 0
goal = False
while True:
    if visited[index] == 1:
        break

    visited[index] = 1
    if index == 1:
        goal = True
        break

    index = as_[index]
    num_push += 1

if goal:
    print(num_push)
else:
    print(-1)
# Judge status: Wrong Answer
def splittingplie(n , a):

    ans = 10**18
    allsum = int(sum(a))
    asum = 0

    for i in range(n):
        asum += a[i]
        b = allsum - asum
        rldifference = abs(asum - b)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()
# Judge status: Accepted
n , m = map(int, input().split())
e = 0
d = []
for i in range(1, n + 1):
  l = list(map(int, input().split()))
  for a in range(l[0]):
    b = l[a + 1]
    d.append(b)
for j in range(1, m + 1):
  c = 0
  for k in d:
    if k == j:
      c += 1
  if c == n:
    e += 1
print(e)
# Judge status: Wrong Answer
N=int(input())
A=list(map(int,input().split()))
x,cnt=1,0

for i in range(N):
    if A[i]==x:
        x+=1
    else:
        cnt+=1

print(cnt if cnt>=0 else -1)
# Judge status: Accepted
a=input().split()
a.sort()
cnt=0
while len(a)>0:
    i=a.count(a.pop(0))
    for j in range(i):
        a.pop(0)
    cnt+=1
print(cnt)
# Judge status: Wrong Answer
A, B, K = map(int, input().split())

for i in range(min(K, B - A)):
  print(A + i)

if abs(A - B) >= 2 * K:
  for j in reversed(range(min(K, B - A))):
    print(B - j)
else:
  for j in reversed(range(min(K-1, B - A))):    
    print(B - j)
# Judge status: Wrong Answer
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

for i in range(N):
    A[i+1]+=A[i]
for i in range(M):
    B[i+1]+=B[i]

idx=N
ans=0
for i in range(N):
    if A[i]>K:
        idx=i-1
        break

idx2=0
for i in range(idx,-1,-1):
    while idx2<M and A[idx]+B[idx2+1]<=K:
        idx2+=1
    ans=max(ans,i+idx2)

print(ans)
# Judge status: Accepted
N, M, K = map(int, input().split())
flag = False

for j in range(M + 1):
    for i in range(N + 1):
        # t = i * j + (N - i) * (M - j)
        # area = M * N - t
        area = (M - j) * i + (N - i) * j
        if area == K:
            flag = True

if flag:
    print('Yes')
else:
    print("No")
# Judge status: Wrong Answer
N = int(input())
li = list(map(int, input().split()))

li.sort()

sum = 0
for i in li[:-2]:
    sum = i + sum

Nmax = li[-1]
if N <= 2 or li[0] < 1:
    print("No")
elif Nmax < sum and 0 < Nmax:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = list(input())
a = int(''.join(n))
b = []
b.append(int(n[0]))
b.append(int(n[1]))
b.append(int(n[2]))
b = sorted(b)
if a % 111 == 0:
    print(a)
else:
    if int(n[0]) <= b[1]:
        print(b[1] * 111)
    elif b[1] < int(n[0]) <= b[2]:
        print(b[2] * 111)
# Judge status: Wrong Answer
# -*- coding : utf-8 -*-

S = str(input())

w = ""
for i in range(len(S)):
  if S[i] == "B":
    if w == "":
      w = ""
    else :
      w = w.rstrip()
  else:
    w = w + S[i]

print(w)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if a[i+1]-a[i]==1:
    ans=ans+c[a[i]-1]
print(sum(b)+ans)
# Judge status: Wrong Answer
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
v=a1[0]+a2[0]
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    dis=list(map(int,dis))
    c=a1[dis[0]-1]+a2[dis[1]-1]-dis[2]
    l.append(c)
l1=sorted(set(l))
print(l1[0])
# Judge status: Accepted
N,M = map(int,input().split())

V = [[] for _ in range(N)]

for _ in range(M):
    a,b = map(int,input().split())
    a = a-1
    b = b-1
    V[a].append(b)
    V[b].append(a)

from collections import deque

q = deque([0])

ans = [-1]*N
ans[0] = 0

while q:
    v = q.popleft()
    for nv in V[v]:
        if ans[nv] == -1:
            ans[nv] = v + 1
            q.append(nv)

print("Yes")
print(*ans[1:],sep="\n")