peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
X,K,D=map(int,input().split())
zX = abs(X)

maxDist=K*D
if(zX>maxDist):
  print(zX-maxDist)
else:
  sabun=maxDist-zX
  ans1 = sabun % (D*2)
  ans2 = abs(ans1 - (D*2))
  if(ans1 > ans2):
    print(ans2)
  else:
    print(ans1)
# Judge status: Accepted
n=int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
	for j in range(1,105):
		for k in range(1,105):
			v = i*i+j*j+k*k+i*j+j*k+k*i;
			if v<10050:
				ans[v]+=1

for i in range(n):
	print(ans[i+1])
# Judge status: Accepted
a, b = map(str, input().split())
n, m = map(int, input().split())
u = input()
if u == a:
    print(n - 1, m)
else:
    print(n, m - 1)
# Judge status: Accepted
nums = int(input())
total = 0

for num in range(1, nums+1):
    len_num = len(str(num))
    if len_num % 2 == 1:
        total += 1

print(total)
# Judge status: Wrong Answer
buf=input().split(" ")
N=int(buf[0])
K=int(buf[1])
p=list(map(int, input().split()))
ex=[]

for i in range(N):
  ex.append((p[i]*(p[i]+1)/2)/p[i])

ex=sorted(ex,reverse=True)
print("{:.12f}".format(sum(ex[0:K])))
# Judge status: Accepted
N=int(input())
H=list(map(int,input().split()))[::-1]
flag=True
base=H[0]
for i in range(N-1):
    if H[i]+1==H[i+1]:
        H[i+1]-=1
    elif H[i]>=H[i+1]:
        continue
    else:
        flag=False
print("Yes" if flag else "No")
# Judge status: Accepted
n=int(input())
a=[int(i) for i in input().split()]
cnt={}
for i in range(n):
    cnt[a[i]]=0
ok=1
for i in range(n):
    cnt[a[i]]+=1
    if cnt[a[i]]==2:
        print("NO")
        ok=0
        break
if ok==1:
    print("YES")
# Judge status: Accepted
N = int(input())
print(1/2 if(N%2==0) else (N+1)/(2*N) )
# Judge status: Wrong Answer
A,B,C=map(int,input().split())
K=int(input())

for i in range(0,K+1):
    for j in range(0,K+1-i):
        for k in range(0,K+1-i-j):
            #print('{},{},{}'.format(i,j,k))
            if(A*(2**i) < B*(2**j) and B*(2**j) < C*(2**k)):
                if(i==j==k==0):
                    break
                print('Yes')
                exit()

print('No')
# Judge status: Wrong Answer
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=len(a)
a=dict(Counter(a))
count=0
for i in a:
  count+=1
  ans-=a[i]
  if count==k:
    break
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
cnt=0
for x in range(a,b+1):
        if x%c==0:cnt+=1
print(cnt)
# Judge status: Wrong Answer
s = int(input())
x = 10**9-(s%10**9)
y = (s+x)//10**9
print(0,0,10**9,1,x,y)
# Judge status: Wrong Answer
a,b = map(int,input().split())
if a >= b:
  print(a*(a-1))
else:
  print(b*(b-1))
# Judge status: Accepted
def main():
    x, y = map(int, input().split())

    for i in range(x+1):
        if 2 * i + 4 * (x - i) == y:
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n,k = map(int,input().split())
a = sorted([i for i in map(int,input().split())])
maxi = -1
ans = (n + (n - a[-1]%n))%n + a[0]
#print(ans)
for i in range(1,len(a)):
    maxi = max(maxi,a[i] - a[i - 1])
    ans += a[i] - a[i - 1]
maxi = max(maxi,(a[-1] + (a[-1] - a[0]))%n)
ans -= maxi
print(ans)
# Judge status: Wrong Answer
x=int,input()
if(x==1):
  print(0)
elif(x==0):
  print(1)
# Judge status: Wrong Answer
def main():
  n = int(input())
  A = sorted([int(x) for x in input().split()])
  for i in range(n-1):
    if A[i] == A[i+1]:
      print("Yes")
      return 0
      break;
      
  print("No")
  return 0
          
if __name__ == "__main__":
  main()
# Judge status: Accepted
n = int(input())
s = input()

# full search
cnt = s.count('E')

ans = cnt
for i in range(n):
    if s[i] == 'E':
        cnt -= 1
        if ans > cnt:
            ans = cnt
    
    else:
        cnt += 1

print(ans)
# Judge status: Wrong Answer
n, m, k = map(int, input().split())

for i in range(1, n+1):
    for j in range(1, m+1):
        if k == n*j + m*i - 2*i*j:
            print("Yes")
            exit()
print("No")
# Judge status: Accepted
import sys

# print('input >>')
N = int(input())
As = list(map(int,(input().split())))

INF = 10 ** 18

ans = 1

over = False

for A in As:
    if A == 0:
        print(0)
        sys.exit()

for A in As:
    ans *= A
    if ans > INF:
        print(-1)
        sys.exit()
        
# print('-----output-----')
print(ans)
# Judge status: Accepted
# B - Judge Status Summary

n = int(input())

AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(n):
    j =input()
    if j == 'AC':
        AC += 1
    elif j == 'WA':
        WA += 1
    elif j == 'TLE':
        TLE += 1
    elif j == 'RE':
        RE += 1
print('''
AC x {}
WA x {}
TLE x {}
RE x {}
'''.format(AC,WA,TLE,RE))
# Judge status: Accepted
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*N
maxi=max(a)
for i in range(N):
  s.append(1+i-a[i])
  if 1+i+a[i]<N:
    num[1+i+a[i]]+=1
for i in range(N):
  if s[i]>=0:
    count+=num[s[i]]
print(count)
# Judge status: Wrong Answer
n = int(input())
s = input()
e_cnt = 0
for i in range(n):
    if s[i] == "E":
        e_cnt += 1
ans = e_cnt
w_cnt = 0
for i in range(n):
    ans = min(w_cnt + e_cnt, ans)
    if s[i] == "W":
        w_cnt += 1
    else:
        e_cnt -= 1

print(ans)
# Judge status: Wrong Answer
s,w=[int(i) for i in input().split()]
print(["unsefe","safe"][s>w])
# Judge status: Wrong Answer
import collections

n = int(input())
s_list=[input() for i in range(n)]

s_dict=collections.Counter(s_list)
    
ans = [kv[0] for kv in s_dict.items() if kv[1] == max(s_dict.values())]
print(*ans, sep='\n')
# Judge status: Accepted
N,X=map(int,input().split())
print(['No','Yes'][X<=N*500])
# Judge status: Accepted
S = input()

result = 0
if S == "RRR":
    result = 3
elif S == "RRS" or S == "SRR":
    result = 2
elif "R" in S:
    result = 1

print(result)
# Judge status: Accepted
n=int(input())

tmp=[]
for _ in range(n):
    tmp.append(list(map(int,input().split())))

tmp.sort(key=lambda x:x[1])

t = 0
for a,b in tmp:
    t+=a
    if b < t:
        print("No")
        exit()

print("Yes")
# Judge status: Wrong Answer
n = int(input())
s = input()
t = input()

if s == t:
  print(n)
  exit()

ans = ''
for i in range(n):
  ss = s[n-i-1:]
  tt = t[:i+1]
  if ss == tt:
    ans = s[:n-i-1]+t[i+1:]

if len(ans) == 0:
  print(len(s+t))
else:
  print(len(ans))
# Judge status: Accepted
a = []
z = []
s = input()
for i,j in enumerate(s):
    if j == 'A':
      a.append(i)
    elif j == 'Z' :
        z.append(i)
        
print(max(z)-min(a)+1)
# Judge status: Wrong Answer
S = input()
l = sorted(list(set(S)))

ans ="None"
for i in range(len(l)):
  if ord(l[i]) !=  97 + i:
    ans = chr(97+i)
    break

print(ans)
# Judge status: Accepted
w = list(input())
A = [ 0 for _ in range(26)]
for c in w:
    i = ord(c) - ord("a")
    A[i]+=1
ans = "Yes"
for a in A:
    if a%2 == 1:
        ans = "No"
        break
print(ans)
# Judge status: Wrong Answer
# AtCoder Beginner Contest 100
# B - Ringo's Favorite Numbers

D,N=map(int,input().split())
if N==100:
    print(N*101**D)
else:
    print(N*100**D)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
dp=[[0,0]for _ in range(n)]
dp[0]=[a[0],-a[0]]
for i in range(1,n):
  dp[i][0]=max(dp[i-1][0]+a[i],dp[i-1][1]-a[i])
  dp[i][1]=max(dp[i-1][0]-a[i],dp[i-1][1]+a[i])
print(dp[n-1][0])
# Judge status: Accepted
n,m = map(int, input().split())
l=[list(map(int ,input().split())) for x in range(n)]
ans=[0]*(m+1)
for i in range(n):
    for j in range(l[i][0]):
        ans[(l[i][j+1])] +=1
print(ans.count(n))
# Judge status: Wrong Answer
str = input().split()
a1 = int(str[0])
a2 = int(str[1])
if a1 >= a2:
    a1 = a2%a1
if a1 < a2-a1:
    print(a1)
else:
    print(a2-a1)
# Judge status: Wrong Answer
a,b = map(int,input().split())
if a > b:
  print(a*(a-1))
elif a == b:
  print(a*b)
else:
  print(b*(b-1))
# Judge status: Accepted
N = int(input())
for i in range(30):
    for j in range(20):
        if 4*i + 7*j == N:
            print("Yes")
            exit()
print("No")
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

four = 0
two = 0
one = 0
for i in a:
  if i%4 == 0:
    four += 1
  elif i%2 == 0 and i%4 != 0:
    two += 1
  elif i%2 != 0:
    one += 1

if four + 1 >= two//2 + two%2 + one or n == two:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
b = []

if n % 2 == 0:
    for i in range(n - 1, 0, -2):
        print(i)
        b.append(a[i])
    for i in range(0, n, 2):
        print(i)
        b.append(a[i])
else:
    for i in range(n - 1, -1, -2):
        print(i)
        b.append(a[i])
    for i in range(1, n, 2):
        print(i)
        b.append(a[i])

for i in range(len(b)):
    print(b[i], end=" ")
# Judge status: Accepted
n = int(input())
y_count = 0
x = 800*n

for i in range(1,n+1):
    if i%15==0:
        y_count+=1
    
print(x-y_count*200)
# Judge status: Wrong Answer
n = int(input())
a_s = list(map(int, input().split(' ')))
b_s = list(map(int, input().split(' ')))
c_s = list(map(int, input().split(' ')))

sat = 0
for i in range(0, n):
    print(sat)
    idx = a_s[i] - 1
    b = b_s[idx]
    sat += b
    if i < n-1 and a_s[i] +1 == a_s[i+1]:
        if i > 0:
            print('true')
            sat += c_s[i-1]
print(sat)
# Judge status: Accepted
n, m = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
c = [0] * m
d = [0] * m
for j in range(m):
    c[j], d[j] = map(int, input().split())
for i in range(n):
    e = []
    for j in range(m):
        e.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
    f = e.index(min(e))
    print(f + 1)
# Judge status: Accepted
x = input()
count_s = 0
ans = 0
for i in range(len(x)):
    if x[i] == 'S':
        count_s += 1
    if x[i] == 'T':
        if count_s == 0:
            ans += 1
        else:
            count_s -= 1
ans += count_s
print(ans)
# Judge status: Accepted
import math
N,K=map(int,input().split())
A=math.log(N,K)
print(int(A)+1)
# Judge status: Accepted
a, b = input().split()
num = int(a+b)
for i in range(1,317) :
    if num == i ** 2 :
        print("Yes")
        break
else :
    print("No")
# Judge status: Wrong Answer
s = input()
 
x = 0


for i in range(len(s)):
  if s[i] == 1:
    x += 1
  
print(x)
# Judge status: Accepted
k,n=map(int,input().split())
A=list(map(int,input().split()))
ans=-1
for i in range(n-1):
  ans=max(ans,A[i+1]-A[i])
print(k- max(ans,k-(A[n-1]-A[0])))
# Judge status: Accepted
import sys
N = int(input())
A = list(map(int, sys.stdin.readline().split()))
S = 0
for i in A:
    S = S ^ i

for i in A:
    print(S ^ i)
# Judge status: Wrong Answer
n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1) for _ in xrange(2)]
for i in xrange(n):
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[(i+1)%2][j]=max(z[(i+1)%2][j],z[i%2][j-a[i][0]]+a[i][1])
print max(z[(w+1)%2])
# Judge status: Accepted
N = int(input())
S = list(input())

ans = N

left_W = 0
right_E = S[1:].count("E")

for n in range(N):
  if n == 0:
    ans = min(ans,S[1:].count("E"))
        
  elif n == N-1 :
    ans = min(ans,S[:n].count("W"))
      
  else:
    if S[n] == "E":
      right_E -= 1
    if S[n-1] == "W":
      left_W += 1
    ans = min(ans,left_W + right_E)

print(ans)
# Judge status: Wrong Answer
n = int(input())

top= 0
bot= 10**10

for _ in range(n):
	
	x,y = map(int, input().split(' '))
	tot= x+y
	if tot> top:
		top= tot
	if tot< bot:
		bot= tot

print(top-bot)
# Judge status: Wrong Answer
S=input()
T=input()
L=[[0]*26 for _ in range(2)]
for s in S:
  L[0][ord(s)-ord('a')]+=1
for t in T:
  L[1][ord(t)-ord('a')]+=1
ans=0
for i in range(26):
  ans+=abs(L[0][i]-L[1][i])
ans=ans//2
print(ans)
# Judge status: Accepted
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N >= K:
  print(K * X + (N  - K) * Y)
else:
  print(N * X)
# Judge status: Wrong Answer
# 21   import sympyが最速だが、Atcoderには無い
import math
x = int(input())

#エラトステネスの篩
n = [i for i in range(2,2*int(math.sqrt(x))+1)]

for i in n:
    for j in n:
        if j % i == 0 and j/i !=1:
            n.remove(j)
            
while x > 0:
    x +=1
    for i in n:
        if x % i == 0:
            break
    else:
        print(x)
        break
# Judge status: Accepted
n = int(input())
a = 0
for i in range(1,n+1):
    if not(i % 3 == 0 or i % 5 == 0):
        a += i
print(a)
# Judge status: Accepted
import collections

N = int(input().split()[0])
S = input()

index2count_dict = collections.defaultdict(int)
left_black_count = 0
for i, char in enumerate(S):
    index2count_dict[i] = left_black_count
    if char == "#":
        left_black_count += 1

right_white_count = 0
min_count = float("inf")
for i in range(N):
    index = N - (i + 1)
    count = index2count_dict[index] + right_white_count
    min_count = min(min_count, count)
    if S[index] == ".":
        right_white_count += 1

ans = min_count
print(ans)
# Judge status: Accepted
a,b=map(int, raw_input().split())
for i in range(1, 10001):
    if int(i*0.08) == a and int(i*0.1) == b:
        print i
        break
else:
    print -1
# Judge status: Accepted
N, M = map(int, input().split())
if N == M:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
def main():
    n = int(input())
    w = list(map(int, input().split()))

    avr = sum(w) // 2
    print(sum(w))
    res = 0
    ans = 0
    for i in range(n):
        res += w[i]
        if res > avr:
            ans = abs(sum(w[(i+1):]) - sum(w[:(i+1)]))
            print(ans)
            return


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math
import itertools

N = int(input())

line = list(map(int, input().split(" ")))
line_set = set(line)
dic = {}

for num in line_set:
    cnt = line.count(num)
    dic[num] = cnt
    
pattern = list(itertools.combinations(line_set, 3))

sum_ = 0
for lis in pattern:
    a, b, c = lis
    if a + b > c and b + c > a and a + c > b:
        sum_ += dic[a]*dic[b]*dic[c]
print(sum_)
# Judge status: Wrong Answer
n, x, y = map(int, input().split())
L = []
for i in range(1, n):
    for j in range(i+1, n+1):
        length = j - i
        if i <= x and j >= y:
            length -= y-x-1
        L.append(length)
for k in range(1, n):
    print(len([l for l in L if l==k]))
# Judge status: Wrong Answer
import math

X = int(input())

l = [True] * 1000001
l[0], l[0] = False, False

for i in range(1, 1000+1):
  if l[i]:
    if i >= X:
      print(i)
      break
    else:
      for j in range(2*i, 1000000, i):
        l[j] = False
# Judge status: Wrong Answer
import math
n = input()
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
  ans = min(ans, len(bin(i)) - bin(i).rfind("1") -1)
  print(round(ans))
# Judge status: Accepted
import collections

n = int(input())
a = list(int(input()) for i in range(n))

a = dict(collections.Counter(a))
ans = [i for i in a.values() if i%2 == 1]

print(len(ans))
# Judge status: Wrong Answer
a,b = map(int,input().split())
print(a if a<b else a-1)
# Judge status: Accepted
S = input()
T = input()

ans = "No"

if (len(S) == len(T) - 1) & (S == T[:-1]):
    ans = "Yes"

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

alice, bob = 0, 0

for i in range(len(a)):
    if i % 2 == 0:
        alice += max(a)
        a.remove(max(a))
    else:
        bob += max(a)
        a.remove(max(a))

print(alice - bob)
# Judge status: Accepted
N,K = map(int,input().split())
A = list(map(int,input().split()))

Ad = {x:0 for x in set(A)}
if len(set(A)) <= K:
    print(0)
else:
    count = 0
    for a in A:
        Ad[a] += 1
    Ad = sorted(Ad.items(), key=lambda x:x[1])
    for i in range(len(set(A))-K):
        count += Ad[i][1]
    print(count)
# Judge status: Accepted
N = int(input())
S = input()

l = 0
for i in range(N):
    k = len(set(S[:i]) & set(S[i:]))
    if k > l:
        l = k
print(l)
# Judge status: Accepted
x = int(input())

def judge(n):
    for i in range(1, n // 2 + 1):
        if i == 1: continue
        if n % i == 0:
            return False
    return True

i = x
while True:
    if judge(i):
        print(i)
        break
    i += 1
# Judge status: Wrong Answer
s=input()
k=int(input())
m=len(s)
box=[chr(i) for i in range(97,97+26)]

word={j:26-i for i,j in enumerate(box)}
word_num={26-i:j for i,j in enumerate(box)}
number={i:j for i,j in enumerate(box)}
ans=""

for i,j in enumerate(s):
    if i==m-1:
        k %=26
        if k>=word[j]:ans +=number[k-word[j]]
        else:ans +=word_num[word[j]-k]
    elif word[j]<=k:
        k -=word[j]
        ans +="a"
    else:ans +=j

print(ans)
# Judge status: Accepted
n=int(input())
ans=0
if 10**(len(str(n))-1)==n:
    ans=10
else:
    listn=list(str(n))
    for i in range(len(listn)):
        ans+=int(listn[i])
print(ans)
# Judge status: Accepted
import math
INF = 1001001001
h, n = map(int, input().split())
ab = list(list(map(int, input().split())) for _ in range(n))

dp = [INF] * (h+1)
dp[0] = 0
for i in range(n):
    for j in range(h):
        nj = min(j+ab[i][0], h)
        dp[nj] = min(dp[nj], dp[j]+ab[i][1])

print(dp[h])
# Judge status: Accepted
n,m=map(int,input().split())
l,r=1,n
for i in range(m):
    L,R=map(int,input().split())
    l=max(l,L)
    r=min(r,R)
if l>r:
    print(0)
else:   
    print(r-l+1)
# Judge status: Accepted
s = input()
if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a,b,c = map(int,input().split())
if b+c >= a:
  print(int(c-a+b))
else:
  print('0')
# Judge status: Accepted
n = int(input())
ans = 0
sums = 0
for i in range(n):
    a = int(input())
    sums += a
    if a == 0:
        ans += sums // 2
        sums = 0
ans += sums // 2
print(ans)
# Judge status: Wrong Answer
x, y = map(int,input().split())
print([-1, x][y%x>0])
# Judge status: Accepted
n = int(input())
s = list(str(input()))
t = list(str(input()))
p = 0
ans = n * 2

for i in range(n):
    if s[i] == t[0]:
        for x in range(n-i):
            if s[i + x] == t[x]:
                p += 1
            else:
                p = 0
                break
        else:
            ans -= p
            break

print(ans)
# Judge status: Wrong Answer
n=int(input())
a=[]
for n in range(n):
  a.append(input())

frag='Yes'
for i in range(n):
  if a.count(a[i])!=1:
    frag='No'
    break
for i in range(n-1):
  if a[i][-1]!=a[i+1][0]:
    frag='No'
    break
    
print(frag)
# Judge status: Wrong Answer
from itertools import combinations

n = int(input())
l = list(map(int, input().split()))

# 三角形
# a+b > c 

result = []
for idx in combinations(list(range(len(l))), 3):
    if (l[idx[0]] != l[idx[1]] and l[idx[1]] != l[idx[2]] and l[idx[2]] != l[idx[0]]):
        if (l[idx[0]]+l[idx[1]] > l[idx[2]]):
            result.append([idx[0]+1,idx[1]+1,idx[2]+1])
print(len(result))
# Judge status: Accepted
N = int(input())
X = list(map(int, input().split()))
X = sorted(X)

# print(N)
# print(X)

minX, maxX = min(X), max(X)
min_cost = 1e10

for p in range(minX, maxX + 1):
    cost = sum([(x - p) ** 2 for x in X])
    min_cost = min(min_cost, cost)

print(min_cost)
# Judge status: Wrong Answer
S = input()
l = len (S)
S = S.replace('a','')
S = S.replace('i','')
S = S.replace('u','')
S = S.replace('e','')
S = S.replace('o','')
print (l-int (len(S)))
# Judge status: Accepted
MOD = int(1e9+7)

N = int(input())
answer = pow(10, N, MOD)
answer -= pow(9, N, MOD) * 2
answer += pow(8, N, MOD)
answer %= MOD
print(answer)
# Judge status: Wrong Answer
from math import gcd

A, B, K = map(int, input().split())
gcd_ = gcd(A,B)

cnt = 0
for i in range(1, gcd_+1):
    modA = A%i
    modB = B%i
    if modA==0 and modB==0:
        cnt += 1
    elif modA*100%i == 0 and modB*100%i == 0:
        cnt += 1
    if cnt == K:
        print(i)
        exit()
# Judge status: Accepted
w, h, x, y = map(int, input().split())

ans = 0
if w / 2 == x and h / 2 == y:
    ans = 1
    
print((w * h) / 2, ans)
# Judge status: Accepted
L=list(map(int,input().split()))
L.sort()
print(L[0]*L[1]*(L[2]%2))
# Judge status: Accepted
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

a,b,c,k = map(int,readline().split())
if even(k):
    print(a-b)
else:
    print(b-a)
# Judge status: Accepted
l = list(map(int,input().split()))

l.sort()
flag = False

for item in l:          
    if item % 2 == 0:
        flag = True

if flag == True:
    print(0)
else:
    print(l[0] * l[1])
# Judge status: Accepted
s = input()
t = input()

s = sorted(s)
t = sorted(t,reverse = True)
ans = "Yes" if s < t else "No"
print(ans)
# Judge status: Wrong Answer
n = int(input())
l = list(map(int,input().split()))

from itertools import accumulate

tot=sum(l)
ans=10**9+7
for i in list(accumulate(l)):
    if i <= tot//2:
        ans=min(ans, abs(tot-(i*2)))


for i in list(accumulate(l[::-1])):
    if i <= tot//2:
        ans=min(ans, abs(tot-(i*2)))

print(ans)
# Judge status: Accepted
n, x = map(int, input().split())
l = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-1):
    if l[i] <= x:
        x -= l[i]
        ans += 1
else:
    if l[-1] == x:
        ans += 1
print(ans)
# Judge status: Wrong Answer
n, m = map(int, input().split())

X = sorted(map(int, input().split()))

distances = sorted((X[i+1]-X[i], i, i+1) for i in range(m-1))

if n >= m:
    print(0)
    exit()

ans = 0
distances = distances[-n+1:]
distances.sort(key=lambda x: x[1])

start = 0
for _, l, r in distances:
    ans += X[l] - X[start]
    start = r

if start < r:
    ans += X[-1] - X[start]

print(ans)
# Judge status: Accepted
W,H,x,y = map(int, input().split())
print(W*H/2, 1 if W/2 == x and H/2 == y else 0)
# Judge status: Accepted
L=int(input())
di = L/3
print(str(di * di * di))
# Judge status: Wrong Answer
n = int(input())
print(n * (n + 1) // 2)
# Judge status: Accepted
s=input()
t=input()
n=len(s)
m=len(t)
ind=-1
for i in range(n-m+1):
  f=0
  for j in range(m):
    c=s[n-i-1-j]
    if t[m-1-j]!=c and c!='?':
      break
    else:
      f+=1
  if f==m:
    ind=i
    break

if ind==-1:
  print("UNRESTORABLE")
else:
  s=s[:n-ind-m]+t+s[n-ind:]
  s=s.replace('?','a')
  print(s)
# Judge status: Accepted
A,B,C = map(int,input().split())
print(min(C,B//A))
# Judge status: Accepted
# B - 105

N = int(input())

ans = 0
for i in range(1,N+1,2):
    tmp = 0
    for j in range(1, i+1):
        if i%j==0:
            tmp += 1
    if tmp==8:
        ans += 1

print(ans)
# Judge status: Wrong Answer
N = int(input())

x = N * 800
y = 0

for i in range(N+1):
    if i % 15 == 0:
        y = y + 200
ans = x-y        
print(ans)
# Judge status: Accepted
n=int(input())
t=0
for i in range(n):
  l=len(str(i+1))
  if l%2!=0:
    t+=1
    #print(i)
print(t)
# Judge status: Accepted
N,M = map(int,input().split())
XY = [tuple(map(int,input().split())) for i in range(M)]

rs = [0] * N
rs[0] = 1
cs = [1] * N
for x,y in XY:
    x,y = x-1,y-1
    if rs[x]:
        if cs[x]==1:
            rs[x] = 0
        rs[y] = 1
    cs[x] -= 1
    cs[y] += 1
print(sum(rs))
# Judge status: Accepted
import sys
input = sys.stdin.readline

def main():
    s = input()
    min_a_index = min([i for i, c in enumerate(s) if c == "A"])
    max_z_index = max([i for i, c in enumerate(s) if c == "Z"])
    print(max_z_index - min_a_index + 1)

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
odd = 0
even2 = 0
even4 = 0
for x in a:
    if x % 2 == 1:
        odd += 1
    elif x % 4 == 0:
        even4 += 1
    else:
        even2 += 1
if even4 - odd > -1:
    print('Yes')
elif even4 - odd == -1 and even2 == 0:
    print('Yes')
else:
    print("No")
# Judge status: Wrong Answer
import datetime

S = input()
S = datetime.datetime.strptime(S, '%Y/%m/%d')



a = int(S.year)

if a != 2018:
    S = S.replace(2018)
    
print(S.date())
# Judge status: Accepted
a=int(input())

if a >= 30:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
a = [int(x) for x in input().split()]

b = [x-(i+1) for i,x in enumerate(a)]
b.sort()

x = b[n//2]

ans = 0
for i in range(n):
    ans += abs(b[i]-x)

print(ans)