Harryxun/stf_run huggingface dataset:
h, w, d = map(int, input().split())
a = []
for i in range(h):
    a+=list(map(int, input().split()))
n = len(a)
q = int(input())
max_dbl_line = 10

def dist(i, j):
    dw = abs(i%w - j%w)
    dh = abs(i//w - j//w)
    return dw + dh

# ダブンリングテーブル作成
dbl = [[0] * n for i in range(max_dbl_line)]
tmp = []
for i in range(n):
    if a[i]+d in a:
        next_node = a.index(a[i]+d)-1
    else:
        next_node = -1
    if next_node!=-1:
        next_d = dist(a.index(i+1)-1, next_node)
    else:
        next_d = float('inf')
    tmp.append((next_node, next_d))
dbl[0] = tmp
for i in range(max_dbl_line-1):
    temp = []
    for j in range(n):
        next_node = dbl[i][dbl[i][j][0]][0]
        next_d = dbl[i][j][1]+dbl[i][dbl[i][j][0]][1]
        temp.append((next_node, next_d))
    dbl[i+1] = temp

def f(l, r):
    cnt = (r-l)//d
    ret = 0
    now = a.index(l)-1
    if cnt==0:
        return ret
    for i in range(max_dbl_line):
        if cnt & 1<<i:
            ret+=dbl[i][now][1]
            now = now + d*2**i
    return ret

for i in range(q):
    l, r = map(int, input().split())
    print(f(l,r))

### FIXED CODE ###

import sys
input = sys.stdin.readline

h, w, d = map(int, input().split())
n = h*w
a = [0]*n
for i in range(h):
    t = list(map(int, input().split()))
    for j in range(w):
        a[w*i+j] = t[j]-1

def dist(i, j):
    dh = abs(i//w - j//w)
    dw = abs(i%w - j%w)
    return dh + dw

idx_list = [0] * n
for i in range(n):
    idx_list[a[i]] = i

dist_list = [0]*n
for i in range(n):
    if i < d:
        dist_list[i] = 0
    else:
        dist_list[i] = dist_list[i-d] + dist(idx_list[i-d], idx_list[i])

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    l-=1; r-=1
    print(dist_list[r] - dist_list[l])
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	start=0
	for i in A:
		if i<=0:
			start+=1
		else:
			break
	B=A[start:len(A)+1]
	end=len(B)
	MAX=[0]*end
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(B[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

### FIXED CODE ###

while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))
a, b, c, x = map(int, input().split())
count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                count += 1
print(count)

### FIXED CODE ###

a, b, c, x = [int(input()) for _ in range(4)]
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1
print(count)
s=input()
m=len(s)
if n<2019:
    print(0)
    exit()
from collections import Counter
c=Counter()
tmp=""
c[0]+=1
for i in s[::-1]:
    tmp=i+tmp
    c[int(tmp)%2019]+=1

ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)


### FIXED CODE ###

s=[int(j) for j in input()][::-1]
c=[0]*2019
tmp=0
c[0]+=1
t=1
import numpy as np
for i in s:
    tmp+=t*i
    c[tmp%2019]+=1
    t=t*10%2019
c=np.array(c)
ans=c*(c-1)//2
print(ans.sum())
s = input()

if len(c) < 26:
    for i in "abcdefghijklmnopqrstuvwxyz":
        if not i in s:
            ans = s + i
            break

else:
    tmp = ""
    ss = list(s)
    for i in range(len(ss)):
        if i == 0:
            tmp += ss.pop()
            continue

        if ss[-1] > tmp[-1]:
            tmp += ss.pop()
        else:
            ss.pop()
            ans = "".join(ss) + min(tmp)
            break
    else:
        ans = -1

print(ans)


### FIXED CODE ###

s = input()
alp = "abcdefghijklmnopqrstuvwxyz"

if len(s) < 26:
    for i in alp:
        if not i in s:
            ans = s + i
            break

else:
    tmp = []
    ss = list(s)
    for i in range(len(ss)):
        if i == 0:
            tmp.append(ss.pop())
            continue

        if alp.index(ss[-1]) > alp.index(tmp[-1]):
            tmp.append(ss.pop())
            continue
        else:
            remove = ss.pop()
            tmp.sort()
            for j in tmp:
                if j > remove:
                    renew = j
                    break
            ans = "".join(ss) + renew
            break
    else:
        ans = -1

print(ans)
a,b=map(int,input().split())
import math
def x (a,b):
    return(a*b)//math.gcd(a,b)
print(x(a,b))


### FIXED CODE ###

A, B = map(int, input().split())
AA = A
BB = B
lcm = 1
cont = 1

while cont == 1:
  if A % B == 0 or B % A == 0:
    lcm = min(A, B)
    break
  
  if A < B:
    B = B % A
  elif A > B:
    A = A % B

ans = int(AA * BB / lcm)
print(ans)
N=int(input())
A=list(map(int,input().split())
B=[0]
for i in range(N):
  B+=[B[i]+A[i]]
C=[]
asn+=1      
for i in B:
  if i in C:
     ans+=1
  else:
     C+=[i]
print(ans)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[0]
for i in range(N):
  B+=[B[i]+A[i]]
C=[]
ans=0      
B.sort()
c=1
for i in range(1,N+1):
  if B[i]==B[i-1]:
    c+=1
  else:
    ans+=c*(c-1)//2
    c=1
ans+=c*(c-1)//2
print(ans)
a = input()
b = input()

T=1000
ans = 0
for i in range(len(a)-len(b)+1):
  for j in range(len(b)):
    if a[i+j]=!b[j]:
      ans +=1
      ans = min(T, ans)
print(ans)
        
  

### FIXED CODE ###

a = input()
b = input()

T=1000

for i in range(len(a)-len(b)+1):
  ans = 0
  for j in range(len(b)):
    if a[i+j]!=b[j]:
      ans +=1
  T = min(T, ans)
print(T)
n,a,b,c,d=map(int,input().split())
res=list(input())
if c<d:
    for i in range(1,n):
        if res[i-1]=="#" and res[i]=="#":
            print("No")
            exit()
    print("Yes")
    exit()

print(res[n+6])

# for i in range(b,d+1):
#     if i==1:
#         continue
#     if res[i-2]=="." and res[i-1]=="." and res[i]==".":
#         print("Yes")
#         exit()
#     if res[i-1]=="#" and res[i]=="#":
#         print("No")
#         exit()
        
# print("No")
# exit()


### FIXED CODE ###

n,a,b,c,d=map(int,input().split())
res=list(input())
if c<d:
    for i in range(a,d+1):
        if res[i-1]=="#" and res[i]=="#":
            print("No")
            exit()
    print("Yes")
    exit()

for i in range(b,d+1):
    if i==1:
        continue
    if res[i-2]=="." and res[i-1]=="." and res[i]==".":
        print("Yes")
        exit()
    if res[i-1]=="#" and res[i]=="#":
        print("No")
        exit()
        
print("No")
exit()
n = map(int, input())
count = 0
for i in range(n[0]):
  a, b = map(int, input())
  r = (a **2 + b ** 2) ** 0.5
  if r <= n[1]:
    count += 1
print(count)
  

### FIXED CODE ###

N, D = map(int, input().split())
count = 0
for i in range(N):
  a, b = map(int, input().split())
  r = (a **2 + b ** 2) ** 0.5
  if r <= D:
    count += 1
print(count)
num, 
bricks,
count, 
smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: 
      count = 1
    else: 
      smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

### FIXED CODE ###

num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: 
      count += 1
    else: 
      smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)
x = input()
if x>= 30:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

x = int(input())
if x >= 30:
    print("Yes")
else:
    print("No")
import sys
sys.setrecursionlimit(100000000)

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

A = [0]*M

for i in range(M):
    A[i] = int(input())

A.append(N+1)

# DP version
DP = [0]*N
DP[0] = 1
# １段の階段を登るやり方の数
DP[1] = 1
# 2段の階段を登るやり方の数
DP[2] = 2

for i in range(3,N):
    DP[i] = DP[i-1] + DP[i-2]

def step_comb(L):
    if DP[L]>0:
        return DP[L]
    DP[L] = step_comb(L-1) + step_comb(L-2)
    return DP[L]
    
total_comb = 1
NOW = 0
for a in A:
    if NOW == a:
        print(0)
        sys.exit()
    L = a-1-NOW
    total_comb *= step_comb(L)
    NOW = a + 1
    
print(total_comb % 1000000007 )


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)

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

if M == 0:
    A = []
else:
    A = [0]*M
    for i in range(M):
        A[i] = int(input())

A.append(N+1)

# DP version
DP = [0]*(N+1)
DP[0] = 1
# １段の階段を登るやり方の数
DP[1] = 1
# 2段の階段を登るやり方の数
#DP[2] = 2

for i in range(2,N+1):
    DP[i] = DP[i-1] + DP[i-2]

def step_comb(L):
    if DP[L]>0:
        return DP[L]
    DP[L] = step_comb(L-1) + step_comb(L-2)
    return DP[L]
    
total_comb = 1
NOW = 0
for a in A:
    if NOW == a:
        print(0)
        sys.exit()
    L = a-1-NOW
    total_comb *= step_comb(L)
    NOW = a + 1
    if NOW == N:
        break
    
print(total_comb % 1000000007 )
a,b = map(int, input().split())
d=a//b
r=a%b
f=a/b
print(d,r,f)


### FIXED CODE ###

a,b,c = map(int, input().split())
d=0
for i in range(a,b+1):
  if c%i==0:
    d=d+1
print(d)
import math

def prime(x):
    if x==1:
        prime=False
    else:
        prime=True
        for i in range(2,int(math.sqrt(x)+1)):
            if x%i==0:
                prime=False
                break
    return prime

def count_prime(N):
    if prime(N): #初期値が素数の場合
        big_prime=True
        
    else:　#初期値が素数でない場合
        big_prime=False
        rtN_init=int(math.sqrt(N)+1)
        p=[0 for n in range(int(math.sqrt(N)+1))]
        
        #素因数分解。ルートＮまでの範囲で素因数を探す。見つかったらpの素因数インデックスを++
        while N>1 and prime(N)==False:
            rtN=int(math.sqrt(N)+1)
            for i in range(2,rtN+1):
                if N%i==0 and prime(i):
                    p[i]+=1
                    N=N//i
                    break
        #素因数がルートNより大きい場合の処理
            if prime(N) and N>rtN_init:
                big_prime=True
    return p,big_prime

def main():
    N=int(input())
    p,q=count_prime(N)
    cnt=0
    
    for n in range(len(p)):
        num=1
        while p[n]>=1:
            p[n]-=num
            if p[n]>=0:
                cnt+=1
                num+=1
    if q==True:
        cnt+=1
    print(cnt)
        
if __name__=="__main__":
    main()
    

### FIXED CODE ###

import math

def prime(x):
    if x==1:
        prime=False
    else:
        prime=True
        for i in range(2,int(math.sqrt(x)+1)):
            if x%i==0:
                prime=False
                break
    return prime

def count_prime(N):
    p=[0 for n in range(int(math.sqrt(N)+1))]
    
    if prime(N):#初期値が素数の場合
        big_prime=True
        
    else:#初期値が素数でない場合
        big_prime=False
        rtN_init=int(math.sqrt(N)+1)
        
        #素因数分解。ルートＮまでの範囲で素因数を探す。見つかったらpの素因数インデックスを++
        while N>1:
            #素数がルートNを超える場合
            if prime(N) and N>rtN_init:
                big_prime=True
                break
            else:
                for i in range(2,rtN_init):
                    if N%i==0 and prime(i):
                        p[i]+=1
                        N=N//i
                        break
    return p,big_prime

def main():
    N=int(input())
    p,q=count_prime(N)
    cnt=0
    
    for n in range(len(p)):
        num=1
        while p[n]>=1:
            p[n]-=num
            if p[n]>=0:
                cnt+=1
                num+=1
    if q==True:
        cnt+=1
    print(cnt)
        
if __name__=="__main__":
    main()
n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
g = [0 for i in range(n)]
 
 
def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
     
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
 
def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
 
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(g[1]):
        a[G[0]-1][g[2+j]-1] = 1

int main

### FIXED CODE ###

n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
g = [0 for i in range(n)]
 
 
def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
     
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]
 
def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
 
for i in range(n):
    g = map(int, raw_input().split())
    for j in range(g[1]):
        a[g[0]-1][g[2+j]-1] = 1
 
main()
h=list(map(int,input().split()))
l=[0]
c='plus'
for i in range(n-1):
    if c=='minus' and h[i]<=h[i+1]:
        l.append(i)
    if h[i]<=h[i+1]:c='plus'
    else:c='minus'

w=0
m=0
for i in range(len(l)-1):
    w+=max(h[l[i]:l[i+1]+1])-m
    m=h[l[i+1]]
w+=max(h[l[-1]:n])-m
print(w)

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
l=[0]
c='plus'
for i in range(n-1):
    if c=='minus' and h[i]<=h[i+1]:
        l.append(i)
    if h[i]<=h[i+1]:c='plus'
    else:c='minus'

w=0
m=0
for i in range(len(l)-1):
    w+=max(h[l[i]:l[i+1]+1])-m
    m=h[l[i+1]]
w+=max(h[l[-1]:n])-m
print(w)
n, x = map(int, input().split())
l = list(map(int, input().split()))
total = 0

for i in range(n - 1):
    sub = l[i] + l[i+1]
    if sub > x:
        total += sub - x
        l[i+1] -= sub - x
        if l[i+1] > x:
            l[i] -= l[i+1] - x
            total += l[i+1 - x]




print(total)

### FIXED CODE ###

n, x = map(int, input().split())
l = list(map(int, input().split()))
total = 0

for i in range(n - 1):
    diff = l[i] + l[i+1] - x
    if diff > 0:
        total += diff
        if diff > l[i+1]:
            l[i+1]=0
        else:
            l[i+1] -= diff

print(total)
X = 2*3.1415926535*R
print(X)

### FIXED CODE ###

import math
R = int(input())
print(2*math.pi*R)
import sys
n = int(input())
a = list(map(int, input().split(' ')))

a.sort()
a.append(-1)
counter = 0
b = []
for i in range(n+1):
    if a[counter] == a[i]:
        continue
    else:
        b.append([a[counter], i-counter])
        counter = i
odd = 0
if n%2 == 1:
    if b[0][0] == 0 and b[0][1] == 1:
        b[0][1] += 1
        n += 1
        odd = 1
    else:
        print(0)
        sys.exit()
if odd:
    for i in range(int(n//2)):
        if b[i][0] == i*2 and b[i][1] == 2:
            continue
        else:
            print(0)
            sys.exit()
else:
    for i in range(int(n//2)):
        if b[i][0] == i*2+1 and b[i][1] == 2:
            continue
        else:
            print(0)
            sys.exit()
if odd:
    print(int(2**(n/2 -1)%(10**9 + 7)))
else:
    print(int(2**(n/2)%(10**9 + 7)))

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int, input().split(' ')))

a.sort()
if n%2 == 0:
    for i in range(n-1):
        if i%2 == 0:
            if a[i] == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
        else:
            if a[i]+2 == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
    result = 2 ** (n//2)
    print(result % (10**9+7))
else:
    if a[0] == 0:
        for i in range(1, n-1):
            if i%2 == 1:
                if a[i] == a[i+1]:
                    continue
                else:
                    print(0)
                    sys.exit()
            else:
                if a[i]+2 == a[i+1]:
                    continue
                else:
                    print(0)
                    sys.exit()
        result = 2**((n-1)//2)
        print(result %(10**9+7))
    else:
        print(0)
        sys.exit()
i=1
while True:
    x=int(input())"文字列なのでint()でキャスト"
    if(x==0) break
    print(f"Case {i}:{x}")
    i=i+1



### FIXED CODE ###

i=0
while True:
    x=int(input()) 
    if(x==0):
        break 
    i=i+1
    print(f"Case {i}: {x}")
import math
X = int(input())


def fif_root(n):
    return math.pow(n, 1/5)


a = 0
while True:
    A = math.pow(a, 5)
    b = list(map(lambda x: fif_root(x), [abs(X-A), X+A]))
    if True in (c := list(map(lambda x: x.is_integer(), b))):
        idx = c.index(True)
        b = b[idx]
        if ind == 1:
            a, b = -a, -int(b)
        else:
            if X - A > 0:
                b = -int(b)
            else:
                b = int(b)
        break
    a += 1
print(a, b)


### FIXED CODE ###

import math
X = int(input())


def fif_root(arg):
    def root(x):
        return math.floor(math.pow(x,1/5)*pow(10,10))/pow(10,10)
    return list(map(lambda x: root(x), arg))

def check_integer(arg):
    return list(map(lambda x: x.is_integer(), arg))

a = 0
while (A:= math.pow(a, 5))-math.pow(a-1, 5) <= X:
    #a,-aの時それぞれの5乗根を計算する。
    root = fif_root([abs(X-A), X+A])
    if True in (c := check_integer(root)):
        idx = c.index(True)
        b = int(root[idx])
        if idx == 1:
            a, b = -a, -b
        else:
            if X - A >= 0:
                b = -b
        print(a, b)
        break
    a += 1
n, M, k = map(int,input().split())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
read_a = [0]*n
read_b = [0]*M
time = 0
ans = 0
memo = 0
for j in range(n):
    if time + a_l[j] <= k:
        time += a_l[j]
        read_a[j] = 1
        memo = j
        ans = j+1
    else:
        break

kotae = [ans]


def dfs(i,a,t,m):
    global kotae
    if i < M:
        if b_l[i] + t <= k:
            tt = t + b_l[i]
            aa = a + 1
            kotae.append(aa)
            ii = i+1
            mm = m
            #print(aa)
            dfs(ii,aa,tt,mm)
            
        else:
            if m >= 0:
                tt = t - a_l[m]
                mm = m - 1
                aa = a - 1
                ii = i
                dfs(ii,aa,tt,mm)
            


dfs(0,ans,time,memo)


print(max(kotae))
    





### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n, M, k = map(int,input().split())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
read_a = [0]*n
read_b = [0]*M
time = 0
ans = 0
memo = -1
for j in range(n):
    if time + a_l[j] <= k:
        time += a_l[j]
        read_a[j] = 1
        memo = j
        ans = j+1
    else:
        break

kotae = [ans]


def dfs(i,a,t,m):
    global kotae
    if i < M:
        if b_l[i] + t <= k:
            tt = t + b_l[i]
            aa = a + 1
            kotae.append(aa)
            ii = i+1
            mm = m
            #print(aa)
            dfs(ii,aa,tt,mm)
            
        else:
            if m >= 0:
                tt = t - a_l[m]
                mm = m - 1
                aa = a - 1
                ii = i
                dfs(ii,aa,tt,mm)
            


dfs(0,ans,time,memo)


print(max(kotae))
# -*- coding: utf-8 -*-


def insertion_sort(n, A):
    for i in xrange(1, len(A)):
        key = A[i]
        j = i - 1
        while j >= 0 and A[j] > key:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = key

if __name__ == "__main__":
    n = int(raw_input())
    A = raw_input().split(" ")
    A = map(int, A)
    insertion_sort(n, A)
    print " ".join(A).strip()

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

def main():
	num = int(raw_input())
	list = map(int, raw_input().split())
	sort(num, list)

def sort(num, list):
	output(list)
	for i in range(1, num):
		key = list[i]
		j = i - 1
		while j >= 0 and list[j] > key:
			list[j+1] = list[j]
			j -= 1
		list[j+1] = key
		output(list)
def output(list):
	print " ".join(map(str, list))
			


if __name__ == "__main__":
	main()
while True:

    H, W =(int(i) for i in input().split())
    line1, line2 = "", ""
    line3, line4 ="#", "."
    if W % 2 == 0:
        for i in range(W//2):
            line1 += "#."
            line2 += ".#"
        if H % 2 == 0:
            for i in range(H//2):
                print (line1)
                print (line2)
            print()
        else:
            print(line1)
            for i in range(H//2):
                print(line2)
                print(line1)
            print()
            
    elif H == 0 and W ==0:
        break
    
    else:
        for i in range(W//2):
            line3 += ".#"
            line4 += "#."
        if H % 2 == 0:
            for i in range(H//2):
                print (line3)
                print (line4)
            print()
        else:
            print(line3)
            for i in range(H//2):
                print(line4)
                print(line3)
            print()

### FIXED CODE ###

while True:

    H, W =(int(i) for i in input().split())
    line1, line2 = "", ""
    line3, line4 ="#", "."
    if H == 0 and W ==0:
        break
    
    elif W % 2 == 0:
        for i in range(W//2):
            line1 += "#."
            line2 += ".#"
        if H % 2 == 0:
            for i in range(H//2):
                print(line1)
                print(line2)
            print()
        else:
            print(line1)
            for i in range(H//2):
                print(line2)
                print(line1)
            print()
            
    
    
    else:
        for i in range(W//2):
            line3 += ".#"
            line4 += "#."
        if H % 2 == 0:
            for i in range(H//2):
                print (line3)
                print (line4)
            print()
        else:
            print(line3)
            for i in range(H//2):
                print(line4)
                print(line3)
            print()
h, w =map(int,input().split())

if h == 1 or w == 1:
  print(1)
else:
  if (h * w) % 2 == 0:
    print((h * w) // 2)
  elif:
    print(((h * W) // 2) + 1)
  


### FIXED CODE ###

h, w =map(int,input().split())

if h == 1 or w == 1:
  print(1)
else:
  if (h * w) % 2 == 0:
    print((h * w) // 2)
  else:
    print(((h * w) // 2) + 1)
n,a.b = map(int,input().split())

print(min(n*a,b))

### FIXED CODE ###

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

print(min(n*a,b))
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
    
counter = 0
sum = 0

for i in range(len(l)):
    if lcm // int(l[i]) % 2 == 1:
        counter += 1
        
if counter == len(l):
    sum += 1

x = m // (int(lcm)/2)
y = m // lcm
print(int(x-y))

### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def div_ceil(x, y): return (x + y - 1) // y
 
N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = A[0]
for a in A[1:]:
    L *= a // gcd(L, a)
for a in A:
    if (L // a) % 2 == 0:
        ans = 0
        break
else:
    ans = div_ceil(M // L, 2)
print(ans)
import random
list = []
for i in range(31):
  list.append(random.randint(0,10000))
K = int(input())
print(list[K-1])


### FIXED CODE ###

list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(list[K-1])
import numpy as np
N, M = map(int, input().split())
A = np.array(np.log2(sorted(list(map(int, input().split())), reverse=True)).astype(np.float64))
#print(A)
while True:
    A_m = np.where(A >= int(A[0]))
    if len(A_m[0]) <= M:
        A[A_m] -= 1.
        A = np.sort(A)[::-1]
        M -= len(A_m[0])
        #print(A, M)
    else:
        A[:M] -= 1.
        break
    if A[0] < 0:
        break
#print(A)
A = (2 ** A).astype(np.int64)
#print(A)
print(np.sum(A))

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
A = [-int(i) for i in input().split()]
heapq.heapify(A)
for i in range(M):
    a = -int(heapq.heappop(A) / 2)
    heapq.heappush(A, -a)
print(-sum(A))
d = dict()

def getv():
  M = int(input())
  for x in range(M):
    n = input()
    if d.get(n) is None:
      d[n] = 0
    d[n] += 1

getv(1)
getv(-1)

print(sorted(d, key=lambda x:x[1], reverse=True)[0])

### FIXED CODE ###

d = dict()

def getv(a):
  M = int(input())
  for x in range(M):
    n = input()
    if d.get(n) is None:
      d[n] = 0
    d[n] += a

getv(1)
getv(-1)

print(max(0,d[sorted(d, key=lambda x:d[x], reverse=True)[0]]))