peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n,m,x,y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
if x[n-1]<y[0]:
  print("No War")
else:
  print("War")
# Judge status: Accepted
S, T = input().split()
A, B = [int(x) for x in input().split()]
U = input()

d = {S: A, T: B}
d[U] -= 1

print(d[S], d[T])
# Judge status: Accepted
import math

n,k = map(int,input().split())
ans = int(math.log(n,k))+1
print(ans)
# Judge status: Wrong Answer
i = int(input())

k = 100
cnt = 0
while k > 0:
  if i // k == 1:
    cnt += 1
    
  i %= 100
  k //= 10
  
print(cnt)
# Judge status: Wrong Answer
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
binary_list = [1 for i in range(n)]
#print(a_list)

for i in range(n):
    if binary_list[i]==1:
        for k in range(i+1, n):
            if a_list[k]%a_list[i]==0:
                binary_list[k] = 0

if a_list[0] in a_list[1:]:
    binary_list[0] = 0

print(sum(binary_list))
# Judge status: Accepted
_ = "_"


def solve(f):
    if _ in f:
        a = solve(f.replace(_, '+', 1))
        b = solve(f.replace(_, '-', 1))
        if a is not None:
            return a
        if b is not None:
            return b
    else:
        if eval(f) is 7:
            return f
        else:
            return None


s = _.join(input())
print(solve(s) + '=7')
# Judge status: Accepted
N = int(input())
result = []

for A in range(1, N):
    B = N - A
    A = str(A)
    B = str(B)
    A_sum = sum(list(map(int, A)))
    B_sum = sum(list(map(int, B)))
    result.append(A_sum + B_sum)

print(min(result))
# Judge status: Accepted
s=int(input())
n=set()
a=s
for i in range(10**7):
    if a in n:
        break
    
    if a%2==0:
        n.add(a)
        a=a//2
    else:
        n.add(a)
        a=3*a+1

print(i+1)
# Judge status: Accepted
N=int(input())
count=0
for i in range(1,10):
  for m in range(1,10):
    if i*m==N:
      count+=1
if count>=1:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
x, y = map(int, input().split())

if (x + y)%3 != 0:
    print(0)
    exit()

diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1

for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = pow((i + 1), (mod - 2))%mod
    ans = ans*ie%mod

print(ans)
# Judge status: Accepted
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: Accepted
s = input()
if s[0]=='9' or s[1]=='9': print('Yes')
else: print('No')
# Judge status: Wrong Answer
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline().rstrip

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

ans = ":(" if A > 9 or B > 9 else "Yay!"
print(ans)
# Judge status: Wrong Answer
SUM = 0
N = [int(j) for  j in input().split(' ')]
LIST = [j for j in range(N[0],N[1]+1)]

for i in range(1,len(LIST)):
    if SUM == 0:
        SUM = LIST[i-1] * LIST[i]
    else:
        SUM *= LIST[i]
if SUM < 0:
    print("Negative")
elif SUM > 0:
    print("Positive")
else:
    print("Zero")
# Judge status: Accepted
S = input()
T = input()
ans = 'UNRESTORABLE'
for i in range(len(S)-len(T), -1, -1):
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            break
    else:
        ans = S[:i].replace('?', 'a')+T+S[i+len(T):].replace('?', 'a')
        break
print(ans)
# Judge status: Accepted
import math
a,b,n = map(int,input().split())
x = min(b-1,n)
print(math.floor(a*x/b) - a * math.floor(x/b))
# Judge status: Wrong Answer
n, x = map(int, input().split())
lis = list(map(int, input().split()))

ans = 10**9 + 7

for i in range(n):
    ans = min(ans, abs(x-lis[i]))

print(ans)
# Judge status: Accepted
import itertools

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

permutations = list(itertools.permutations(range(1,n+1)))
ps = permutations.index(p)
qs = permutations.index(q)

print(abs(ps-qs))
# Judge status: Wrong Answer
N, Y = map(int, input().split())
ans = False
for i in range(N+1):
  for j in range(N+1-i):
    k = N-i-j
    if 10000*i + 5000*j + 1000*k == Y:
      ans = True
      print(i, j, k)
    break
      
if ans == False:
  print(-1, -1, -1)
# Judge status: Wrong Answer
n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
import numpy as np
c = np.array(a)
count = 0
for i in b:
    if i > 10**5:
        j = sum(c>10**5)
        count += j
        break
    else:
        j = a.count(i)
        if j < i:
            count += j
        elif j == i:
            pass
        else:
            k = j - i
            count += k
print(count)
# Judge status: Accepted
word = input()
if word[len(word)-1] == 's':
	word += 'es'
else:
	word += 's'
print(word)
# Judge status: Accepted
x,m = map(int, input().split())
s=[-1]*m
c=[-1]*m
for i in range(m):
    s[i], c[i] = map(int, input().split())
if x ==1:
    start = 0
else:
    start = 10**(x-1)

for j in range(start, 1000):
    num = str(j)
    for k1, k2 in zip(s, c):
        if num[k1-1] != str(k2):
            break
    else:  #すべて一致したとき
        print(j)
        break
else:
    print(-1)
# Judge status: Wrong Answer
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
       
    return max(table)
N=int(input())
ans=0
li=[i for i in range(1,N+1)]
for i in range(1,N+1):
  ans+=num_divisors_table(i)*i
print(ans)
# Judge status: Accepted
x=int(input())
if x==1:
    print(1)
    exit()

i=2
ans=0
while i*i<x:
    j=2
    while i**j<=x:
        ans=max(ans,i**j)
        j +=1
    i += 1
print(ans)
# Judge status: Accepted
N,M=list(map(int, input().split()))
A=[list(input()) for _ in range(N)]
B=[list(input()) for _ in range(M)]
K=N-M+1

for i in range(K):
  for j in range(K):
    # print(i,i+M,j,j+M)
    if all(all(A[k+i][l+j] == B[k][l] for l in range(M)) for k in range(M)):
      print('Yes')
      exit()
else:
  print('No')
# Judge status: Accepted
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc160/tasks/abc160_c

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

dist = []
for i in range(N-1):
    dist.append(A[i+1] - A[i])
dist.append(K - A[-1] + A[0])

print(K - max(dist))
# Judge status: Wrong Answer
import itertools
n = int(input())
lst = []

for _ in range(n):
  l = list(map(int, input().split()))
  lst.append(l)
  
hp = [[0] * 3 for _ in range(n)]

plst = list(itertools.permutations([_ for _ in range(3)], 2))

for _ in range(0, n):
    for i in plst:
      hp[_][i[1]] = max(hp[_-1][i[0]] + lst[_][i[1]],hp[_][i[1]])

print(max(hp[n-1]))
# Judge status: Wrong Answer
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
for i in range(1,size):
	dp[i] = min(
	dp[i-1] + abs(array[i] - array[i-1]),
	dp[i-2] ,abs( array[i] - array[i-2] )
	)
print(dp[-1])
# Judge status: Wrong Answer
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx-sx, ty-sy
ans = []
for _ in range(dy):
    ans.append('U')
for _ in range(dx):
    ans.append('R')
for _ in range(dy):
    ans.append('D')
for _ in range(dx):
    ans.append('L')
ans.append('L')
for _ in range(dy+1):
    ans.append('U')
for _ in range(dx+1):
    ans.append('R')
ans.append('D')
ans.append('R')
for _ in range(dy+1):
    ans.append('D')
for _ in range(dx+1):
    ans.append('L')
ans.append('U')
# Judge status: Accepted
#-----------------------------
#https://atcoder.jp/contests/agc008/submissions/15248942
import sys
 
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
#-----------------------------
R,G,B = inm()
K = ini()
X = 0
while R >= G:
    X += 1
    G *= 2

while G >= B:
    X += 1
    B *= 2

if X <= K:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
# import sys;input = lambda : sys.stdin.readline()
s = input()
A, Z = None, None
for i in range(len(s)):
    if s[i] == "A":
        A = i
        break
for i in range(len(s) - 1, -1, -1):
    if s[i] == "Z":
        Z = i
        break
print(Z - A + 1)
# Judge status: Wrong Answer
W,H,x,y=map(int,input().split())
size1 = min((x*H), ((W-x)*H))
size2 = min((W*y), (W*(H-y)))
count = 0
if size1 == size2:
  count += 1
print(max(size1, size2), count)
# Judge status: Accepted
from collections import Counter
a=int(input())
l=list(map(int,input().split()))
b=int(input())
s=Counter(l)
initial_sum=sum(l)

for _ in range(b):
  x,y=map(int,input().split())
  k=s[x]
  s[x]=0
  s[y]+=k
  initial_sum+=(y-x)*k
  print(initial_sum)
# Judge status: Accepted
import sys

s = input()
t = input()
ls = len(s)
lt = len(t)

ans = lt
for i in range(ls -lt + 1):
  tmp = lt
  for j in range(lt):
    if s[i + j] == t[j]:
      tmp -= 1
  ans = min(ans, tmp)
  if ans == 0:
    print(0)
    sys.exit()
  
print(ans)
# Judge status: Accepted
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, d = Input()
    d = 2 * d + 1
    return (n+d-1)//(d)

print(main())
# Judge status: Accepted
s = list(input())
t = s[::-1]
n = len(s)
if s != t:
  print ('No')
  exit()
if n == 3:
  print('Yes')
  exit()
d = s[:int((n-1)/2)]
e = d[::-1]
#print(d,e)
r = s[int((n+3)/2-1):]
q = r[::-1]
#print(r,q)
if d != e:
  print('No')
  exit()
if r != q:
  print ('No')
  exit()
  
print('Yes')
# Judge status: Wrong Answer
a,b = map(str, input().split())
c,d = map(int, input().split())
e = input()
if a == e:
  c -= 1
else:
  d -= 1
print(a,b)
# Judge status: Accepted
n,m = map(int,input().split())
if n-m == 0:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = int(input())
a = [int(i) for i in input().split()]
b = []
sum_a = sum(a)
cum = 0
for i in a:
  cum += i
  b.append(sum_a - cum)
print(min(b))
# Judge status: Accepted
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(n):
  if i+1 != p[i]:
    count += 1

if count <= 2:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
L = list(map(int, input().split()))

ans1 = L[0]*L[1]*(L[2]//2-(L[2]-L[2]//2))
ans2 = L[0]*L[2]*(L[1]//2-(L[1]-L[1]//2))
ans3 = L[1]*L[2]*(L[0]//2-(L[0]-L[0]//2))
print(min(abs(ans1), abs(ans2), abs(ans3)))
# Judge status: Wrong Answer
N,K,S=map(int,input().split())
A=[1]*N
for i in range(K):
    A[i]=S
print(*A)
# Judge status: Accepted
import re

chr = input()


if re.match("[a-z]", chr):
    print("a") 
else:
    print("A")
# Judge status: Wrong Answer
s = input()

if s[2] == s[3] and s[4] == s[5]:
    print("yes")
else:
    print("no")
# Judge status: Wrong Answer
s = input()
k = int(input())
f = True
for si in s:
    if si != "1":
        print(si)
        f = False
        break
if f: print("1")
# Judge status: Accepted
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re


def main():
    S = input()
    T = input()

    S = S.replace("?", ".")[::-1]
    T = T[::-1]

    for i in range(len(S) - len(T) + 1):
        if re.match(S[i:i + len(T)], T):
            s = S[:i].replace(".", "a") + T + S[i + len(T):].replace(".", "a")
            print(s[::-1])
            break
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()
# Judge status: Accepted
print('YNEOS'[input()not in'357'::2])
# Judge status: Accepted
n, m = map(int, input().split())

if n == 2 or m == 2:
    ans = 0
elif n == 1 and m == 1:
    ans = 1
elif n == 1 or m == 1:
    ans = max(n, m) - 2
else:
    ans = (n - 2)*(m - 2)

print(ans)
# Judge status: Wrong Answer
a,b = map(int,input().split())
flag = 0
 
for i in range(a):
  for j in range(a):
    nokori = b - ((i * 1000) + (j * 5000))
    if nokori == 0 and (i+j) == a:
      k = 0
      flag = 1
      break
    elif nokori%10000 == 0 and nokori >= 0:
      k = int(nokori/10000)
      if (i+j+k)==a:
        flag = 1
        break
    
      
  if flag == 1:
    break
if flag == 1:
  print(k,j,i)
else:
  print("-1 -1 -1")
# Judge status: Wrong Answer
N,K=map(int, input().split())
ko = (N-K+1)*K+1
print('{:.0f}'.format(ko*(ko+1)/2))
# Judge status: Accepted
from collections import deque
s = [0,0,0]

sa = deque(list(input()))
sb = deque(list(input()))
sc = deque(list(input()))

now = sa.popleft()

if now == 'a':
	d = sa
if now == 'b':
	d = sb
if now == 'c':
	d = sc

while True:
	if len(d) == 0:
		ans = now
		break
	now = d.popleft()
	if now == 'a':
		d = sa
	if now == 'b':
		d = sb
	if now == 'c':
		d = sc

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

ans = 0
temp = 1000000000000

for i in range(n):
  if temp > abs(a*1000-1000*t+h[i]*6):
    temp = abs(a*1000-1000*t+h[i]*6)
    ans = i+1

print(ans)
# Judge status: Accepted
a,b = map(int,input().split())
if a>=b:
    ans = [str(n) for n in [b]*a]
    print("".join(ans))
else:
    ans = [str(n) for n in [a]*b]
    print("".join(ans))
# Judge status: Accepted
S = input()
mod_bucket = [0] * 2019
mod_bucket[0] = 1
 
_S = S[::-1]
mod = 0
p = 1
for i in range(len(S)):
    mod = (p * int(_S[i]) + mod) % 2019
    mod_bucket[mod] += 1
    p = p*10%2019

ans = sum([mod*(mod-1)/2 for mod in mod_bucket])
print(int(ans))
# Judge status: Accepted
import sys
input = sys.stdin.readline
N = int(input())
W = [input() for _ in range(N)]

before = [W[0]]
for i in range(1,N) :
    if W[i] in before :
        print("No")
        exit()
    if W[i-1][-2] != W[i][0] :
        print("No")
        exit()
    before.append(W[i])

print("Yes")
# Judge status: Wrong Answer
n, m = [int(i) for i in input().split()]
d = sorted({i[0]: i[1] for i in [[int(j) for j in input().split()] for k in range(n)]}.items(), key = lambda x:x[0])
sm = 0
i = 0
for i in d:
    if m > i[1]:
        sm += i[0] * i[1]
        m -= i[1]
    else:
        sm += i[0] * m
        break
print(sm)
# Judge status: Accepted
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    s = int(input())

    print([1, 0][s])

if __name__ == "__main__":
    resolve()
# Judge status: Accepted
S = input()
T = input()
if T[0:len(S)] == S:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n = int(input())
if n == 1:
  print('a')
elif n == 2:
  print('aa\nab')
elif n == 3:
  print('aaa\naab\naba\nabb\nabc')
elif n == 4:
  print('aaaa\naaab\naaba\naabb\naabc\nabaa\nabab\nabac\nabba\nabbb\nabbc\nabca\nabcb\nabcc\nabcd')
# Judge status: Wrong Answer
import itertools
n = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
tmp = list(itertools.permutations(range(1,n+1)))
tmp = sorted(tmp)
ans = []
for index,t in enumerate(tmp):
  if list(t) == P or list(t) == Q :
    ans.append(index)

if len(ans) ==1:
  print(*ans)
else:
  print(abs(ans[0]-ans[1]))
# Judge status: Wrong Answer
x=int(input())
a=x//11
b=x%11
while (a+1)*11<=x:
  a+=1
if b>6:
  print(2*a+2)
else:
  print(2*a+1)
# Judge status: Accepted
def main():
    x,a,b = map(int,input().split())
    now = b - a
    if now <= 0:
        print("delicious")
    elif now <= x:
        print("safe")
    else:
        print("dangerous")

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n=int(input())
c=n//500
if c!=0:
    n-=(c*500)
    k=n//5
    print(c*1000+k*5)
else:
    print(c*1000)
# Judge status: Accepted
#!/usr/bin/env python3

s = sorted(input())
t = sorted(input(), reverse=True)

ans = ""
for x,y in zip(s,t):
    if x > y:
        ans = "No"
        break
    elif y > x:
        ans = "Yes"
        break

if ans == "":
    if len(s) < len(t):
        ans = "Yes"
    else:
        ans = "No"

print(ans)
# Judge status: Wrong Answer
n, k = map(int,input().split())
x = []
for _ in range(n):
    a,b = map(int,input().split())
    x += [a]*b
print(x[k-1])
# Judge status: Accepted
S, C = map(int, input().split())

ans = min(S, C // 2)
S -= ans
C -= ans * 2
if C >= 4:
    ans += C // 4
print(ans)
# Judge status: Accepted
x=int(input())
a=int(x/100)
r=x-a*100
if r/5<=a:
    print(1)
else:
    print(0)
# Judge status: Wrong Answer
num = input()
list = list(map(int,input().split()))
list2 = set(list) 
print("No") if len(list) == len(list2) else print("Yes")
# Judge status: Wrong Answer
l, r = map(int, input().split())
l_2 = l%2019
r_2 = r%2019
ans = 2019
if r_2 - l_2 > 2017:
    print(0)
else:
    for i in range(l_2,r_2+1):
        for j in range(i+1,r_2+1):
            print(i,j)
            tmp = i*j%2019
            if tmp < ans:
                ans = tmp
    print(ans)
# Judge status: Wrong Answer
abc = input().split(" ")
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

d = 0
if a==b:
    d=d+1
if b==c:
    d=d+1
if c==a:
    d=d+1
if d==1:
    print("yes")
else:
    print("no")
# Judge status: Accepted
n, k = map(int, input().split())
h = list(map(int, input().split()))

h.sort(reverse=True)
h = h[k:]

print(sum(h))
# Judge status: Accepted
S=input()
x=int(S[:2])
y=int(S[2:])

if 0<x<13 and 0<y<13:print("AMBIGUOUS")
elif 0<x<13:print("MMYY")
elif 0<y<13:print("YYMM")
else:print("NA")
# Judge status: Wrong Answer
# AGC015a
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    n, a, b = map(int, input().split())
    if b-a < 0:
        print(0)
        exit(0)
    if n == 1:
        if b != a:
            print(0)
        else:
            print(1)
        exit(0)
    print((n-1)*(b-a)-1)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
nmx=list(map(int, input().split()))
N=nmx[0]
M=nmx[1]
X=nmx[2]
list=[input().split() for i in range(N)]
alist=[0]*M
for i in range(N):
    c=int(list[i][0])
    for j in range(1,M+1):
        a=int(list[i][j])
        alist[j-1]+=a
if min(alist)<X:
    print('-1')
else:
    for i in range(N):
        c=int(list[i][0])
        for j in range(1,M+1):
            a=int(list[i][j])
# Judge status: Accepted
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    d = defaultdict(int)
    for _ in range(N):
        a, b = map(int, readline().split())
        d[a] += b
    A = sorted(d.items(), key=lambda x:x[0])
    count = 0
    for key, value in A:
        count += value
        if count>=K:
            print(key)
            break
if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
count = 0
l = len(a)
z = 0
for i in b:
    if i > l:
        count = l-z
        break
    else:
        j = a.count(i)
        if j < i:
            count += j
            z += j
        else:
            count += j-i
            z += j
print(count)
# Judge status: Accepted
import sys
readline = sys.stdin.buffer.readline

def main():
    S = input()
    L = len(S)
    s = set(S)
    if L == len(s):
        ans = 'yes'
    else:
        ans = 'no'
    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Accepted
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def gcd(a, b):
  if a > b:
    a, b = b, a
  while b % a:
    a, b = b % a, a
  return a

def main():
  n = int(input())
  As = list(map(int, input().split()))
  As.sort()
  min = 10**9 + 1
  num = As[0]
  for A in As[1:]:
    num = gcd(num, A)
  print(num)
  
if __name__=='__main__':
  main()
# Judge status: Accepted
abcd=list(input())
enzanshi=[['+','-'],['+','-'],['+','-']]
for i in range(2**3):
  l=[]
  for j in range(3):
    if (i>>j)&1:
      l.append(enzanshi[j][0])
    else:
      l.append(enzanshi[j][1])


  keisan=""
  for i,j in zip(abcd,l+['']):
    keisan+=i+j

  if eval(keisan)==7:
    print(keisan + '=7')
    break
# Judge status: Accepted
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
if min(Y,min(y))-max(X,max(x))>=1:
    print("No War")
else:
    print("War")
# Judge status: Wrong Answer

a,b,k = map(int,input().split())
ans = []

if a < b:
    for i in range(1,a+1):
        if a % i == 0:
            ans.append(i)
else:
    for j in range(1,b+1):
        if b % j == 0:
            ans.append(j)

#print(ans)
print(ans[k-1])
# Judge status: Accepted
#70 C - Five Transportations
N = int(input())
lis = [int(input()) for _ in range(5)]
mini = min(lis)
group = (N+mini-1)//mini

ans = 5 + group - 1
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)
B.append(0)
ans = 0
for i in range(len(A)-1):
    a = A[i]
    b = B[i]
    if a > b:
        ans += b
    else:
        ans += a
        if A[i + 1] >= b - a:
            ans += b - a
            A[i + 1] -= b - a
        else:
            ans += A[i + 1]
            A[i + 1] = 0
print(ans)
# Judge status: Accepted
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
ans = ""
for c in s:
    ans += chr((ord(c)+n-ord("A"))%26 + ord("A"))
print(ans)
# Judge status: Accepted
N = int(input())
print((1000 - N%1000) % 1000)
# Judge status: Accepted
#-*- coding: utf-8 -*-
import numpy as np

N, D = map(int, input().split())
X=[]
Y=[]
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

x=np.array(X)
y=np.array(Y)
distance_calc=(x**2+y**2)**0.5
cnt=0
for i in range(len(distance_calc)):
    if distance_calc[i]<=D:
        cnt+=1
print(cnt)
# Judge status: Accepted
import sys
input = sys.stdin.readline
s = input()

chrs = [chr(i) for i in range(97, 97+26)]

for i in chrs:
  if i not in s:
    print(i)
    exit()
print("None")
# Judge status: Wrong Answer
import numpy as np
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())
#print(A)
D=[0]*10**5;W=[0]*10**5
for i in range(10**5):
  D[i]=A.count(i+1)
  W[i]=i+1

for i in range(Q):
    D[C[i]-1]+=D[B[i]-1]
    D[B[i]-1]=0
    print(int(np.average(D, weights=W)*10**5*(10**5+1)//2))
# Judge status: Accepted
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    x,y=map(int,input().split())
    cnt=0
    while True:
        x*=2
        cnt+=1
        if x>y:
            break
    print(cnt)

    
resolve()
# Judge status: Wrong Answer
S = input()
l = []

for i in range(len(S) - 2):
    a = S[i] + S[i + 1] + S[i + 2]
    l.append(a)
ans = int(l[0])
for j in l:
    ans = min(ans, abs(int(j) - 753))
print(ans)
# Judge status: Accepted
s=input()
a=s.count('a')
b=s.count('b')
c=s.count('c')
print('YES' if abs(a-b)<2 and abs(a-c)<2 and abs(c-b)<2 else 'NO')
# Judge status: Wrong Answer
a,b = map(int, input().split())

if a<5:
    print(0)
elif a>=6 & a<13:
    print(int(b/2))
else:
    print(int(b))
# Judge status: Wrong Answer
n,a,b = map(int,input().split())
print((a)*n//(a+b) + min(n%(a+b),a))
# Judge status: Wrong Answer
s = input().rstrip()
print('x' * len(s))
# Judge status: Wrong Answer
t= list(input())

for i in range(1, len(t)):
  if i == len(t)-1 and t[i] == '?':
    t[i] == 'D'
  if t[i-1] == 'P' and t[i] == '?':
    t[i] = 'D'
  elif t[i] == '?' and t[i-1] == 'D':
    t[i] = 'P'
    
print(''.join(t))
# Judge status: Wrong Answer
a, b = map(int, input().split())
print([':(', 'Yay!'][int((a <= 16) & (b <= 8))])
# Judge status: Wrong Answer
a = list(map(int, input().split()))
p = list(map(int, input().split()))

N = a[0]
K = a[1]

p.sort()

g = sum(p[0:K-1])
print(g)
# Judge status: Accepted
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())
    t = A[x - 1] + B[y - 1] - c
    if t < ans:
        ans = t

print(ans)
# Judge status: Accepted
S = list(input())
pr = 'X'
ans = 'Good'
for s in S:
    if pr == s:
        ans = 'Bad'
        break
    pr = s
print(ans)