peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ans = 0

for i in range(n-1,-1,-1):
    ans += (ab[i][1]-(ab[i][0]+ans)%ab[i][1])%ab[i][1]
    print(ans)
# Judge status: Accepted
N, X = map(int, input().split())
Ls = list(map(int, input().split()))

ans = 1
D = 0
for L in Ls:
    D += L
    ans += D <= X

print(ans)
# Judge status: Wrong Answer
import re

S = input()

patterns = (".*keyence", "k.*eyence", "ke.*yence", "key.*ence", "keye.*nce", "keyen.*ce", "keyenc.*e", "keyence.*")
if any(re.match(pattern, S) for pattern in patterns):
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())
ans = 1
for i in range(1,31623):
    if N >= i**2:
        ans = i**2
    else:
        break
print(ans)
# Judge status: Accepted
n = int(input())
l = [int(i) for i in input().split()]
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = l[i] + l[j]

        mi = 0
        ma = n - 1
        while mi != ma:
            m = (mi + ma) // 2 + 1
            if l[m] < a:
                mi = m
            else:
                ma = m - 1
        ans += max(0, mi - j)
print(ans)
# Judge status: Wrong Answer
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
t = ''.join(list(reversed(S())))
if s < t:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import math

N = int(input())

x = N
n = math.floor(math.sqrt(N))
p = {}
i = 2

while i <= n:
    while x % i == 0:
        p.setdefault(i, 0)
        p[i] += 1
        x //= i
    i += 1

if x != 1 and x == N:
    p.setdefault(N, 1)

ans = 0

for v in p.values():
    i = 1
    while v - i >= 0:
        v -= i
        ans += 1
        i += 1

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

N = input().rstrip()
N = N[::-1]

if N[0] == "3":
    print("bon")
elif N[0] == "0" or N[0] == "1" or N[0] == "6" or N[0] == "8":
    print("pon")
else:
    print("hon")
# Judge status: Accepted
N=int(input())
S=input()
print('Yes' if N%2==0 and S[:N//2]==S[N//2:] else 'No')
# Judge status: Accepted
n, r =  map(int, input().split())
if n>=10:
  print(r)
else:
  print(r+(100*(10-n)))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

ok = []
no_and_no_even = []
no_and_even = []
for i in range(N):
    if (A[i] % 4 == 0):
        ok.append(A[i])
    elif (A[i] % 4 != 0 and A[i] % 2 == 0):
        no_and_even.append(A[i])
    else:
        no_and_no_even.append(A[i])

if (len(ok) == len(no_and_no_even) or len(ok) == len(no_and_no_even) - 1):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
def check_num(i):
    s = str(i)
    l = len(s)
    
    for ll in range(l - 1):
        if not ((int(s[ll]) >= int(s[ll - 1]) - 1) 
                & (int(s[ll]) <= int(s[ll - 1]) + 1)):
            return False
    return True

k = int(input())
c = 0
x = 0

while (-1):
    x += 1
    flag = check_num(x)
    if flag == True:
        c += 1
        if c == k:
            print(x)
            break
# Judge status: Wrong Answer
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n,k = I2()
l = []
for i in range(k):
    d = I()
    for k in intl():
        l.append(k)
print(len(l)-len(list(set(l))))
# Judge status: Wrong Answer
n=int(input())
s=[input()for i in range(n)]
d=dict()
for i in s:
 i="".join(sorted(list(i)))
 try:d[i]+=d[i]+1
 except:d[i]=0
print(sum(d.values()))
# Judge status: Wrong Answer

import sys

n,m = map(int,input().split())
suuji = ['0'  for i in range(n)]
# print(suuji)
for i in range(m):
    a,b = map(int,input().split())
    if suuji[a-1]=='0' or suuji[a-1]==str(b):
        suuji[a-1]=str(b)
    else:
        print(-1)
        sys.exit()

if suuji[0] != '0':
    ans = int(''.join(suuji))
else:
    ans = -1

print(ans)
# Judge status: Wrong Answer
from bisect import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for i in B:
    max_A = bisect(A, i-1)
    min_C = bisect(C, i+1)
    print("m_A", max_A, "m_C", min_C)
    ans += (max_A)* (len(C) - min_C)
print(ans)
# Judge status: Accepted
x, n = map(int,input().split())
p_l = list(map(int,input().split()))

if x not in p_l:
    print(x)
    exit()

for i in range(1,100):
    if (x - i) not in p_l:
        print(x-i)
        break
    elif (x + i) not in p_l:
        print(x+i)
        break
# Judge status: Accepted
import sys
n = int(input())
a = list(map(int, input().split()))

nl = sum(a)

tmp = 1
l = 0
ans = 0
for ai in a:
    ans += tmp
    if tmp < ai:
        print(-1)
        sys.exit()
    tmp -= ai
    l += ai
    if l + 2 * tmp <= nl:
        tmp *= 2
    else:
        tmp = nl - l

print(ans)
# Judge status: Accepted
n = int(input())
d = list(map(int,input().split()))
d = sorted(d)
print(d[round(n/2)]-d[round(n/2)-1])
# Judge status: Wrong Answer
import math

N = int(input())

lower = N / 1.08
upper = (N + 1) / 1.08

vl = math.ceil(lower)
vu = math.floor(upper)

if vl < upper:
  print(vl)
  exit(0)
if lower <= vu:
  print(vu)
  exit(0)
else:
  print(":(")
# Judge status: Wrong Answer
a , b ,c , k = map(int, input().split())


tmp = k - a # k比a的張數多
tmp2 = k -a-b

if k < a:
    print(k)
elif  tmp > 0  and tmp < b:
    print(a)
elif tmp2 != k:
    print(a - tmp2)
else:
    print(-k)
# Judge status: Accepted
N = int(input())
H = list(map(int, input().split()))
marks = [0]*N
for i in range(N-1):
  if H[i]>=H[i+1]:
    marks[i]=1
c = 0
lis = []
for i in range(N):
  if marks[i]==1:
    c+=1
  else:
    lis.append(c)
    c=0
print(max(lis))
# Judge status: Accepted
X,Y = map(int,input().split())

def solve(now,y,ans=0):
  ans = 0
  while now <= y:
    ans += 1
    now *= 2
  return ans
  
print(solve(X,Y))
# Judge status: Accepted
import sys

def main():
    X = list(map(int, input().split()))
    if max(X) % 2 == sum(X) % 2:
        print((max(X) * 3 - sum(X))//2)
    else:
        print(((max(X)+1) * 3 - sum(X))//2)
    
    

if __name__ == '__main__':
    main()
# Judge status: Accepted
S = input()
T = input()

ans = len(T)
for i in range(len(S)-len(T)+1):
  t = len(T)
  for j in range(len(T)):
    if S[i+j] == T[j]:
      t -= 1
  # print(t)
  ans = min(ans, t)
print(ans)
# Judge status: Wrong Answer
n, p = map(int, input().split())
a = list(map(int, input().split()))

odd = sum([item % 2 for item in a])
even = n - odd

ans = 0
if even == n and p == 1:
    print(0)
elif odd == n and p == 0:
    print(0)
else:
    # 偶数枚入った袋は選ぶor選ばない自由
    ans += 2 ** even

    # 奇数枚入った袋は2で割って余りがPになるよう選ぶ個数を決める
    ans *= 2 ** (odd - 1)
    print(ans)
# Judge status: Accepted
s = input()
n = len(s)
for i in range(n):
    if s[i] == 'A':
        l = i
        break
for i in range(n-1,i,-1):
    if s[i] == 'Z':
        r = i+1
        break
ans = max(0,r-l)
print(ans)
# Judge status: Accepted
num = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
z = list(map(int,input().split()))
val = 0
 
for i in range(num):
    val += y[x[i]-1]
    if 1<=i and x[i]-x[i-1] == 1:
        val += z[x[i]-2]
 
print(val)
# Judge status: Accepted
D, N = map(int, input().split())

if D == 0:
  if N != 100:
    print(N)
  else:
    print(101)
elif D == 1:
  if N != 100:
    print(N * 100)
  else:
    print(10100)
else:
  if N != 100:
    print(N*10000)
  else:
    print(1010000)
# Judge status: Accepted
S = input()

if "a" in S and "b" in S and "c" in S:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import copy
k = int(input())
c = 10
ans = 0
if k <= 10:
	print(k)
else:
	while ans < k:
		C = copy.copy(list(str(c)))
		ok = 0
		for i in range(len(C)-1):
			if abs(int(C[i]) - int(C[i+1])) <= 1:
				ok += 1
		if ok == len(C) - 1:
			ans += 1
		c += 1
	print(ans + 8)
# Judge status: Wrong Answer
n = int(input())
A = [list(map(int,input().split())) for _ in range(n)]
#print(A)
A = sorted(A, key = lambda x:x[0])
#print(A)
now = 0
cnt = 0
for i in range(n):
    if now < A[i][0]:
        now = A[i][0] + A[i][1]
        cnt += 1
print(cnt)
# Judge status: Wrong Answer
n = int(input())
L = [0 for _ in range(n+2)]
L[0]=2
L[1]=1
if n > 2:
    for i in range(2,n+1):
        L[i] = L[i-1]+L[i-2]
print(L[n])
# Judge status: Wrong Answer
h, n = map(int, input().split())
a = list(map(int,input().split()))
if sum(a) > h :
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N,Y = map(int,input().split())


for x in range(N+1):
	for y in range(N-x+1):
		for z in range(N-x-y+1):
			if Y == 10000*x + 5000*y + 1000*z:
				print(x,y,z)
				exit()
print(-1,-1,-1)
# Judge status: Accepted
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
 
if N <= K :
	answer = X * N
elif N >= K + 1:
	answer = (X * K) + (Y * (N - K) )
print(answer)
# Judge status: Wrong Answer
n = int(input())
i = 0
for _ in range(n):
    x, y = map(int, input().split())
    if x == y:
        i += 1
if(i < 3):
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
# C - Poll

N = int(input())
D = {}
for _ in range(N):
    s = str(input())
    if s not in D:
        D[s] = 1
    else:
        D[s] += 1

ans = []
mx = D[max(D)]
for d in D:
    if D[d] == mx:
        ans.append(d)

for a in sorted(ans):
    print(a)
# Judge status: Accepted
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)

for i in range(q):
    b, c = map(int, input().split())
    sum_res += (c-b)*counter[b]

    counter[c] += counter[b]
    counter[b] = 0
    print(sum_res)
# Judge status: Wrong Answer
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
ruiseki = [0]+list(itertools.accumulate(A))
i = bisect.bisect_left(ruiseki,sum(A)/2)
print(i)
print(min(abs(sum(A[:i])-sum(A[i:])),abs(sum(A[:i-1])-sum(A[i-1:]))))
# Judge status: Wrong Answer
a,b = map(int, input().split())

total =0

for i in range(2):
    if a >= b:
        total+=a
    else:
        total+=b

print(total)
# Judge status: Accepted
import numpy as np
 
N,Max_W = map(int,input().split())
 
dp = [0 for _ in range(Max_W + 1)]
dp = np.array(dp)
 
for i in range(N):
    w,v = map(int,input().split())
    a = dp[:-w] + v
    b = dp[w:]
    m = np.maximum(a,b)
    dp[w:] = m
print(dp[-1])
# Judge status: Accepted
n, m = map(int, input().split())

print(min(((n * 2 + m) // 4, m // 2)))
# Judge status: Wrong Answer
def mealdelivery(x , a , b):

    return "A" if abs(x - a) > abs(x - b) else "B"

def main():
    x , a , b = map(int , input().split())
    print(mealdelivery(x , a , b))

if __name__ == '__main__':
    main()
# Judge status: Accepted
s=input()
t=input()
if len(s)<len(t):
  print("UNRESTORABLE")
  exit()
n=len(s)
m=len(t)
for i in range(n-m,-1,-1):
  x=s[i:i+m]
  for j in range(m+1): #
    if j==m:
      print((s[:i]+t+s[i+m:]).replace("?","a"))
      exit()
    if x[j]=="?":
      continue
    elif x[j]!=t[j]:
      break
print("UNRESTORABLE")
# Judge status: Wrong Answer
s = list(map(int,input()))

n = int(len(s)/2)

a = [0]*len(s)
b = [0]*len(s)

for i in range(n):
  a[2*i] = 0
  a[2*i+1] = 1
  b[2*i] = 1
  b[2*i+1] = 0

an = 0
bn = 0

for j in range(len(s)):
  if a[j] != s[j]:
    an += 1
  if b[j] != s[j]:
    bn += 1

print(min(an, bn))
# Judge status: Accepted
import itertools
n, m, x = map(int, input().split())
table = [tuple(map(int, input().split())) for _ in range(n)]
ans = []
for i in range(1,n+1):
    for cap in itertools.combinations(table, i):
        money = 0
        a = [0] * m
        for j in cap:
            money += j[0]
            for k in range(m):
                a[k] += j[k+1]
        if not len([l for l in a if l < x]):
            ans.append(money)
if not ans:
    print(-1)
else:
    print(min(ans))
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))

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


ans=left
ans.extend(right)
L=[str(a) for a in ans]
L=" ".join(L)
print(L)
# Judge status: Accepted
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
ans1 = max(x[0] + x[1] for x in d) - min(x[0] + x[1] for x in d)
ans2 = max(x[0] - x[1] for x in d) - min(x[0] - x[1] for x in d)
print(max(ans1, ans2))
# Judge status: Accepted
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a.sort()
ct = Counter(a)
st = set()
ans = 0
x = max(a)
for i in range(n):
    if a[i] in st:
        continue
    if ct[a[i]]>1:
        st.add(a[i])
    for j in range(2,x//a[i]+1):
        st.add(a[i]*j)
for i in range(n):
    if not a[i] in st:
        ans += 1
print(ans)
# Judge status: Accepted
a, b, c, k = map(int, input().split())

if a + b >= k:
	if a >= k:
		print(k)
	else:
		print(a)
else:
	print(a - (k - a - b))
# Judge status: Accepted
from heapq import heappop, heappush 
N, M = map(int, input().split())
score = 0
AB = [[] for i in range(M)]
for i in range(N):
  a, b = map(int, input().split())
  if M - a >= 0:
    AB[M - a].append(b)
  
#print(AB)
queue = []
for i in range(1, M + 1):
  for j in AB[-i]:
    heappush(queue, -j)
  if queue != []:
    score += -1 * heappop(queue)
  
  #print(score, queue)  
print(score)
# Judge status: Accepted
A, B, C, D = map(int, input().split())
Ta = -(-C//B)
Ao = -(-A//D)
print('Yes' if Ta <= Ao else 'No')
# Judge status: Accepted
n,m=map(int,input().split())
ab=[]
ans=0
for i in range(n):
  a,b=map(int,input().split())
  ab.append([a,b])
ab.sort()
for a,b in ab:
  t=min(b,m)
  ans+=t*a
  m-=t
print(ans)
# Judge status: Wrong Answer
from bisect import bisect_left, bisect_right

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
sumSunuke = 0

for x in range(N):
    ab = bisect_right(A, B[x])
    bc = N - bisect_left(C, B[x])
    if B[x] in A:
        ab -= 1
    if B[x] in C:
        bc -= 1
    sumSunuke += ab * bc
print(sumSunuke)
# Judge status: Accepted
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
dp = [float('INF')]*(N+1)
dp[0] = 0
for i in range(N+1):
    if i+1<=N:
        dp[i+1] = min(dp[i+1],dp[i]+1)
    num6,num9 = 6,9
    while i+num6<=N:
        dp[i+num6] = min(dp[i+num6],dp[i]+1)
        num6 *= 6
    while i+num9<=N:
        dp[i+num9] = min(dp[i+num9],dp[i]+1)
        num9 *=9
print(dp[-1])
# Judge status: Accepted
A = [int(a) for a in input().split()]
A.sort()
K = int(input())
print(A[0] + A[1] + A[2] * 2 ** K)
# Judge status: Wrong Answer
MOD = 10**9+7
X, Y = map(int, input().split())
x, y = X, Y
while 0 <= y:
    if x == 2*y:
        break
    x += 1
    y -= 1
else:
    print(0)
    exit()


def com(n, r):
    X = Y = 1
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % MOD
        X = X*(n-i+1) % MOD
    Y = pow(Y, MOD-2, MOD)
    return X*Y


print(com(x//2, x-X) % MOD)
# Judge status: Wrong Answer
n,m=map(int,input().split())
while True:
    if m%n==0:
        print(n)
        exit()
    else:
        n-=1
# Judge status: Wrong Answer
X = int(input())
for a in range(10**2):
    B = a**5 - X
    b = B**-5
    if b % 1 == 0:
        print(str(int(a))+" "+str(int(b)))
        break
# Judge status: Wrong Answer
import math
n,k=map(int,input().split())
print(math.ceil(math.log(n,k)))
# Judge status: Accepted
N, K = map(int, input().split())
p = list(map(int, input().split()))

p.sort()
ans = 0
for i in range(K):
    ans += p[i]
print(ans)
# Judge status: Wrong Answer
import math

h_hand_len, m_hand_len, h, m = map(int, input().split())

m_radian = math.radians(m * 6)
h_radian = math.radians(h * 30) + m_radian/12.0

diff = abs(m_radian - h_radian)
if diff > math.pi:
    diff = diff - math.pi
    
ab = float(h_hand_len) * float(m_hand_len) * math.cos(diff)

ans = math.sqrt(h_hand_len**2 + m_hand_len**2 - 2.0 * ab)
print(ans)
# Judge status: Accepted
N = int(input())
q = [[int(i) for i in input().split()] for j in range(N)]
q = sorted(q, key=lambda x: x[1])

time = 0
for i in range(N):
    a, b = q[i]
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")
# Judge status: Wrong Answer
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    if len(set(A)) == 1:
        print(A[0])
    elif all(A[0] % 2 == a % 2 == 0 for a in A):
        print(2)
    else:
        print(1)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
  s = input()
  if s == "AC":
    ac += 1
  if s == "WA":
    wa += 1
  if s == "TLE":
    tle += 1
  if s == "RE":
    re += 1
    
print("AC x " + str(ac))
print("WA x " + str(wa))
print("tle x " + str(tle))
print("re x " + str(re))
# Judge status: Wrong Answer
import itertools

N, K = map(int, input().split())
A = input().split()
L = [int(b.strip()) for b in A]  

#print(N)
#print(K)
#print(L)

ret = 1000
for v in itertools.combinations(L, 3):
    #print(v)
    s = sum(v)
    #print(s)
    if ret > s:
      ret = s

print(ret)
# Judge status: Accepted
A,B=map(int, input().split())
print((A+B)//2 if (A+B)&1==0 else 'IMPOSSIBLE')
# Judge status: Wrong Answer
#　149D
n, k = map(int, input().split())
point={}
point['s'],point['p'],point['r'] = map(int, input().split())
s = input()

ans =0
before = [0]*k
for i in range(len(s)):
    if i > k:
        if (s[i] == s[i-k]) & (before[i%k]==1):
            before[i%k] = 0
        else:
            ans += point[s[i]]
            before[i%k] = 1
    else:
        ans += point[s[i]]
        before[i%k] = 1
print(ans)
# Judge status: Accepted
s = input()
t = input()

ans = 'No'
if s == t:
    print('Yes')
else:
    for i in range(len(s)-1):
        s = s[-1] + s[0:len(s)-1]
        if s == t:
            ans = 'Yes'
            break
    print(ans)
# Judge status: Accepted
def solve():
    N, M = map(int, input().split())
    INF = 10 ** 9
    dp = [INF] * (10 ** 7)
    dp[0] = 0

    for _ in range(M):
        a, b = list(map(int, input().split()))
        for i in range(N + 1):
            if dp[i] == INF:
                continue
            dp[i+a] = min(dp[i+a], dp[i] + b)
    return min(dp[N:])

print(solve())
# Judge status: Accepted
def actual(A, B, K):
    min_left = A
    max_left = min(A + (K - 1), B)

    min_right = max(B - (K - 1), max_left + 1)
    max_right = B

    left = set(range(min_left, max_left + 1))
    right = set(range(min_right, max_right + 1))

    unique_nums = left | right

    return '\n'.join(map(str, sorted(unique_nums)))

A, B, K = map(int, input().split())
print(actual(A, B, K))
# Judge status: Wrong Answer
H, N = map(int, input().split())

count = 0
i = 0
arr = list(map(int, input().split()[:N]))
attack = H

for i in range(N):
    attack = attack - arr[i]
    print(attack)
    i = i + 1
    count = count + 1

if count > 1 and attack <= 0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np

#  = input()
#  = int(input())
X, Y, Z = map(int, input().split())
print(Z, X, Y)
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()
# Judge status: Accepted
N, K, S = map(int,input().split())

if S != 10**9:
  res = [S]*K + [10**9]*(N-K)
else:
  res = [10**9]*K + [1]*(N-K)
  
print(*res)
# Judge status: Wrong Answer
from random import random
print(['Yes', 'No'][random() < 0.5])
# Judge status: Accepted
H, W = map(int, input().split())
if H == 1 or W == 1:
    ans = 1
else:
    ans = W * (H//2) + (W + 1) // 2 * (H % 2)
print(ans)
# Judge status: Wrong Answer
# A - Frog1
import numpy as np

N = int(input())
h = list(map(int, input().split()))
dp = [10000]*(N+2)
dp[0] = 0

for i in range(N):
    if i+1<N:
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
    if i+2<N:
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))
print(dp[N-1])
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

import math
g = math.gcd(a[0], a[1])
for i in range(2, n):
    g = math.gcd(g, a[i])

print(g)
# Judge status: Accepted
x = int(input())
print('Yes' if x >= 30 else 'No')
# Judge status: Accepted
n=int(input())

l=[]
for i in range(n):
 s,p=input().split()
 p=int(p)
 l.append([s,p,i])
l.sort()
l.append(['',0,0])

b_name=l[0][0]
t_list=[]

for name, point, inx in l:
 if name==b_name:
  t_list.append([int(point),inx])
 else:
  t_list.sort(reverse=True)
  for i,j in t_list:
   print(j+1)
  t_list=[]
  t_list.append([int(point),inx])
  b_name=name
# Judge status: Wrong Answer
# import re
S = input()
cnt = 0

multiple = [2019]
i = 2
while multiple[-1] < 200000:
    multiple.append(2019 * i)
    i += 1
multiple.pop()
multiple = [str(i) for i in multiple]

# cnt = len(re.findall('18171', S))
# print(cnt)

for i in range(len(S)):
    for j in multiple:
        if j in S[i:i+len(j)]:
            cnt += 1

print(cnt)
# Judge status: Accepted
n, m = map(int, input().split())
nums = [0, 1]
broken = set()
for i in range(m):
    broken.add(int(input()))
def fib(n):
    for i in range(n):
        if i+1 in broken:
            nums.append(0)
        else:
            a = nums[i]
            b = nums[i+1]
            nums.append((a+b)%1000000007)
    return nums[-1]
print(fib(n))
# Judge status: Accepted
s=input()
while len(s)>7:
    if s[-7:]=="dreamer":
        s=s[:-7]
    elif s[-5:]=="dream":
        s=s[:-5]
    elif s[-6:]=="eraser":
        s=s[:-6]
    elif s[-5:]=="erase":
        s=s[:-5]
    else:
        break
if s in ["dreamer","dream","eraser","erase"]:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
a, b = map(int, input().split())
if a <= 5:
    print(0)
elif a <= 12:
    print(b // 2)
else:
    print(b)
# Judge status: Accepted
N,M=map(int,input().split())
ab=[]
for i in range(N):
  ab.append(list(map(int,input().split())))
cd=[]
for i in range(M):
  cd.append(list(map(int,input().split())))
for i in ab:
  l=[]
  for j in cd:
    l.append(abs(i[0]-j[0])+abs(i[1]-j[1])) 
  print(l.index(min(l))+1)
# Judge status: Accepted
n, a, b = map(int, input().split())

if(b < a):
    swap(a, b)

ans = -1
if a%2 == b%2:
    ans = (b - a) // 2

else:
    x = a + (b - a) // 2
    a = n - a + 1
    b = n - b + 1
    y = a + (b - a) // 2
    ans = min(x, y)

print(ans)
# Judge status: Accepted
N = int(input())
ans=0
for i in range(1,N+1):
    if len(str(i))%2!=0:
        ans+=1
print(ans)
# Judge status: Wrong Answer
import sys
n, m = map(int, input().split())
 
g = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    g[u-1].append(v-1)
    g[v-1].append(u-1)

for i in g[0]:
    for n in g[i]:
        print('POSSIBLE')
        sys.exit()

print('IMPOSSIBLE')
# Judge status: Wrong Answer
N, M = map(int, input().split(" "))

m = {}
ans = []
for i in range(1, N + 1):
	m[i] = []
for i in range(M):
	p, y = map(int, input().split(" "))
	ans.append((p,y))
	m[p] = m[p] + [y]

l = {}
for k,v in m.items():
	for i, v in enumerate(sorted(v)):
		l[k, v]  = "{:0>6}{:0>6}".format(k, i)

for k in ans:
	print(l[k])