peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 13:43:11 2020

@author: shinba
"""
import sys 
import itertools

l,r = map(int,input().split())

if l % 2019 == 0:
    print(0)
    sys.exit()
else:
    if l//2019 +1 <= r/2019:
        print(0)
        sys.exit()

l %= 2019
r %= 2019
ans = float("inf")

for i in itertools.combinations(range(l,r+1),2):
    mod = (i[0]*i[1])%2019
    ans = min(mod,ans)
    
print(ans)
# Judge status: Accepted
N = int(input())
move = []

for _ in range(5):
    move.append(int(input()))

min_value = min(move)
group_count = -(-N // min_value)

# 最後のグループが出発するまでの値はgroup_count - 1
print(group_count - 1 + 5)
# Judge status: Accepted
n,k,x,y = [int(input()) for i in range(4)]
print(n*x-(x-y)*max(n-k,0))
# Judge status: Accepted
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t = t + F[j] - (t % F[j])
        t += C[j]
    print(t)
# Judge status: Accepted
# -*- coding: utf-8 -*-
 
def score(x,y,z):
    return pow(x,2)+pow(y,2)+pow(z,2)+(x*y)+(y*z)+(z*x)

N = int(input())

num = [0 for i in range(N)]
# x,y,zは高々10^2
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            value = score(x,y,z)
            if value <= N:
                num[value-1] += 1

for n in num:
    print(n)
# Judge status: Wrong Answer
s=input()
if s=="Sunny":
  print("Cloudy")
if s=="Cloudy":
  print("Rainy")
else:
  print("Sunny")
# Judge status: Accepted
n = int(input())
print((n*(n+1))//2)
# Judge status: Accepted
A,B,C,D=map(int, input().split())
print('Yes' if (C+B-1)//B <= (A+D-1)//D else 'No')
# Judge status: Accepted
from collections import Counter
def p_factorization(n):
  p=[]
  for i in range(2,int(n**0.5)+1):
    while n%i==0:
      p.append(i)
      n//=i
  if n>1:
    p.append(n)
  return p
n=int(input())
ans=0
for pi in Counter(p_factorization(n)).items():
  x=pi[1]
  for i in range(50):
    if i*(i+1)//2<=x<(i+1)*(i+2)//2:
      ans+=i
      break
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
import math
D = 10 ** 9 + 7


# 組み合わせの総数 nCr
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

S = int(input())

max_length = S // 3

total = 0
for i in range(max_length):
    N = (S + i) - 3 * (i + 1)
    add = combinations_count(N, i)
    total += add
    total %= D

print(total)
# Judge status: Accepted
n = int(input())
x = n
y = n//15
print(800*x - 200*y)
# Judge status: Accepted
n, a = map(int,open(0))
print("YNeos"[n % 500 > a :: 2])
# Judge status: Accepted
import sys
k=int(input())
a,b=map(int,input().split())
for i in range(a,b+1):
    if i%k==0:
        print("OK")
        sys.exit()
else:
    print("NG")
# Judge status: Accepted
# coding: utf-8
# Your code here!
a, b, c = map(int,input().split())

if a <= c <= b:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
x = int(input())
sum = 600
for i in range(8, 0, -1):
    if x < sum:
        print(i)
        break
    sum += 20
# Judge status: Accepted
n,k=map(int,input().split())
check=[0]*n
ans=0
for i in range (k):
  d=int(input())
  l=list(map(int,input().split()))
  for j in range(d):
    h=l[j]
    check[h-1]+=1
    
for k in range(n):
  if check[k]==0:
    ans+=1

print(ans)
# Judge status: Accepted
n = int(input())
l, r = 0, n**2
while r-l > 1:
  k = (r+l)//2
  if k*(k+1)//2 < n:
    l = k
  else:
    r = k

if n == 1:
  r = 1

key = []
for i in range(r, 0, -1):
  if n-i >= 0:
    key.append(i)
    n -= i
    if not n:
      break

key.reverse()
for value in key:
  print(value)
# Judge status: Wrong Answer
A = map(int, input().split())

if sum(A) > 22:
  print('bust')
else:
  print('win')
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))

hight_sum = 0
for i in range(n-1):
    hight = 0
    diff = a[i+1] - a[i]
    if diff < 0:
        hight -= diff
        a[i+1] -= diff
        hight_sum += hight
print(hight_sum)
# Judge status: Accepted
n = int(input())
p_l = list(map(int,input().split()))
p_sort = sorted(p_l)

cnt = 0
for i in range(n):
    if(p_l[i]!=p_sort[i]):
        cnt += 1
if(cnt <= 2):
    print('YES')
else:
    print('NO')
# Judge status: Accepted
import bisect

def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c,d=Csum(a),Csum(b)
d.pop(0)
ans=0
for i in range(n+1):
    if k-c[i]<0:
        break
    ans=max(ans,i+bisect.bisect_right(d,k-c[i]))
print(ans)
# Judge status: Wrong Answer
n,m = map(int,input().split())
ans = 0
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        x = m//i
        if x>=n:
            ans = i
print(ans)
# Judge status: Wrong Answer
s = int(input())
if s == 0:
  print(0)
elif s == 1 or 10 or 100:
  print(1)
elif s == 11 or 101 or 110:
  print(2)
else:
  print(3)
# Judge status: Accepted
x = int(input())
if x == 3 or x == 5 or x == 7:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
num = input()

num_list = ["Sunny","Cloudy","Rainy","Sunny"]

counter = num_list.index(num)


print(num_list[counter + 1])
# Judge status: Accepted
a, b, k = map(int, input().split())
j = 0

if a >= b:
    a, b = b, a

ans = [0] * a

for i in range(1, a + 1):
    if a % i == 0 and b % i == 0:
        ans[j] = i
        j = j + 1

ans.sort(reverse = True)
print(ans[k - 1])
# Judge status: Wrong Answer
a = int(input())
n1 = int( "%s" % a )
n2 = int( "%s%s" % (a,a) )
n3 = int( "%s%s%s" % (a,a,a) )
print (n1+n2+n3)
# Judge status: Accepted
x = int(input())
ans = (x // 500) * 1000 + ((x % 500) // 5) * 5
print(ans)
# Judge status: Accepted
data=[int(x) for x in input().split()]
if data.count(data[0])==2 or data.count(data[1])==2:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
I=lambda:list(map(int,input().split()))
n=I()[0];arr=I();q=I()[0];
cnt={};
for i in arr:cnt[i]=0;
for i in arr:cnt[i]+=1;
s=sum(arr)
while(q):
  q-=1;b,c=I();
  if(b not in cnt or not cnt[b]):print(s);continue;
  s-=(cnt[b]*b);s+=(cnt[b]*c);
  if(c not in cnt):cnt[c]=0;
  cnt[c]+=cnt[b];cnt[b]=0;
  print(s)
# Judge status: Accepted
S,C=map(int,input().split())

x=min(S, C//2)
if S>x:
    print(x)
else:
    x+=(C-2*x)//4
    print(x)
# Judge status: Accepted
A, B, C, K = map(int, input().split())

if K%2==1:
  print(-A+B)
else:
  print(A-B)
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))
sa=set(a)
nums=len(sa)
if nums<=k:
    print(0)
else:
    num=[0]*n
    for i in range(n):
        num[a[i]-1]+=1
    num.sort()
    ans=0
    for i in range(n-k):
        ans+=num[i]
    print(ans)
# Judge status: Accepted
w = input()
wl = []
for i in range(len(w)):
    wl.append(w[i])

from collections import Counter
W = Counter(wl)

answer = 'Yes'
for i in range(len(w)):
    if W[w[i]]%2 != 0:
        answer = 'No'
        break
        
print(answer)
# Judge status: Accepted
yymmdd = list(input())
yymmdd[3] = "8"
print("".join(yymmdd))
# Judge status: Accepted
from bisect import bisect_left

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

L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        k = bisect_left(L, L[i]+L[j])
        ans += (k-j-1)
print(ans)
# Judge status: Accepted
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

import bisect as bs
import numpy as np
A.sort()
C.sort()
#B_a:b未満のAのパーツ数、B_c:b超のCのパーツ数
B_a = np.array([bs.bisect_left(A,b) for b in B]) 
B_c = np.array([N-bs.bisect_right(C,b) for b in B])
ans = np.dot(B_a, B_c)
print(ans)
# Judge status: Wrong Answer
A, B, N = map(int, input().split())

lo = 0
hi = N
ans = 0

def f(x):
    return int(A*x/B)-A*int(x/B)

while lo < hi:
    mid = (lo + hi) // 2
    
    if f(lo) < f(hi):
        lo = mid + 1
    else:
        hi = mid

print(f(lo))
# Judge status: Accepted
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N - x + 1):
        z = N - x - y
        if x*10000+y*5000+z*1000 == Y:
            print(x, y, z)
            exit()


print("-1 -1 -1")
# Judge status: Accepted
n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
minc=float("inf")

for i in range(2**n):
  lst=[0]*(m+1)
  for bit in range(n):
    if (i>>bit)&1==1:
      for ii,aa in enumerate(a[bit]):
        lst[ii]+=aa
  if min(lst[1:]) >= x:
    minc=min(minc,lst[0])
    
print(-1 if minc == float("inf") else minc)
# Judge status: Accepted
n=int(input())
print(int(n*(n+1)/2))
# Judge status: Wrong Answer
n,r = map(int,input().split())
print(r+100*(10-n))
# Judge status: Accepted
import functools
import fractions

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

# xが2で何回割れるか
def div2count(x):
    count=0
    while x%2==0:
        x=x//2
        count+=1
    return count

N,M=map(int,input().split())
A=list(map(int,input().split()))
if len(set(map(div2count,A)))!=1:
    print(0)
    exit()
LCM=functools.reduce(lcm,A)
HLCM=LCM//2
Y=M//HLCM
if Y%2==0:
    print(Y//2)
else:
    print((Y+1)//2)
# Judge status: Wrong Answer
N = int(input())

def digit_sum(A):
    S = 0
    while A > 0:
        S += A % 10
        A //= 10
    return S

ans = 10e+6
for A in range(N):
    cand = digit_sum(A) + digit_sum(N - A)
    ans = min(ans, cand)

print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.buffer.readline

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)

for _ in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)

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

res = 0
for i in range(1, l):
    for j in range(i, l):
        if l > i+j:
            k = l - (i+j)
            res = max(res, k*i*j)
print(res)
# Judge status: Accepted
import math
n, d = map(int, input().split())
print(math.ceil(n/(1 + 2*d)))
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[n-1] == n:
    p[n-1], p[n-2] = p[n-2], p[n-1]
    ans += 1
print(ans)
# Judge status: Wrong Answer
W, H, N = map(int, input().split())
x0, y0 = 0, 0

for _ in range(N):
    xi, yi, a = map(int, input().split())
    if a == 1:
        x0 = max(xi, x0)
    elif a == 2:
        W = min(xi, W)
    elif a == 3:
        y0 = max(yi, y0)
    elif a == 4:
        H = min(yi, H)

ans = (W-x0)*(H-y0)
if ans < 0:
    ans = 0
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
result = 0
for i in range(a, b+1):
    if str(i) == str(i)[::-1]:
        result += 1
print(result)
# Judge status: Wrong Answer
n = int(input())-1
a = "abcdefghijklmnopqrstuvwxyz"
s = a[n % 26]
n = n//26
while n:
    s = s + a[n % 26-1]
    n = n // 26
print(s[::-1])
# Judge status: Wrong Answer
A, B, X = map(int, input().split())
if A <= X:
  print('YES')
elif X <= A + B:
  print('YES')
else:
  print('NO')
# Judge status: Accepted
n, m, k= map(int, input().split())
for p in range(m+1):
    for q in range(n+1):
        t = n*p + m*q - 2*p*q
        if t == k:
            print('Yes')
            exit()
else:
    print('No')
# Judge status: Accepted
N = input()

l = [int(x) for x in list(str(N))]

if int(7) in l:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
n, t = map(int, input().split())

c_t = [list(map(int, input().split())) for i in range(n)]

min_c = t + 1
for i in c_t:
    if i[1] <= t and i[0] < min_c:
        min_c = i[0]

if min_c == t+1:
    print("TLE")
else:
    print(min_c)
# Judge status: Accepted
tem = int(input(""))
if tem >= 30:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
dic = {}
dic.setdefault('a',str(input())+'E')
dic.setdefault('b',str(input())+'E')
dic.setdefault('c',str(input())+'E')
dare = dic['a'][0]
dic['a'] = dic['a'][1:]
while len(dic['a'])>0 and len(dic['b'])>0 and len(dic['c'])>0:
    tmp = dic[dare][0]
    dic[dare] = dic[dare][1:]
    if tmp=='E':
        ans = dare.upper()
    dare = tmp
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

a,b=MI()
if (a+b)%2==0:
    print((a+b)//2)
else:
    print("IMPOSSIBLE")
# Judge status: Wrong Answer

a = int(input())
b = int(input())
c = int(input())

x = int(input())

count = 0

for i in range(a):
    for j in range(b):
        for k in range(c):
            total = 500 * i + 100 * j + 50 * k
            if total == x:
                count += 1

print(count)
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
minx=S
sum=0
for x in A:
  sum+=x
  minx=min(minx,abs(sum-(S-sum)))
print(minx)
# Judge status: Wrong Answer
s = input()
l = len(s)

for i in range(2**(l-1)):
    ans = 0
    a = s[0]
    for j in range(l-1):
        if i >> j == 0:
            a += '+' + s[j+1]
        else:
            a += '-' + s[j+1]
    ans = eval(a)
    if ans == 7:
        print(a + '=7')
# Judge status: Wrong Answer
from itertools import product

N,K = list(map(int,input().split()))
D = list(map(int,input().split()))

D_ = [_ for _ in range(10) if _ not in D]
D_.sort()

break_flag=False
for s_ in D_:
    if break_flag:
        break
    elif s_ == 0:
        continue
    for p in product(D_,repeat=len(str(N))-1):
        ans=int(str(s_)+''.join(map(str,p)))
        if N <= ans:
            print(ans)
            break_flag=True
            break
# Judge status: Accepted
s=list(input())
for i in range(ord('a'),ord('z')+1):
    if s.count(chr(i))==0:
        print(chr(i))
        exit()
print('None')
# Judge status: Accepted
n=int(input())
s=input()
import sys
a=0
if n==1:
    print('No')
    sys.exit()
if n%2!=0:
    print('No')
    sys.exit()
else:
    for i in range(n//2):
        if s[i]==s[i+(n//2)]:
            pass
        else:
            a=1
            break
if a==0:
    print('Yes') 
else:
    print('No')
# Judge status: Accepted
S = list(input())
flag = [0]*26
for c in S:
    if(flag[ord(c)-ord('a')] == 0):
        flag[ord(c)-ord('a')] = 1
    else:
        print("no")
        exit()
print("yes")
# Judge status: Wrong Answer
import numpy as np
tmp=[int(i) for i in input().split(' ')]
tmp_s=[int(i) for i in input().split(' ')]
score=[]
leng=tmp[0]-tmp[1]+1
for i in range(leng):
  t=np.prod(np.array(tmp_s)[i:i+tmp[1]])
  score.append(t)
  if i>0:
    if score[i-1]<score[i]:
      print('Yes')
    else:
      print('No')
# Judge status: Accepted
L,R=map(int,input().split())
ans=2019
for i in range(L,R):
	for j in range(i+1, R+1):
		if j%2019==0:
			print(0)
			exit()
		ans=min(ans,(i*j)%2019)
print(ans)
# Judge status: Wrong Answer
#!/usr/bin/env python

def main():
    s = int(input())
    if s <= 10 ** 9:
        x1 = s
        y2 = 1
        y1 = 0
        x2 = 0
    else:
        u, d = divmod(s, 10**9)
        x1 = u + 1
        y2 = 10 ** 9
        y1 = 10 ** 9 - d
        x2 = 1

    print(0, 0, x1, y1, x2, y2)

if __name__ == '__main__':
    main()
# Judge status: Accepted
S = input()
for i in range(4)[::-1]:
    if 'R' * i in S:
        print(i)
        exit()
# Judge status: Accepted
X,K,D=map(int, input().split())

if abs(X) // abs(D) > K:
    print(abs(X)-(K*D))
    exit()

K2= K - (abs(X) // D)


X= abs(X) - abs(((K-K2)*D))

if K2 % 2 == 1:
    X= abs(X) - D


print(abs(X))
# Judge status: Accepted
ans = 10 ** 9
n = int(input())
A = list(map(int,input().split()))
for i in range(-100,101):
  X = 0
  for j in A:
    X += (j - i) ** 2
  ans = min(ans,X)
print(ans)
# Judge status: Accepted
N, K = map(int, input().split(' '))
print(min(N % K, abs(N % K - K)))
# Judge status: Accepted
import sys
input = sys.stdin.readline

x = int(input())
a = 1
while True:
    for b in range(0, a):
        if a**5 - b**5 == x:
            print(a, b)
            sys.exit()
        if a**5 + b**5 == x:
            print(a, -b)
            sys.exit()
    a += 1
# Judge status: Wrong Answer
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

for i in range(n):
    if B[i] - A[i] >= 0:
        ans += A[i]
        B[i] = B[i] - A[i]
        if B[i] - A[i+1] >= 0:
            ans += A[i+1]
        else:
            ans += B[i]
            A[i+1] = A[i+1] - B[i]
    else:
        ans += B[i]

print(ans)
# Judge status: Accepted
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
li=c.most_common()
if len(li)<=k:
  print(0)
  exit()
li=li[k:]
ans=0
for i in li:
  ans+=i[1]
print(ans)
# Judge status: Accepted
from math import *

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

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

right=[0]*(N+1)
for i in range(N-1,-1,-1):
  right[i]=gcd(right[i+1],A[i])

ans=0
for i in range(N):
  ans=max(ans,gcd(left[i],right[i+1]))

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

xl = [tuple(map(int, input().split())) for _ in range(n)]
xl = sorted(xl)


def run(xl):
    res = 1
    x, l = xl[0]
    cur = x + l
    for (x, l) in xl:
        if x - l >= cur:
            cur = x + l
            res += 1
    return res


res = max(run(xl), run(list(reversed([(-x, l) for x, l in xl]))))

print(res)
# Judge status: Accepted
N, M = map(int, input().split())

a = set([i + 1 for i in range(M)])
for n in range(N):
    A = list(map(int, input().split()))
    K = A.pop(0)
    a &= set(A)
print(len(a))
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
x = 2*(a+b)
if x>=c:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N,X,Y = map(int,input().split())

X -= 1
Y -= 1
ans = [0]*(N)

d = [[N]*N for i in range(N)]

for i in range(N):
    for j in range(i,N):
        if i<=X and Y<=j:
            d[i][j] = X-i+j-Y+1
        else:
            d[i][j] = min(abs(i-X)+abs(Y-j)+1,j-i)



for i in range(N):
    for j in range(i+1,N):
        ans[d[i][j]] += 1

for i in range(1,N):
    print(ans[i])
# Judge status: Accepted
N = int(input())
l = list(map(int,input().split()))
Sum = sum(l)
ans = 0
for i in range(N-1):
    Sum -= l[i]
    ans += Sum*(l[i])
    ans %= (10**9 + 7)

print(ans)
# Judge status: Wrong Answer
a,b=list(map(int,input().split()))

for i in range(1000):
    if int(i*0.08)==a and int(i*0.1)==b:
        print(i)
        break
    elif i==100:
        print(-1)
# Judge status: Wrong Answer
A=int(input())
N=1
for i in range(A):
  if i**2 <= A:
    N = i**2
  else:
    break
print(N)
# Judge status: Accepted
from collections import defaultdict
n,m=map(int, input().split())
v = [0]*n
v[0]=1
ans = [1]*n
fi = 1
for i in range(m):
    a,b=map(int, input().split())
    ans[a-1]-=1
    ans[b-1]+=1
    if v[a-1]:
        v[b-1]=1
        fi+=1
    if ans[a-1]==0:
        v[a-1]=0
        fi-=1

print(sum(v))
# Judge status: Accepted
c=input()
bo=["a","i","u","o","e"]

if c in bo:
  print("vowel")
else:
  print("consonant")
# Judge status: Accepted
a,b,c=map(int,input().split())
if a==b and b!=c:
  print("Yes")
elif b==c and c!=a:
  print("Yes")
elif c==a and a!=b:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
if a[0] > x:
  c += a[0] - x
  a[0] = x
for i in range(n-1):
  if a[i]+a[i+1] > x:
    c +=  a[i]+a[i+1] - x
    a[i+1] = x-a[i]
print(c)
# Judge status: Accepted
n,m = map(int,input().split())
Al =[0]*(m+1)


for i in range(n):
  A = list(map(int,input().split()))
  
  for j in range(1,A[0]+1):
    Al[A[j]] += 1

print(Al.count(n))
# Judge status: Wrong Answer
n=int(input())

ans=[0]*(2001)

ans[3]=1
for  i in range(4,2001):
  a=1
  for j in range(3,i):
    if (i-j>=3 ):
      a+=(ans[j]*ans[i-j])
      a%=(10**9+7)
  ans[i]=a;
print(ans[n]%(10**9+7))
# Judge status: Wrong Answer
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
y = a[0]
for i in range(1, N):
    z = a[i]
    w = max(y+z-x, 0)
    y = z-w
    ans += w

print(ans)
# Judge status: Accepted
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
 
 
 
array=[a,b,c,d,e]
if(max(array)-min(array) <= k):
    print("Yay!")
else:
    print(":(")
# Judge status: Accepted
N = int(input())
D1 = [0]*N
D2 = [0]*N

for i in range(N):
  D1[i], D2[i] = map(int, input().split())
  
a = 0
  
for i in range(N-2):
  if D1[i] == D2[i] and D1[i+1] == D2[i+1] and D1[i+2] == D2[i+2]:
    a = 1
    
if a == 1:
  print("Yes")

else:
  print("No")
# Judge status: Wrong Answer
import math
R = int(input())

print(2*math.pi)
# Judge status: Wrong Answer
N = int(input())
S = list(input())

cnt = sum([1 for i in range(N-2) 
           for j in range(i+1, N-1) 
           for k in range(j+1, N) 
           if S[i] != S[j] != S[k] and j-i != k-j
          ])   
        
print(cnt)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
a.sort()
Alice = 0
Bob = 0
for i in range(n):
  if i % 2 == 0:
    Alice += a[i]
  else:
    Bob += a[i]
print(Alice - Bob)
# Judge status: Accepted
N=int(input())
ans=1
for i in range(1,N+1):
    ans=(ans*i)%1000000007
print(ans%(10**9+7))
# Judge status: Wrong Answer
# おっぱっぴー

A, B, C = map(int, input().split())

if A == B == C:
    print(-1)
for i in range(100):
    A, B, C = B/2+C/2, A/2+C/2, A/2+B/2

    if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
        print(i+1)
        break
# Judge status: Wrong Answer
X, Y = map(int, input().split())
ans = 0
for i in range(X):
    ans += 4
if ans >= Y:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import sys

n, *lst = map(int, sys.stdin.read().split())
sqr = int(n ** 0.5) + 1
for i in range(sqr, 0, -1):
  if not n % i:
    print(i + n // i - 2)
    quit()
# Judge status: Accepted
a=list(input())
b=list(input())
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
    print("YES")
else:
     print("NO")
# Judge status: Wrong Answer
s = input()
check = True
for c in s:
    if s.count(c) > 1:
        check = False
        break
print('Yes' if check else 'No')
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())

def binary_search(ok, ng, cond):
    while abs(ok - ng) > 1:
        mid = (ok + ng) / 2
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

candidate = int(binary_search(n, 0, lambda x: x * 1.08 >= n))
if n == int(candidate * 1.08):
    print(candidate)
else:
    print(':(')
# Judge status: Accepted
a = [0]*5
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())
b = 10**10
t = 0
for i in range(5):
    c = a[i]%10
    t += -1*(-1*a[i]//10)*10
    if c == 0:
        pass
    else:
        b = min(b,c)
if b == 10**10:
    print(t)
else:
    print(t+b-10)
# Judge status: Wrong Answer
s=list(map(int,input().split()));print(min(s.count("0"),s.count("1")))
# Judge status: Accepted
import math

h = int(input())
w = int(input())
n = int(input())

if h > w:
    print(math.ceil(n / h))
else:
    print(math.ceil(n / w))
# Judge status: Accepted
import itertools
n = int(input())
a = tuple([int(i) for i in input().split()])
b = tuple([int(i) for i in input().split()])

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
res = 1000
for i in range(n-1):
  print(2*sum(a[:i]))
  res = min(res,abs(sum(a[:i+1])-sum(a[i+1:])))
print(res)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
ans = 0
if N >= 2:
    ans += A[0]

if N >= 3:
    idx = 1
    for i in range(N-2):
        ans += A[idx]
        if i % 2 == 1:
            idx += 1

print(ans)
# Judge status: Wrong Answer
N = int(input())
P = [int(x) for x in input().split()]

ans = 0
if P[0] == 1:
    temp = P[1]
    P[1] = P[0]
    P[0] = temp
    ans += 1
for i in range(1,N):
    if P[i] == i+1:
        temp = P[i]
        P[i] = P[i-1]
        P[i-1] = P[i]
        ans += 1
print(ans)