CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = [int(s) for s in input().split()]
b = a.copy()
max_index = a.index(max(a))
count = 0
last_index = len(a)
while(last_index > 0):
    b[max_index: last_index] = [a[max_index]] * (last_index - max_index)
    last_index = max_index
    
    if last_index == 0 or len(set(a[:last_index])) <= 1:
        break
    max_index = a.index(max(a[:last_index]))

for i in range(len(a)):
    count += b[i] - a[i]
print(count)

# Optimized solution
n = int(eval(input()))
a = [int(s) for s in input().split()]
count = 0
max = a[0]
for i in range(1, len(a)):
    if max >  a[i]:
        if a[i - 1] > max:
            max = a[i - 1]
        count += max - a[i]
    else:
        max = a[i]
print(count)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
fumidai_list, A_after = [], 0

for count_a in range(len(A)):
    fumidai = 0

    if(A[count_a] >= A_after):
        A_after = A[count_a]
        fumidai_list.append(fumidai)

    elif(A[count_a] < A_after):

        while True:
            fumidai = fumidai + 1
            A[count_a] = A[count_a] + fumidai
            if(A[count_a] >= A_after):
                break

        fumidai_list.append(fumidai)

print((sum(fumidai_list)))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
fumidai_list, A_after = [], 0

for count_a in range(len(A)):
    fumidai = 0

    if(A[count_a] >= A_after):
        A_after = A[count_a]
        fumidai_list.append(fumidai)

    elif(A[count_a] < A_after):
        fumidai = A_after - A[count_a]
        fumidai_list.append(fumidai)

print((sum(fumidai_list)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

res = a[0]
ans = 0
for i in range(1, n):
  if res>=a[i]:
    ans += res-a[i]
  else:
    res = a[i]
    
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))


res = a[0]
ans = 0
for i in range(1, n):
  if res-a[i]>=0:
    ans += res-a[i]
  else:
    res = a[i]
    
print(ans)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
c=0
for i in range(len(A)-1):
  m=max(A[0:i+1])
  if m>A[i+1]:
    d=m-A[i+1]
    c+=d
print(c)

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
c=0
m=A[0]
for i in range(len(A)-1):
  if m<A[i+1]:
    m=A[i+1]
  if m>A[i+1]:
    d=m-A[i+1]
    c+=d
print(c)
# Original solution
n = int(eval(input()))
li = list(map(int,input().split()))
ans = 0
for i in range(n):
    if i > 0:
        while li[i-1] > li[i]:
            li[i]+=1
            ans += 1

print(ans)


# Optimized solution
n = int(eval(input()))
li = list(map(int,input().split()))
ans = 0
for i in range(n):
    if i > 0:
        if  li[i-1] > li[i]:
            ans += li[i-1]-li[i]
            li[i] += (li[i-1]-li[i])

print(ans)
# Original solution
N=int(eval(input()))
A=[int(_) for _ in input().split(" ")]

max=max(A)
if A[0] == max:
  total=0
  for i in range(len(A)):
    total = total + max - A[i]
  print(total)
  exit()

ans=0
total=0
b=len(A)
a=1

while a!=0:
  max=0
  for i in range(b):
    if max < A[i]:
      a=i
      max=A[i]
  for i in range(a+1,b):
    total += max - A[i]
  b=a

print(total)
    


# Optimized solution
N=int(eval(input()))
A=[int(_) for _ in input().split(" ")]

max=0
total=0

for i in range(len(A)):
  if max < A[i]:
    max=A[i]
  else:
    total+=max-A[i]

print(total)
# Original solution
n = int(eval(input()))
A = list(map(int,input().split()))

step = [0]
for i in A[1:]:
    if A[A.index(i)-1] >= i:
        step.append(A[A.index(i)-1] - i)
        A[A.index(i)] += A[A.index(i)-1] - i
print((sum(step)))


# Optimized solution
n = int(eval(input()))
A = list(map(int,input().split()))
step = [0]
for k,i in enumerate(A[1:]):
    if A[k] >= i:
        step.append(A[k] - i)
        A[k+1] = A[k+1] + A[k] - i
print((sum(step)))
# Original solution
#coding: utf-8
import sys
def input():
    return sys.stdin.readline()[:-1]
"""
N人が1列に並んでおり、前からi番目の人の身長は A_iです。
それぞれの人の足元に、高さが0以上の踏み台を設置し、全ての人が次の条件を満たすようにしたいです。
条件：踏み台を込めて身長を比較したとき、自分より前に、自分より背の高い人が存在しない
この条件を満たす時の、踏み台の高さの合計の最小値を求めてください。
"""
N = int(eval(input()))
A = list(map(int, input().split()))
out = 0
for x, a in enumerate(A):
    if x==0:
        continue
    out += max(0, max(A[:x])-a)
print(out)

# Optimized solution
#coding: utf-8
import sys
def input():
    return sys.stdin.readline()[:-1]
"""
N人が1列に並んでおり、前からi番目の人の身長は A_iです。
それぞれの人の足元に、高さが0以上の踏み台を設置し、全ての人が次の条件を満たすようにしたいです。
条件：踏み台を込めて身長を比較したとき、自分より前に、自分より背の高い人が存在しない
この条件を満たす時の、踏み台の高さの合計の最小値を求めてください。
"""
N = int(eval(input()))
A = list(map(int, input().split()))
out = 0
# for x, a in enumerate(A):
#     if x==0:
#         continue
#     out += max(0, max(A[:x])-a)
vmax = 0
for a in A:
    vmax = max(vmax, a)
    out += vmax - a
print(out)
# Original solution
N = int(eval(input()))
A = input().split()
count = 0
for i in range(N-1):
  if int(A[i]) > int(A[i+1]):
    count += int(A[i]) - int(A[i+1])
    A[i+1] = int(A[i])

print(count)

# Optimized solution
N = int(eval(input()))
A = input().split()
count = 0

for i in range(N):
  A[i] = int(A[i])
for i in range(N-1):
  if A[i] > A[i+1]:
    count += A[i] - A[i+1]
    A[i+1] = A[i]

print(count)
# Original solution
N = int(eval(input()))#整数
A = list(map(int, input().split()))#配列Int型

ans = 0

for i in range(N):
    for j in range(i + 1):
        if A[i] > A[j]:
            ans = A[i] - A[j]
            A[j] += ans
print(ans)

# Optimized solution
N = int(eval(input()))#整数
A = list(map(int, input().split()))#配列Int型

ans = 0
max_val = A[0]

for i in range(1, N):
    if max_val > A[i]:
        ans += max_val - A[i]
    else:
        max_val = A[i]
print(ans)
# Original solution
b=0
print((sum((b:=max(c:=int(a),b))-c for a in[*open(0)][1].split())))

# Optimized solution
b=s=0
for a in[*open(0)][1].split():a=int(a);b=max(b,a);s+=b-a
print(s)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

res = []
for i in range(len(A) - 1, 0, -1):
    val = A[i]
    max_val = -1
    for j in A[:i]:
        if max_val < j:
            max_val = j

    if max_val > val:
        res.append(max_val - val)
    else:
        res.append(0)

print((sum(res)))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

res = 0
max_val = -1
for a in A:
    if a >= max_val:
        max_val = a
    else:
        res += max_val - a

print(res)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
hight = A[0]
base = 0
for i in range(1,N):
  if A[i] < hight:
    base += hight - A[i]
  else:
    hight = A[i]
print(base)

# Optimized solution
N = int(eval(input()))
List = list(map(int,input().split()))
counter = 0
height = List[0]
for i in range(1,N):
  if List[i] < height:
    counter += height - List[i]
  else:
    height = List[i]
print(counter)
# Original solution
N = int(eval(input()))
As = list(map(int, input().split()))
 
sum_humidai = 0
 
for person_idx, person_height in enumerate(As):
  
  if person_idx == 0:
    continue
    
  max_front_person = max(As[:person_idx])
  if max_front_person > person_height:
    humidai = max_front_person - person_height
    sum_humidai += humidai
 
print(sum_humidai)

# Optimized solution
N = int(eval(input()))
As = list(map(int, input().split()))
 
sum_humidai = 0
max_front_person = 0
  
for person_idx, person_height in enumerate(As):
  
  if person_idx == 0:
    continue
    
  max_front_person = max(max_front_person, As[person_idx - 1])
  if max_front_person > person_height:
    humidai = max_front_person - person_height
    sum_humidai += humidai
 
print(sum_humidai)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
l = []

for i in range(n):
    if i == 0:
        l.append(a[0])
    else:
        if max(l) <= a[i]:
            l.append(a[i])
        else:
            l.append(max(l))
            
print((sum(l) - sum(a)))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
l = [a[0]]

for i in range(n-1):
    if l[i] >= a[i+1]:
        l.append(l[i])
    else:
        l.append(a[i+1])

print((sum(l) -sum(a)))
# Original solution
##C - Step(TLE)
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    ##print(i,A)
    if A != []:
        maxi = max(A)
        Idx = A.index(maxi)
        ans += maxi*(len(A) - Idx) - sum(A[Idx::])
        del A[Idx::]
    else:
        break
print(ans)

# Optimized solution
##C - Step(TLE)
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
maxi = 0
for i in A:
    ans += max(0,maxi-i)
    maxi = max(maxi,i)
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
def seek(LIST:list):
    global ans
    max_num = max(LIST)
    index = LIST.index(max(LIST))
    if(index == 0):
        ans += max_num*len(LIST)-sum(LIST)
    else:
        cal_LIST = LIST[index:]
        ans += max_num*len(cal_LIST)-sum(cal_LIST)
        new_list = LIST[0:index]
        seek(new_list)
seek(A)
print(ans)


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
max_num = A[0]
ans = 0
for i in A:
    if(max_num>=i):
        ans += max_num-i
    else:
        max_num = i
print(ans)
# Original solution
n = int(eval(input()))
A = list( int(x) for x  in input().split() )

fumidai = 0

for i in range(n):
    x_list = A[0:i+1]
    max_list = max(x_list)
    if max_list > A[i]:
        fumidai += max_list - A[i]

print(fumidai)

# Optimized solution
n = int(eval(input()))
A = list( int(x) for x  in input().split() )

fumidai = 0
great = A[0]

for i in range(n):
    if great > A[i]:
        fumidai += great - A[i]
    else:
        great = A[i]

print(fumidai)
# Original solution
N = int(eval(input()))
array = []
array += list(map(int,input().split()))
sumarray = sum(array)
step = 0
while array != []:
    rearray=array[array.index(max(array)):]
    step+=len(rearray)*max(array)
    del array[array.index(max(array)):]
ans=step-sumarray
print(ans)


# Optimized solution
N = int(eval(input()))
array = []
array+=list(map(int,input().split()))
ans=0
premax=0
for n in range(N):
    premax=max(array[n],premax)
    ans+=premax-array[n]
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    if A[i-1] <= A[i]:
        continue
    ans += A[i-1] - A[i]
    A[i] = A[i-1]
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    if A[i-1] > A[i]:
        d = A[i-1] - A[i]
        A[i] += d
        ans += d
print(ans)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
S=0
i=N
while i>1:
    saidai=A.index(max(A[0:i]))
    S+=sum(list([max(A[0:i])-x for x in A[saidai:i]]))
    i=saidai
print(S) 

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
s=a[0]
ans=0
for i in range(n):
    if a[i]<s:
        ans+=s-a[i]
    else:
        s=a[i]
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
    if i == 0 and max(a):
        continue
    elif i < max(a):
        ans += 1

print(ans)

# Optimized solution
from sys import stdin
readline = stdin.readline
n = int(readline())
a = list(map(int, readline().split()))
x = 0
ans = 0
for i in a:
    if x > i:
        ans += (x-i)
    else:
        x = i
print(ans)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
B=0
for i in range(N):
    L = [A[j] for j in range(i+1)]
    L.sort()
    B += L[i]-A[i]
print(B)


# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
B=0
Mi=A[0]

for i in range(1,N):
    if A[i] > Mi:
        Mi = A[i]
    B += Mi - A[i]
print(B)
# Original solution
N = int(eval(input()))
height = list(map(int, input().split()))
total = 0
max_number = height[0]

for i in range(1, height.index(max(height))):
	if height[i] > max_number:
		max_number = height[i]
	else:
		total += (max_number - height[i])

for i in range(height.index(max(height)), N):
	total += (max(height)-height[i])
    
print(total)

# Optimized solution
N = int(eval(input()))
height = list(map(int, input().split()))
total = 0
max_number = height[0]

for i in range(1, height.index(max(height))):
	if height[i] > max_number:
		max_number = height[i]
	else:
		total += (max_number - height[i])

total += (max(height)*(N-1-height.index(max(height)))-sum(height[height.index(max(height))+1:N]))
    
print(total)
# Original solution
# dp[i] := i番目の人が選ばれたときの踏み台

def main():
    # INF = 10 ** 9
    N = int(eval(input()))
    A = list(map(int, input().split()))

    # initialize
    dp = [0] * (N + 10)
    dp[0] = A[0]

    res = 0
    for i in range(1, N):
        for j in range(10**9):
            tmp = A[i] + j
            if dp[i-1] <= tmp:
                dp[i] = tmp
                res += j
                break
    print(res)

if __name__ == "__main__":
    main()

# Optimized solution
# maをi-1番目までにでてる最大値としてi番目との差分を足していく

def main():
    # INF = 10 ** 9
    N = int(eval(input()))
    A = list(map(int, input().split()))

    # initialize
    ma = A[0]

    res = 0
    for i in range(1, N):
        if A[i] <= ma:
            res += ma - A[i]
        else:
            ma = A[i]
    print(res)

if __name__ == "__main__":
    main()
# Original solution
N = eval(input())
A = list(map(int, input().split()))

c = 0
hoge = []

for i in range(len(A)):
  hoge.append(max(A[0:i+1]))

print((sum(hoge)-sum(A)))

# Optimized solution
N = eval(input())
A = list(map(int, input().split()))

c = 0
mae = A[0]

for i in A:
  if i < mae:
    c += mae - i
  else:
    mae = i

print(c)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    if A[i+1] < A[i]:
        cnt += A[i]-A[i+1]
        A[i+1] = A[i]
    else:
        pass
print(cnt)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    if A[i+1] < A[i]:
        cnt += A[i] - A[i+1]
        A[i+1] = A[i]
print(cnt)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

ans = 0
for i in range(1, n):
    if a[i-1] > a[i]:
        ans += a[i-1] - a[i]
        a[i] = a[i-1]
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

tmp = a[0]
ans = 0
for i in a:
    if i < tmp:
        ans += tmp-i
    else:
        tmp = i
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
min_size = A[0]
res = 0
for i in range(N):
  if A[i] < min_size:
    d = min_size - A[i]
    res += d
  elif A[i] > min_size:
    min_size = A[i]
print(res)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

res = 0
max_size = A[0]
for i in range(N):
  max_size = max(max_size, A[i])
  d = max_size - A[i]
  res += d
print(res)
# Original solution
c = [1.1,0.6,0.2,0.0]
r = [0 for i in range(8)]
while 1:
    try:
        e = list(map(float, input().split()))
        for i in range(2):
            for j in range(4):
                if e[i] >= c[j]:
                	r[i+2*j] += 1
                	break
    except:
        break
for i in range(0,8,2):
	print(r[i],r[i+1])

# Optimized solution
from bisect import bisect
ref = [0.2,0.6,1.1]
l,r = [0]*4,[0]*4
while 1:
    try:
        le,re = list(map(float, input().split()))
        l[bisect(ref,le)] += 1
        r[bisect(ref,re)] += 1
    except:
        break
for i in range(1,5):
	print(l[-i],r[-i])
# Original solution
a, b = list(map(int, input().split()))
d = a//b
r = a % b
f = a / b
print(("{:d} {:d} {:.5f}".format(d,r,f)))

# Optimized solution
a, b = list(map(int,input().split()))
d,r,f = a//b,a%b,a/b
print(('{} {} {:.5f}'.format(d,r,f)))
# Original solution
a,b = list(map(int,input().split()))

ans = a+b
#print(ans)

if ans%2 == 1:
  print(((a+b)//2+1))
else:
  print(((a+b)//2))

# Optimized solution
from math import ceil #小数点以下切り上げ
 
a, b = list(map(int, input().split()))
print((ceil((a+b)/2)))
# Original solution
import math
a,b = list(map(int, input().split()))
print((math.ceil( (a+b) / 2) ))

# Optimized solution
import math
a,b = list(map(int, input().split()))
print((int(math.ceil((a+b)/2))))
# Original solution
a,b = list(map(int,input().split()))
c = int((a+b+1)/2)
print(c)

# Optimized solution
a,b = list(map(int,input().split()))
print(((a+b+1)//2))
# Original solution
import math
a, b = list(map(int,input().split()))
print((math.ceil((a+b)/2)))

# Optimized solution
a, b = list(map(int,input().split()))
print(((a+b+1)//2))
# Original solution
a, b = list(map(int, input().split()))
print((-(-(a+b)//2)))

# Optimized solution
a, b = list(map(int, input().split()))
print((-((-a-b)//2)))
# Original solution
"""
author : halo2halo
date : 24,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

n, a = list(map(int, readline().rstrip().split()))


ans = int((n+a+1)/2)

print(ans)


# Optimized solution
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

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

A, B = list(map(int, readline().split()))

print(((A+B+1)//2))
# Original solution
import math
a, b = list(map(int, input().split()))
print((math.ceil((a+b)/2)))

# Optimized solution
# -*- coding: utf-8 -*-

import math


def func(a, b):
    result = math.ceil((a+b)/2)
    return result


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

print((func(a, b)))
# Original solution
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

a, b = inl()
import math
print(math.ceil((a + b) / 2))


# Optimized solution


import math

a, b = list(map(int, input().split()))
print((math.ceil((a + b) / 2)))
# Original solution
a,b =list(map(int, input().split()))

x = (a+b)/2

import math
print(( math.ceil(x)))

# Optimized solution
import math
a,b = list(map(int, input().split()))
print((math.ceil((a+b)/2)))
# Original solution
a,b = list(map(int,input().split()))
print((-(-(a+b)//2)))

# Optimized solution
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    a, b = list(map(int, input().split()))
    print(((a + b + 1) // 2))
resolve()
# Original solution
import math

a, b = list(map(int, input().split()))
print((math.ceil((a+b)/2)))

# Optimized solution
a, b = list(map(int, input().split()))
print(((a + b + 2 - 1) // 2))
# Original solution
import math

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

x = (a + b) / 2
print((math.ceil(x)))

# Optimized solution
a, b = list(map(int, input().split()))

# "//"は商を求める演算子
x = (a + b + 1) // 2
print(x)
# Original solution
# -*- coding: utf-8 -*-
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN


nums = list(map(int, input().rstrip().split()))

#----------
average = (nums[0] + nums[1]) / 2
print(( Decimal(str(average)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)))


# Optimized solution
# -*- coding: utf-8 -*-

a,b = [int(i) for i in input().rstrip().split()]
print(( ((a+b) + (2-1)) // 2 ))
# Original solution
a, b = list(map(int, input().split()))
if (a + b) % 2 == 0:
    x = (a + b) / 2
else:
    x = (a + b + 1)/2
print((int(x)))



# Optimized solution
a, b = list(map(int, input().split()))
print(((a + b + 1)//2))
# Original solution
st=input().split()
a=int(st[0])
b=int(st[1])
if (a+b)%2==0:
    print(((a+b)//2))
else:
    print(((a+b+1)//2))


# Optimized solution
a,b=list(map(int,input().split()))
print((-((-a-b)//2)))
# Original solution
a,b = list(map(int,input().split()))

if (a+b) % 2 == 0:
    print(((a+b)//2))
else:
    print(((a+b)//2+1))

# Optimized solution
print((-~sum(map(int,input().split()))//2))
# Original solution
a,b=list(map(int,input().split()))
ans= (a+b)//2 if (a+b)%2 == 0 else (a+b)//2+1
print(ans)

# Optimized solution
import math
a,b=list(map(int,input().split()))
print((math.ceil((a+b)/2)))
# Original solution
import math
a,b=list(map(int,input().split()))
print((math.ceil((a+b)/2)))

# Optimized solution
print((-~sum(map(int,input().split()))//2))
# Original solution
a,b=list(map(int,input().split()))
print((-~(a+b)//2))

# Optimized solution
a,b=list(map(int,input().split()))
print((-(-(a+b)//2)))
# Original solution

ab=list(map(int,input().split()));print(((sum(ab)-1)//2+1))


# Optimized solution
print((~-sum(map(int,input().split()))//2+1))
# Original solution
a, b = (int(i) for i in input().split())
#print(a,b)

c=-(-(a+b)//2)
print(c)

# Optimized solution
a, b = (int(i) for i in input().split())
#print(a,b)

c=(a+b+(2-1))//2
print(c)
# Original solution
a, b = list(map(int, input().split()))

if (a + b) % 2 == 0:
    mean = (a + b) // 2
else:
    mean = (a + b) // 2 + 1
print(mean)


# Optimized solution
a, b = list(map(int, input().split()))

if (a + b) % 2 == 0:
    print(((a + b) // 2))
else:
    print(((a + b) // 2 + 1))
# Original solution
print((eval(input().replace(' ','+1+'))//2))

# Optimized solution
print((eval(input().replace(*' +'))+1>>1))
# Original solution
a,b=list(map(int,input().split()))
print((int((a+b+1)/2)))

# Optimized solution
a,b=list(map(int,input().split()))
print(((a+b+1)//2))
# Original solution
import math
a,b=list(map(int,input().split()))
print((math.ceil((a+b)/2)))

# Optimized solution
a,b = list(map(int,input().split()))
print(((a+b+1)//2))
# Original solution
from math import ceil
from statistics import mean
a = list(map(int,input().split()))
print((ceil(mean(a))))

# Optimized solution
import math
a,b = list(map(int,input().split()))
print((math.ceil((a+b)/2)))
# Original solution
a, b = list(map(int, input().split()))
print((-(-(a + b)//2)))

# Optimized solution
a, b = list(map(int, input().split()))
print(((a + b + 1)//2))
# Original solution
import math
import statistics as st

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

print((math.ceil(st.mean((a,b)))))

# Optimized solution
import math
a, b = list(map(int,input().split()))
print((math.ceil((a+b)/2)))
# Original solution
import math
a,b = list(map(int,input().split()))
print((int(math.ceil((a+b)/2))))

# Optimized solution
a,b = list(map(int,input().split()))
print((-(-(a+b)//2)))
# Original solution
from math import ceil
from statistics import mean

ab = list(map(int, input().split()))
print((ceil(mean(ab))))


# Optimized solution
from math import ceil
a, b = list(map(int, input().split()))
print((ceil((a+b)/2)))
# Original solution
x,y = list(map(int, input().split()))
z =x+y
import math
print((math.ceil(z/2)))

# Optimized solution
x,y = list(map(int, input().split()))
import math
print((math.ceil((x+y)/2)))
# Original solution
n,q=list(map(int,input().split()))
c=list(map(int,input().split()))
p=[0]*(max(c)+1)
for i in c:
	p[i]=1

for k in range(q):
	m=int(input())
	flag=0
	ans=0
	for i in range(m-1,0,-1):
		for pi in p[i::m]:
			if pi:
				ans=i
				break
		if ans>0:
			break
	print(ans)

# Optimized solution
N,Q=list(map(int,input().split()))
c=list(map(int,input().split()))

mxc=max(c)
p=[0]*(mxc+1)
for i in c:
    p[i]=1
    
l=[0]*(mxc+1)
num=0
for i in range(mxc+1):
    l[i]=num
    if p[i]:
        num=i
        
for i in range(Q):
    q=int(input())
    sp=mxc
    ans=0
    while 1:
        r=sp%q
        ans=max(ans,r)
        if sp-r<=0:break
        sp=l[sp-r]
    print(ans)