peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
X, Y, A, B, C = map(int, input().split())
p_A = list(map(int, input().split()))
q_B = list(map(int, input().split()))
r_C = list(map(int, input().split()))
p_A2 = sorted(p_A, reverse=True)
q_B2 = sorted(q_B, reverse=True)
r_C2 = sorted(r_C, reverse=True)

ans = []
ans += p_A2[:X]
ans += q_B2[:Y]
ans = sorted(ans)

cnt = 0
for i in range(len(ans)):
    if cnt <= C-1:
        if ans[i] < r_C2[cnt]:
            ans[i] = r_C2[cnt]
            cnt += 1
print(sum(ans))
# Judge status: Accepted
H1, M1, H2, M2, K = map(int, input().split())
Stayup_Time = (H2 * 60 + M2) - (H1 * 60 + M1)
Notstudy_Time = Stayup_Time - K
print(Notstudy_Time)
# Judge status: Accepted
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

AB.sort()

money = 0
for a, b in AB:
  if M > b:
    money += a * b
    M -= b
  else:
    money += a * M
    break
    
print(money)
# Judge status: Wrong Answer
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

gaps = [x[i] - x[i-1] for i in range(1, len(x))]

if n == 1:
    print(sum(gaps) - 1)
else:
    print(sum(sorted(gaps)[:-n+1]))
# Judge status: Accepted
N = int(input())
dic = {"AC":0,"WA":0,"TLE":0,"RE":0}

for i in range(N):
    s = input()
    dic[s] += 1
    

for k, v in dic.items():
    print(k+" x "+str(v))
# Judge status: Accepted
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
sa = "".join(s)
ta = "".join(t)

ans = "No"
l = [sa, ta]
l.sort()
if l[1] == ta:
    ans = "Yes"
if l[0] == l[1]:
    ans = "No"
print(ans)
# Judge status: Accepted
S,W = input().split()

if int(W) >= int(S):
    print("unsafe")
else:
    print("safe")
# Judge status: Accepted
n,r=map(int,input().split())
print(r if n>=10 else r+100*(10-n))
# Judge status: Accepted
def main():
    S = str(input())
    T = str(input())
    counter = 0
    max_match = 0

    if T in S:
        print(0)
    else:
        for i in range(len(T), len(S)+1):
            counter = 0
            for j in range(len(T)):
                if S[i-len(T)+j] == T[j]:
                    counter += 1
            if max_match < counter:
                max_match = counter
        print(len(T)-max_match)
main()
# Judge status: Accepted
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
C = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    check = 0
    point = abs(A[i][0]-C[0][0])+abs(A[i][1]-C[0][1])
    change = point
    for j in range(1,M):
        point = min(point,abs(A[i][0]-C[j][0])+abs(A[i][1]-C[j][1]))
        if point != change:
            check = j
            change = point
    print(check+1)
# Judge status: Wrong Answer
str = input()
print("'" +  str + "'の次は'" + chr(ord(str) + 1) + "'です。")
# Judge status: Wrong Answer
arr = input()
if not 'B' in arr:
    print(arr)
else:
    arr = ''.join(reversed(arr))
    print(arr[:arr.index('B')])
# Judge status: Accepted
N,x=map(int,input().split())
a=[int(x) for x in input().split()]
cnt=0
if a[0]>x:
    cnt += a[0] - x
    a[0]=x 
for i in range(N-1):
    if a[i]+a[i+1] >x:
        cnt += a[i] + a[i+1] - x
        a[i+1]=x-a[i]
print(cnt)
# Judge status: Accepted
S = str(input())
A = "es"
B = "s"
if S[-1] == B:
  print(S+A)
else:
  print(S+B)
# Judge status: Accepted
from heapq import heappop,heappush
N = int(input())
A = list(map(lambda x: -1*int(x),input().split()))

now = -1 * heappop(A)
while(A):
    next = -1 * heappop(A)
    if now % next != 0:
        heappush(A,-1*(now%next))
    now = next
print(now)
# Judge status: Accepted
N,P = map(int,input().split())
A = list(map(int,input().split()))
ans = [1,0]
for a in A:
    if a%2:
        ans[1],ans[0] = ans[1] + ans[0], ans[1] + ans[0]
    else:
        ans[0] = ans[0]*2
        ans[1] = ans[1]*2
print(ans[P])
# Judge status: Accepted
N,K=map(int,input().split())
H=list(map(int, input().split()))
if N<=K:
    print("0")
else:
    H.sort()
    count=sum(H[0:N-K])
    print(count)
# Judge status: Wrong Answer
import math
a,b,c,d=map(int,input().split())
lcm_cd=c*d/math.gcd(c,d)
c_times=b//c-(a-1)//c
d_times=b//d-(a-1)//d
cd_times=b//lcm_cd-(a-1)//lcm_cd
print(int(b-a+1-c_times-d_times+cd_times))
# Judge status: Accepted
m=int(input())//2-1
x=list(map(int,input().split()))
l,r=sorted(x)[m:m+2]
for i in x: print([l,r][i<r])
# Judge status: Accepted
n = int(input())
city = []
nums = []
result = []

for i in range(n):
  s,p = input().split()
  p = int(p)
  city.append(s)
  nums.append(p)
  result.append([s,p,i+1])

for i in sorted(set(city)):
  for j in sorted(set(nums), reverse = True):
    for k in result:
      if k[0] == i and k[1] == j:
        print(k[2])
# Judge status: Accepted
import math
A, B = map(int, input().split())

num = math.ceil(25 / 2 * A)
A_list = []

if A % 2 == 0:
  while num <= math.floor(25 / 2 * (A + 1)):
    A_list.append(num)
    num += 1
else:
  while num < 25 / 2 * (A + 1):
    A_list.append(num)
    num += 1

res = -1
A_list.sort(reverse=True)
for item in A_list:
  if item >= 10 * B and item < 10 * (B + 1):
    res = item

print(res)
# Judge status: Accepted
s = list(input())
t = list(input())
s.sort()
t.sort()
t = t[::-1]

if ''.join(s) < ''.join(t):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import bisect
N =int(input())
lisA =list(map(int,input().split()))
lisB = list(map(int,input().split()))
lisC = list(map(int,input().split()))

lisA.sort()
lisB.sort()
lisC.sort()
cnt = 0

for b in lisB:
    cnt += bisect.bisect_left(lisA,b)*(N-bisect.bisect_right(lisC,b))

print(cnt)
# Judge status: Accepted
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
for i in range(N-K):
    if T[K+i]==T[i]:
        T[K+i]=""
ans=T.count("r")*P+T.count("s")*R+T.count("p")*S
print(ans)
# Judge status: Accepted
from math import gcd


def solve():

    K = int(input())

    rangeK = range(1, K+1)
    ans = 0

    for a in rangeK:
        for b in rangeK:
            for c in rangeK:
                ans += gcd(gcd(a, b), c)

    print(ans)


if __name__ == "__main__":
    solve()
# Judge status: Accepted
from itertools import product

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
se = set(range(10))
for a in A:
    se ^= set([a])

def check(str_num):
    for x in str_num:
        if not int(x) in se:
            return False
    return True

while True:
    if check(str(N)):
        break
    N += 1
print(N)
# Judge status: Accepted
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k < 0:
            break
        if 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            exit()
print(-1, -1, -1)
# Judge status: Accepted
a,b,c,d = [int(x) for x in input().split()]

if (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
x,n=map(int,input().split())

if n==0:
    print(x)
else:
    p=list(map(int,input().split()))
    min=1000000000000000
    ans=0
    for i in range(102):
        if i not in p and abs(x-i) < min:
            min = abs(x-i)
            ans = i
    print(ans)
# Judge status: Accepted
s = input()
a = ""
for S in s:
    if S == 'B':
        if a:
            a = a[:-1]
        else:
            continue
    else:
        a += S
print(a)
# Judge status: Accepted
x,y=map(int,input().split())
x,y=1,y//x
cnt=0
while x<=y:
  x*=2
  cnt+=1
print(cnt)
# Judge status: Accepted
n=int(input())
lists=list(map(int,input().split()))
uselists=[]
for _ in range(n):
    uselists.append(lists[_]-_-1)
uselist=sorted(uselists)
if n%2==0:
    num1=int(n/2-1)
    num2=int(n/2)
    numbers=min(uselist[num1],uselist[num2])
    
if n%2!=0:
    num1=int((n-1)/2)
    numbers=uselist[num1] 
ans=0
for x in range(n):
    ans+=abs(uselist[x]-numbers)
print(ans)
# Judge status: Accepted
n = int(input())
v = list(map(int, input().split()))

v.sort()

tmp = v[0]
for i in range(n-1):
    tmp = (tmp+v[i+1]) / 2
print(tmp)
# Judge status: Wrong Answer
from bisect import bisect_left
import heapq

def solve():
    N,M = map(int, input().split())
    cities_in_prefecture = [[] for _ in range(N)]
    city_ids = []
    for _ in range(M):
        P,Y = map(int, input().split())
        x = bisect_left(cities_in_prefecture[P-1], Y)
        heapq.heappush(cities_in_prefecture[P-1], Y)
        print('{0:06d}{1:06d}'.format(P, x+1), flush=True)
        
solve()
# Judge status: Wrong Answer
S = list(input())
for i in range(0,len(S),2):
  if S[i] == 'L':
    print('No')
    exit()
for j in range(1,len(S),2):
  if S[j] == 'R':
    print('NO')
    exit()
print('Yes')
# Judge status: Wrong Answer
x = int(input())
if 400 <= x < 599:
    print(8)
elif 600 <= x < 799:
    print(7)
elif 800 <= x < 999:
    print(6)
elif 100 <= x < 1199:
    print(5)
elif 1200 <= x < 1399:
    print(4)
elif 1400 <= x < 1599:
    print(3)
elif 1600 <= x < 1799:
    print(2)
elif 1800 <= x < 1999:
    print(1)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
sx,sy,tx,ty=map(int,input().split())
ans=""
for i in range(ty-sy):
    ans+="U"
for i in range(tx-sy):
    ans+="R"
for i in range(ty-sy):
    ans+="D"
for i in range(tx-sy):
    ans+="L"
ans+="L"
for i in range(ty-sy+1):
    ans+="U"
for i in range(tx-sy+1):
    ans+="R"
ans+="DR"
for i in range(ty-sy+1):
    ans+="D"
for i in range(tx-sy+1):
    ans+="L"
ans+="U"
print(ans)
# Judge status: Accepted
# coding: utf-8

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 0
    tmp = 0
    total = sum(A)
    for a in A:
        tmp += a
        if tmp >= total // 2:
            ans = min(2 * tmp - total, total - 2 * (tmp - a))
            break

    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
n,k=map(int,input().split())
s=input()

happy=0
unhappy=0
for i in range(1,n):
  if s[i]==s[i-1]:
    happy+=1
  else:
    unhappy+=1

for i in range(k):
  if unhappy==1:
    unhappy-=1
    happy+=1
    break
  unhappy-=2
  happy+=2

print(min(happy,n-1))
# Judge status: Wrong Answer
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

c = [[0 for _ in range(B)] for _ in range(A)]
for _ in range(M):
    x, y, cp = map(int,input().split())
    c[x-1][y-1] = cp

oldp = 10**20
for an in range(A):
    for bn in range(B):
        if c[an][bn] == 0: continue
        p = a[an]+b[bn]-c[an][bn]
        if oldp > p:
            oldp = p

p = min(a)+min(b)
print(min(oldp,p))
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
for i, j in zip(a, b):
    if i < j:
        cnt += (j - i) // 2 + (j - i) % 2
sa = sum(b) - sum(a)
if cnt <= sa:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
p = int(input())
print((p/3)**3)
# Judge status: Accepted
def framod(x,p=10**9+7):
  a=1
  for i in range(1,x+1):
    a = (a*i)%p
  return a
#############################################
X,Y=map(int,input().split())
p=10**9+7

if (X+Y)%3!=0:
  print(0)
else:
  a = (2*X-Y)//3
  b = (2*Y-X)//3
  t = a+b
  if a<0 or b<0:
    print(0)
  else:
    S=framod(t)
    T=pow(framod(a),p-2,p)
    U=pow(framod(b),p-2,p)
    print(((S*T)%p)*U%p)
# Judge status: Accepted
S = input()
T = input()
 
if(S==T[:len(S)]):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
A, B, C, D = map(int, input().split())

if A<C:
  if B-C < 0:
    print(0)
  else:
    if D-B < 0:
      x = B-D
    else:
      x = 0
    print(B-C-x)
else:
  if D-A < 0:
    print(0)
  else:
    if B-D < 0:
      x = D-B
    else:
      x = 0
    print(D-A-x)
# Judge status: Accepted
n = int(input())
l = list(map(int,input().split()))
l1=sorted(l)
a = l1[n//2-1]
b = l1[n//2]
if a == b:
  for i in range(n):
    print(a)
else:
  for i in l:
    if i <= a:
      print(b)
    else:
      print(a)
# Judge status: Accepted
import numpy as np
from itertools import product
n, m, x = [int(x) for x in input().split()]
a = np.stack([np.array(input().split(), dtype=int) for _ in range(n)])
tot = np.sum(a, axis=0)
if min(tot[1:]) < x:
    print(-1)
    exit(0)
cost = tot[0]
whole = np.array(list(product([0,1],repeat=n)), dtype=bool)[1:-1]
for flag in whole:
    sel = a[flag]
    tot = np.sum(a[flag], axis=0)
    if min(tot[1:]) >= x and tot[0] < cost:
        cost = tot[0]
print(cost)
# Judge status: Accepted
s = input()
q = int(input())
x = 1
f, b = '', ''
for i in range(q):
  a = input().split()
  if a[0] == '1':
    x = -x
  elif (1.5-int(a[1]))*x > 0:
    f = a[2] + f
  else:
    b = b + a[2]
s = f + s + b
if x == -1:
  s = s[::-1]
print(s)
# Judge status: Accepted
A,B,C = map(int,input().split(" "))
if A == B and A != C and B!=C:
    print("Yes")
elif  A== C and A != B and B!=C:
    print("Yes")
elif  B== C and A != B and A!=C:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n,m=map(int,input().split())

candidate = []
for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        candidate.append(b)
    if b==n:
        if a in candidate:
            print('POSSIBLE')
            exit()
print('IMPOSSIBLE')
# Judge status: Wrong Answer
n,k=map(int,input().split())
P=list(map(int,input().split()))

dp=[0]*n
ans=0
for i in range(n):
  dp[i]=((1/2)*P[i]*(P[i]+1)) / P[i]
  if i>k:
    ans=max(ans,sum(dp[i-k:i]))
print(ans)
# Judge status: Wrong Answer
import numpy

e=input().split()
for i in range(len(e)):
  e[i]=int(e[i])
x=e[0]
k=e[1]
d=e[2]
t=k
if k>1000:
 if k%2==0:
   t=1000
 else:
   t=1001
kou=numpy.gcd(x,d)
x=int(x/kou)
d=int(d/kou)
if d>100 and d%2==0:
  d=100
if d>100 and d%2==1:
  d=1001
for i in range(t):
  if abs(x+d)<abs(x-d):
    x+=d
  else:
    x-=d
print(abs(x)*kou)
# Judge status: Accepted
A,B,C=map(int,input().split())
if C-(A-B)<=0:
    print(0)
else:
    print(C-(A-B))
# Judge status: Accepted
n = int(input())
ans = ''
while n:
  ans = chr((n-1)%26+ord('a')) + ans
  if n % 26 == 0:
    n = n//26-1
  else:
    n = n//26
print(ans)
# Judge status: Accepted
X,N = map(int,input().split())
if N == 0:
    print(X)
else:
    L = list(map(int,input().split()))
    for i in range(100):
        if X - i not in L:
            print(X-i)
            break
        elif X + i not in L:
            print(X+i)
            break
# Judge status: Wrong Answer
# coding: utf-8
# Your code here!
n=int(input())
flag=0
for i in range(1,10):
    if n%i==0:
        flag=1
if flag:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a, b, k = map(int, input().split())
ans = set()
for i in range(a, min(b, a+k)):
  print(i)
for i in range(max(b-k+1, a+k), b+1):
  print(i)
# Judge status: Accepted
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
dp = [[0]*3 for i in range(n+1)]

for i in range(n):
    dp[i+1][0] = max(dp[i][1],dp[i][2])+l[i][0]
    dp[i+1][1] = max(dp[i][0],dp[i][2])+l[i][1]
    dp[i+1][2] = max(dp[i][1],dp[i][0])+l[i][2]
    
print(max(dp[n]))
# Judge status: Accepted
n = int(input())
c = list(input())
r = c.count('R')
w = c.count('W')
ans = 0

for i in range(r):
    if c[i] == 'R':
        pass
    elif c[i] == 'W':
        ans += 1
print(ans)
# Judge status: Accepted
N = int(input())
S = input()

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ans = ""
for i in range(len(S)):
  idx = alphabet.find(S[i])
  idy = (idx + N) % 26
  ans += alphabet[idy]
  
print(ans)
# Judge status: Wrong Answer
s,c = map(int,input().split())
ans = 0
if s*2 <= c:
    c = c - s*2
    ans += s
    s = 0
else:
    tmp = c//2
    s = s - tmp
    c = c%2
    ans += tmp
#print(s,c,ans)
ans += c//4
#print(s,c,ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))

dic = {}

ans = 0
for i in range(n):
    if i+1-a[i] in dic:
        ans += dic[i+1-a[i]]
    
    if a[i]+(i+1) in dic:
        dic[(i+1)+a[i]] = dic[(i+1)+a[i]] + 1
    else:
        dic[(i+1)+a[i]] = 1
        
print(ans)
# Judge status: Accepted
def main():
    a, b, x = map(int, input().split())
    print('YES' if a <= x and a + b >= x else 'NO')


if __name__ == '__main__':
    main()
# Judge status: Accepted
from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
S = 0
for k, v in A.items():
  if k<v:
    S += (v-k)
  elif k>v:
    S += v
print(S)
# Judge status: Accepted
X,Y=map(int,input().split())
ans = 0
num = X
while num <= Y:
    num *= 2
    ans += 1
print(ans)
# Judge status: Accepted
a=input()
n=len(a)
if a[n-1]=='2'or a[n-1]=='4'or a[n-1]=='5'or a[n-1]=='7'or a[n-1]=='9':
  print("hon")
elif a[n-1]=='0'or a[n-1]=='1'or a[n-1]=='6'or a[n-1]=='8':
  print("pon")
else:
  print("bon")
# Judge status: Wrong Answer
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().split()]
B = [int(x) for x in readline().split()]

Acum = list(itertools.accumulate(A))
Bcum = list(itertools.accumulate(B))

ans = 0
for i in range(N):
    if i - 1 > 0:
        ans = max(ans, Acum[i] + Bcum[-1] - Bcum[i - 1])
    else:
        ans = max(ans, Acum[i] + Bcum[-1])
print(ans)
# Judge status: Wrong Answer
N, M = map(int, input().split())
AC = set()
WA = set()
for i in range(M):
    p, S = input().split()
    p = int(p) - 1
    S = S == 'AC'
    if S:
        AC.add(p)
    else:
        WA.add(p)
print(len(AC), len(AC & WA))
# Judge status: Wrong Answer
import math
x,y=map(int,input().split())
print(math.ceil(math.log2(y/x)))
# Judge status: Accepted
S = list(input())

ans = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:

        ans += 1

        if S[i+1] == "1":
            S[i+1] = "0"

        else:
            S[i+1] = "1"

print(ans)
# Judge status: Accepted
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

if abs(a-b) <= (v-w)*t:
	print('YES')
else:
	print('NO')
# Judge status: Accepted
A = sorted(list(map(int, input().split())))
print(A[0]+A[1])
# Judge status: Accepted
X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
r = sorted([int(x) for x in input().split()], reverse=True)[:X + Y]

s = sorted(p + q + r, reverse=True)

ans = sum(s[:X + Y])

print(ans)
# Judge status: Accepted
S, T = input(), input()
ma, ima = {}, {}
ok = True
for i in range(len(S)):
    s, t = S[i], T[i]
    if s in ma and ma[s] != t:
        ok = False
    if t in ima and ima[t] != s:
        ok = False
    ma[s] = t
    ima[t] = s
if ok:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
X = int(input())
a = X//200
print(10-a)
# Judge status: Wrong Answer
N = int(input())
print(N//10+N//50)
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
x=1
for a in A:
    if a==x:
        x+=1
    else:
        pass
if x==1:
    print(-1)
else:
    print(N-x+1)
# Judge status: Wrong Answer
a = int(input())
ans = a%10 + int(a/10)%10 + int(int(a/10))%10
print(ans)
# Judge status: Accepted
s = input()
cnt = 0
for i in s:
  if i == '1':
    cnt += 1
print(cnt)
# Judge status: Accepted
n,k = map(int,input().split())
prob = 0
point = 0
for cube in range(1,n+1):
    if cube <= k-1:
        point = cube
        t = 0
        while True:
            point = point*2
            t += 1
            if point >= k:
                break
        prob += 1/n * ((1/2)**t)
    else:
        prob += 1/n
print(prob)
# Judge status: Accepted
N,A,B,C,D = map(int,input().split())
S = list(input())
S.append('.')
A -=1
B -=1
C -=1
D -=1

if C > D:
  if '##' not in ''.join(S[A+1:C]) and '##' not in ''.join(S[B+1:D]) and '...' in ''.join(S[B-1:D+2]):
    print('Yes')
  else:
    print('No')
else:
  if '##' not in ''.join(S[A+1:C]) and '##' not in ''.join(S[B+1:D]):
    print('Yes')
  else:
    print('No')
# Judge status: Accepted
x = input()
y = input()
print('YES' if x==y[::-1] else 'NO')
# Judge status: Accepted
def main():
    X, N = map(int, input().split())
    P = set(list(map(int, input().split())))

    d, v = X, 0
    for i in range(102):
        if i in P:
            continue
        if abs(i - X) < d:
            d = abs(i - X)
            v = i
    return v


print(main())
# Judge status: Accepted
[n,m] = [int(x) for x in input().split()]

if n == m:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N = int(input())
A = [int(input()) for i in range(N)]

ans = 0
part_sum = 0
for i in range(N):
    if A[i] == 0 or i == N-1:
        part_sum += A[i]
        ans += (part_sum // 2)
        part_sum = 0
    else:
        part_sum += A[i]

print(ans)
# Judge status: Accepted
from collections import Counter
 
n = int(input())
s = input()
try:
  x, y, z = Counter(s).values()
  print(x * y * z - sum(s[i] != s[(i + j) // 2] != s[j] != s[i]
                        for i in range(n) for j in range(i + 2, n, 2)))
except ValueError:
  print(0)
# Judge status: Accepted
def boxes():
    N, x = input().split()
    N, x = int(N), int(x)
    arr = [int(a) for a in input().split()]

    total = 0
    for i in range(1, N):
        a, b = arr[i-1], arr[i]
        extra = a + b - x
        if extra > 0:
            total += extra
            if b >= extra:
                arr[i] -= extra
            else:
                arr[i] = 0
    print(total)
boxes()
# Judge status: Accepted
#!/usr/bin/env python3

S = list(input())

A = [S[0]]
prev = ""
for x in S[1:]:
    if prev != "":
        A.append(prev+x)
        prev = ""
    elif A[-1] == x:
        prev = x
    else:
        A.append(x)

print(len(A))
# Judge status: Accepted
N = int(input())
print(N*800-(N//15)*200)
# Judge status: Accepted
a,b,c=map(int,input().split())
print(max(0,c-a+b))
# Judge status: Accepted
N=int(input())
if N<10:
    print(N)
    exit()
if N<100:
    print(9)
    exit()
if N<1000:
    print(9+N-100+1)
    exit()
if N<10000:
    print(909)
    exit()
if N<100000:
    print(909+N-10000+1)
    exit()
if N==100000:
    print(90909)
    exit()
# Judge status: Accepted
AB, BC, CA = [int(i) for i in input().split()]

S = (AB * BC) // 2

print(S)
# Judge status: Accepted
def resolve():
    n, k, q = map(int, input().split())
    points = [k] * n
    for _ in range(q):
        temp = int(input())
        points[temp - 1] += 1
    points = map(lambda x: x - q, points)
    for i in points:
        if i <= 0:
            print('No')
            continue
        print('Yes')
resolve()
# Judge status: Accepted
a, b, x = map(int, input().split())
if a<= x <= a+b:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
S, W = map(int, input().split())

if S <= W:
    print("unsafe")
else:
    print("safe")
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
hidariwa = sum(a)
migiwa = 0
answer = hidariwa
for i in range(n):
  hidariwa -= a[i]
  migiwa +=a[i]
  answer = min(abs(hidariwa-migiwa),answer)
print(answer)
# Judge status: Wrong Answer
N, M = map(int, (input().split()))
ans = N * (N - 1) / 2 + M * (M - 1) / 2
print(ans)
# Judge status: Accepted
import collections
N = int(input())
s = ["".join(sorted(input())) for i in range(N)]

ans = 0
cnt = collections.Counter(s)
for i in cnt.values():
    if i > 1:
        ans += i*(i-1)//2

print(ans)
# Judge status: Accepted
x,y=map(int,input().split())
num=x
ans=1
while num<=y:
  num=num*2
  if (num<=y):
    ans+=1
    
print(ans)
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
mod = 10**9+7
ans = 1
for i in range(1, N+1):
    ans *= i
    ans %= mod
print(ans)
# Judge status: Accepted
N = int(input())

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

cnt = 0
mode = 0

for i in range(len(A)):
    if i == 0:
        continue
    
    if (A[i] - A[i-1] >= 0 and mode >=0) or (A[i] - A[i-1] <= 0 and mode <= 0):
        if A[i] - A[i-1] > 0:
            mode = 1
        if A[i] - A[i-1] < 0:
            mode = -1
    else:
        mode = 0
        cnt += 1

print(cnt+1)