Harryxun/stf_run huggingface dataset:
# coding: utf-8
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()

def min_max(arr):
    """リストの中を二つに分けて、総和の小さい方と大きい方を返す"""
    left = 0; right = len(arr)-1
    l_total = arr[left]
    r_total = arr[right]
    while left + 1 < right:
        if l_total <= r_total:
            left += 1
            l_total += arr[left]
        else:
            right -= 1
            r_total += arr[right]
    mi, ma = min(l_total, r_total), max(l_total, r_total)
    return mi, ma

answer = 10 ** 15
mid = N // 2
used = set()

def F(l, mid, r):
    global answer, used
    used.add(mid)
    l_min, l_max = min_max(A[:mid])
    r_min, r_max = min_max(A[mid:])
    temp = max(l_max, r_max) - min(l_min, r_min)
    if temp < answer:
        answer = temp
    if l_min <= r_min:
        m = (mid+r)//2
        if m not in used:
            F(mid, m, r)
    else:
        m = (mid+l)//2
        if m not in used:
            F(l, m, mid)
    if l_max >= r_max:
        m = (mid+l)//2
        if m not in used:
            F(l, m, mid)
    else:
        m = (mid+r)//2
        if m not in used:
            F(mid, m, r)

F(0, mid, N-1)
print(answer)
# 08

### FIXED CODE ###

# coding: utf-8
import sys
from itertools import accumulate

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
Acum = list(accumulate(A))
l_cut = [None] * N  # 左のリストで2つに切り分けるindex
l_cut[1] = 0
l = A[0]; r = A[1]
for i in range(2, N):
    r += A[i]
    diff = abs(r-l)
    index = l_cut[i-1]
    while index < i - 1:
        temp = abs(l + A[index+1] - (r - A[index+1]))
        if temp < diff:
            index += 1
            l += A[index]
            r -= A[index]
            diff = temp
        else:
            break
    l_cut[i] = index

r_cut = [None] * N
r_cut[-2] = N-2
l = A[-2]; r = A[-1]
for i in range(N-3, 0, -1):
    l += A[i]
    diff = abs(r-l)
    index = r_cut[i+1]
    while index > i:
        temp = abs(r + A[index] - (l - A[index]))
        if temp < diff:
            index -= 1
            r += A[index+1]
            l -= A[index+1]
            diff = temp
        else:
            break
    r_cut[i] = index

answer = 10 ** 17
for i in range(1, N-2):
    a = Acum[l_cut[i]]
    b = Acum[i] - a
    c = Acum[r_cut[i+1]] - Acum[i]
    d = Acum[-1] - (a + b + c)
    temp = max(a, b, c, d) - min(a, b, c, d)
    if temp < answer:
        answer = temp

print(answer)
# 27r
N = int(input())
C = list(map(int,input().split()))
C.sort(reverse=True)
MOD = 10**9+7

ans = 0
d = pow(2,N-2,MOD)
base = pow(2,N-1,MOD)
for i,c in enumerate(C):
    ans += c * (base + i*d)
ans *= pow(2,N,MOD)
ans %= MOD
print(ans)

### FIXED CODE ###

N = int(input())
C = list(map(int,input().split()))
C.sort(reverse=True)
MOD = 10**9+7
if N==1:
    print((C[0]*2)%MOD)
    exit()

ans = 0
d = pow(2,N-2,MOD)
base = pow(2,N-1,MOD)
for i,c in enumerate(C):
    ans += c * (base + i*d)
ans *= pow(2,N,MOD)
ans %= MOD
print(ans)
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, K = map(int, input().split())
cmb_val = cmb(N-1,2)
ma = (N-1)*(N-2)/2

if ma < K:
  print('-1')
else:
  a =[(1, i) for i in range(2, N+1)]
  
  b = [(i, j) for i in range(2, N+1) for j in range(i+1, N+1)]
  a.extend(b[:cmb_val-K])
      
print(len(a))
for i in range(len(a)):
  print(a[i][0], a[i][1])
  
  

### FIXED CODE ###

from operator import mul
from functools import reduce

def cmb(n,r):
  if n < r:
    return 0
  else:
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

N, K = map(int, input().split())
ma = (N-1)*(N-2)/2

if ma < K:
  print('-1')
else:
  cmb_val = cmb(N-1,2)
  a =[(1, i) for i in range(2, N+1)]
  b = [(i, j) for i in range(2, N+1) for j in range(i+1, N+1)]
  a.extend(b[:cmb_val-K])
      
  print(len(a))
  for i in range(len(a)):
    print(a[i][0], a[i][1])
n=int(input())
x=[]
u=[]
for i in range(n):
  x.append(int(input()))
  u.append(str(input()))
ans=0
for j in range(n):
  if u[j]=="JPY":
    ans+=x[j]
  else:
    ans+=x[j]*380000
print(ans)    
  


### FIXED CODE ###

n=int(input())
x=list(input().split() for _ in range(n))
ans=0
for i in range(n):
  if str(x[i][1])=="JPY":
    ans+=float(x[i][0])
  else:
    ans+=float(x[i][0])*380000
    
print(ans)
YYMM = False
MMYY = False
f = input()
h1 = f[0] + f[1]
h2 = f[2] + f[3]

if 1 <= h2 <= 12:
  YYMM = True
if 1 <= h1 <= 12:
  MMYY = True

def ret(c1,c2):
  if c1 and c2:
    return "AMBIGUOUS"
  elif c1:
    return "YYMM"
  elif c2:
    return "MMYY"
  else:
    return "NA"
  
print(ret(YYMM,MMYY))

### FIXED CODE ###

YYMM = False
MMYY = False
f = input()
h1 = f[0] + f[1]
h2 = f[2] + f[3]

if 1 <= int(h2) <= 12:
  YYMM = True
if 1 <= int(h1) <= 12:
  MMYY = True

def ret(c1,c2):
  if c1 and c2:
    return "AMBIGUOUS"
  elif c1:
    return "YYMM"
  elif c2:
    return "MMYY"
  else:
    return "NA"
  
print(ret(YYMM,MMYY))
import fileinput
for line in fileinput.input():
    a = line.split()
    b = input().split()
    hit = 0
    blow = 0
    for i in range(4):
        for j in range(4):
            if a[i] == b[j]:
                if i == j:
                    hit += 1
                else:
                    blow += 1
    print(hit, blow)

### FIXED CODE ###

import sys
for line in sys.stdin:
    hit = 0
    blow = 0
    if line == "\n":
        break
    A = line.split()
    B = [n for n in input().split()]
    for i in B:
        if i in A:
            if A.index(i) == B.index(i):
                hit += 1
            else:
                blow += 1
    print(hit, blow)
S = input()

K = int(input())

tmp = 0
index = 0
res = ""

while K > tmp:
    if S[index] == "1":
        res = "1"
    else:
        res = S[index]
        break;
    index += 1

print(res)

### FIXED CODE ###

S = input()

K = int(input())

index = 0
res = ""

while K > index and index < len(S):
    if S[index] == "1":
        res = "1"
    else:
        res = S[index]
        break;
    index += 1

print(res)
in_rating = 0
N = int(input())
R = int(input())

if N >= 10:
  in_rating = R
  print(in_rating)
else:
  in_rating = R + 100 * (10-N)
  print(in_rating)


### FIXED CODE ###

n,r=map(int,input().split())

if n >= 10:
  print(r)
else:
	in_rate = r + 100 * (10-n)
	print(in_rate)
n=int(input())
l=[]
sum=0
for i in range(1,n+1):
         if  i%3==0 and i%5 ==0:
                    l.apoend("FizzBuzz")
         elif i%3==0 and i%5!=0:
                    l.append("Fizz")
         elif i%5==0 and i%3!=0:
                    l.append("Buzz")
         else:
                    l.append(i)
                    sum+=i
print(sum)
         
                   


### FIXED CODE ###

n=int(input())
l=[]
sum=0
for i in range(1,n+1):
         if i%3!=0 and i%5!=0:
                    l.append(i)
                    sum+=i
print(sum)
import heapq

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

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

ans = 0
for i in range(1, K+1):
    if i > 50:
        continue
    for j in range(i+1):
        tmp = 0
        q = V[:j] + V[N-i+j:]
        heapq.heapify(q)
        for _ in range(min(i, K-i)):
            tmp_min = heapq.heappop(q)
            ans = max(ans, sum(q))
            if tmp_min > 0:
                ans = max(ans, sum(q)+tmp_min)
                break

print(ans)

### FIXED CODE ###

import heapq

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

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

ans = 0
for i in range(1, K+1):
    if i > N:
        continue
    for j in range(i+1):
        tmp = 0
        q = V[:j] + V[N-i+j:]
        heapq.heapify(q)
        for _ in range(min(i, K-i)):
            tmp_min = heapq.heappop(q)
            ans = max(ans, sum(q))
            if tmp_min > 0:
                ans = max(ans, sum(q)+tmp_min)
                break
        ans = max(ans, sum(q))

print(ans)
S = input()
if len(S) == 2:
	print(S)
elese:
	S = S[::-1]
	print(S)

### FIXED CODE ###

S = input()
if len(S) == 2:
	print(S)
else:
	S = S[::-1]
	print(S)
s=int(input())
ans=0
for i in range(len(s)-1):
  if not s[i]-1<=s[i+1]:
    print("No")
    exit()
print("Yes")

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
base=0
for h in H:
    if base>h:
        print("No")
        break
    base=max(base,h-1)
else:
    print("Yes")
n = int(input())
lst = []
for i in range(n):
  if i % 2 == 1:
    lst.append(i)
print(n/len(lst))

### FIXED CODE ###

n = int(input())
lst = []
for i in range(1, n+1):
  if i % 2 == 1:
    lst.append(i)
print(len(lst)/n)
a = int(input())
b = int(input())
c = int(input())
d = int(input())

while a>0 and c>0:
  if c>0:
    c += -b
    
  if c<=0:
    break
    print("Yes")
    
  if a>0:
    a += -d
    
  if a<=0:
    break
    print("No")

### FIXED CODE ###

a,b,c,d = map(int,input().split())
 
while a>0 and c>0:
  if c>0:
    c += -b
    
  if c<=0:
    print("Yes")
    break
    
    
  if a>0:
    a += -d
    
  if a<=0:
    print("No")
    break
n,k = map(int,input().split())
arr = sorted(list(map(int,input().split())))
c = {}
num1 = 1
for i in range(k):
    c[num1] = 0
    num1 *= 2
    if num1 > k:
        break
for i in arr:
    num = 1
    while(num<=num1):
        if i%2 > 0:
            c[num] += 1
        num *= 2
        i = i>>1
x = 0
for i in c:
    if c[i]*2 < n:
        x += i
ans = 0
for i in arr:
    ans += x^i
print(ans)

### FIXED CODE ###

from collections import Counter
N,K = map(int,input().split())
sarr = list(map(int,input().split()))
arr = sorted(sarr)
def xsum(arr,n):
    s = 0
    for i in arr:
        s += n^i
    return s
c = Counter()
for i in arr:
    n = 1
    while n <= K:
        if i%2:
            c[n] += 1
        else:
            c[n] += 0
        n *= 2
        i = i >> 1
ans = 0
p = [1]
while(p[-1]*2 <= K):
    p.append(p[-1]*2)
for i in p[::-1]:
    if c[i] < N - c[i]:
        if ans + i <= K :
            ans += i
print(max(xsum(arr,ans),xsum(arr,K)))
n = int(input())
h = map(int, input().split())
sum = 0
max = 0
for i in range(n):
    if max <= h[i]:
        sum += 1
        max = h[i]
print(sum)

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
sum = 0
m = 0
for i in h:
    if m <= i:
        sum += 1
        m = i
print(sum)
A,B = map(int,input().split())
if A%3==0 or B%3==0 or (A+B)%==0:
  print('Possible')
else:
  print('Impossible')

### FIXED CODE ###

A,B = map(int,input().split())
if A%3==0 or B%3==0 or (A+B)%3==0:
    print('Possible')
else:
    print('Impossible')
x=input()
if x>=30 :
　　put('Yes')
  else :
    put('No')

### FIXED CODE ###

x=int(input())
if x>=30:
  print('Yes')   
else:
  print('No')
n = int(input())
ds = [int(x) for x in input().split()]
ds2 = [x*x for x in ds]
s = 0
s2 = 0
for i in range(n):
  s += ds[i]
  s2 += ds2[i]
ss = 0
for i in range(n):
  ss += ds[i] * s

print((ss - s2) / 2 )

### FIXED CODE ###

a,b = [int(x) for x in input().split()]
c = a - 2*b
if c < 0:
  c = 0
print(c)
N, K = map(int,input().split())
edges = []

if K > (N-1)*(N-2)//2:
    print(-1)
else:
    edges.append((1,2))
    for i in range(3, N+1):
        edges.append((2, i))
    sa = (N-1)*(N-2)//2 - K
    for i in range(min(sa, N-2)):
        sa -= 1
        edges.append((1, i+3))
    if sa != 0:
        i = 3
        j = 4
        while sa > 0:
            while j < N and sa > 0:
                edges.append((i, j))
                j += 1
                sa -= 1
            i += 1
            j = i + 1
        print(len(M))
        for i in range(len(edges)):
            print(edges[i][0], edges[i][1])
    else:
        print(len(M))
        for i in range(len(edges)):
            print(edges[i][0], edges[i][1])
    

### FIXED CODE ###

N, K = map(int,input().split())
edges = []

if K > (N-1)*(N-2)//2:
    print(-1)
else:
    edges.append((1,2))
    for i in range(3, N+1):
        edges.append((2, i))
    sa = (N-1)*(N-2)//2 - K
    for i in range(min(sa, N-2)):
        sa -= 1
        edges.append((1, i+3))
    if sa != 0:
        i = 3
        j = 4
        while sa > 0:
            while j <= N and sa > 0:
                edges.append((i, j))
                j += 1
                sa -= 1
            i += 1
            j = i + 1
        print(len(edges))
        for i in range(len(edges)):
            print(edges[i][0], edges[i][1])
    else:
        print(len(edges))
        for i in range(len(edges)):
            print(edges[i][0], edges[i][1])
h,w=map(int,input().split())

m=[input() for i in range(w)]

cnt=[[1000000 for i in range(h)] for j in range(w)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0


print(0)


### FIXED CODE ###

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

m=[input() for i in range(h)]


cnt=[[1000000 for i in range(w)] for j in range(h)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(h):
    for x in range(w):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[h-1][w-1])
n = int(input())
a = input().split()
a_int = list(map(int,a))
col = 400
all_col = 0 
max_c = 8
c= [0,0,0,0,0,0,0,0]
for i in range(n):
    if a_int[i] > max_c * col:
        all_col += 1
    else:
        ii = int(a_int[i]/col)
        if c[ii] < 1:
            c[ii] += 1
        
cnt = c.count(1)
min_c = max(cnt, 1)
 
print(str(min_c)+' ' +str(max_c))


### FIXED CODE ###

from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))


def main():
    n = input()
    a = readLine_int_list()

    c = []
    _c = [] 

    for i in a:
        rank = i//400
        if rank > 7:
           _c.append(rank) 
        else:    
            c.append(rank)
    
    
    p = len(set(c))
    print(max(1,p), p+len(_c))

        
if __name__ == "__main__":
    main()
import math
n=int(input())
n=int(math.log2(n))
ans=2**(n+1)
print(ans-1)

### FIXED CODE ###

import math
n=int(input())
n=int(math.log2(n))
ans=2**(n+1)
print(ans-1)
n = int(input())
L = map(int,input().split())
print("Yes" if max(L)<sum(L)-max(L) else "No")

### FIXED CODE ###

n = int(input())
L = list(map(int,input().split()))
print("Yes" if max(L)<sum(L)-max(L) else "No")
def judge1(Num,a):
    s = []
    for l in range(2,Num):
        if Num%l == 0:
            alpha = list(a)
            j = int(Num/l - 1)
            b = []
            c = []
            for i in range(j+1):
                b.append(alpha[i])
            for k in range(l):
                c = c + b
            if alpha == c:
                s.append(1)
            else:
                s.append(0)
        else:
            s.append(0)
    return s

N = int(input())
S = input()
a = judge1(N,A)
if 1 in a:
    print("yes")
else:
    print("No")

### FIXED CODE ###

def judge(N,str):
    a = list(str)
    b = []
    c = []
    if N%2 == 0:
        for k in range(int(N/2)):
            b.append(a[k])
            c.append(a[k+int(N/2)])
        if b == c:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
N = int(input())
S = input()
judge(N,S)
n,k,x,y=[int(input()) for i in range(n)]
if k<=x:
    print(n*k)
else:
    print(k*x+(n-k)*y)

### FIXED CODE ###

n,k,x,y=[int(input()) for i in range(4)]
if n<=k:
    print(n*x)
else:
    print(k*x+(n-k)*y)
a, b = map(int, input().split())
if b < a:
  a, b = b, a
if if b <= 8 or 16 - b - 2 <= a:
  print('Yay!')
else:
  print(':(')

### FIXED CODE ###

a, b = map(int, input().split())
if a <= 8 and b <= 8:
  print('Yay!')
else:
  print(':(')
s=input();l=[]
for i in range(len(s)-1):
 if s[i]!=s[i+1]:l+=[max(i+1,len(s)-i-1)]
print(min(l))

### FIXED CODE ###

s=input();l=[];n=len(s)
for i in range(n-1):
 if s[i]!=s[i+1]:l+=[max(i+1,n-i-1)]
print(min(l)if l else n)
from itertools import combinations

n = int(input())
d = map(int, input().split(" "))

print(sum(d[a]*d[b] for a, b in combinations(range(n), 2)))

### FIXED CODE ###

from itertools import combinations

def mapt(fn, *args):
    return tuple(map(fn, *args))

n = int(input())
d = mapt(int, input().split(" "))

print(sum(d[a]*d[b] for a, b in combinations(range(n), 2)))
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    link = {}
    for ab in args[1:]:
        a, b = map(int, ab.split())
        if a in link:
            link[a].append(b)
        else:
            link[a] = [b]
        if b in link:
            link[b].append(a)
        else:
            link[b] = [a]

    n_color = len(max(link.items(), key=lambda x: len(x[1]))[1])

    color = [0]*n

    color[0] = 1
    seek(1, 0, color, link)

    return str(n_color) + '\n' + '\n'.join(map(str, color[:-1]))


def seek(i: int, parent: int, color: list, link: dict):
    c = 1
    for node in link[i]:
        if node == parent:
            continue

        if c == color[i-1]:
            c += 1
        color[node-1] = c
        c += 1
        seek(node, i, color, link)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    link = [set() for _ in range(n+1)]
    edge = []

    for i, ab in enumerate(args[1:]):
        a, b = sorted(map(int, ab.split()))
        edge.append((a, b))
        link[a].add(b)
        link[b].add(a)

    n_color = max(map(len, link))

    color = {}

    queue = [(0, 1)]

    while queue:
        parent, cur = queue.pop()
        used = color[tuple(sorted((parent, cur)))] if 0 < parent else 0
        c = 1

        for child in link[cur]:
            if child == parent:
                continue

            if c == used:
                c += 1
            color[tuple(sorted((cur, child)))] = c
            c += 1

            queue.append((cur, child))

    return str(n_color) + '\n' \
        + '\n'.join(map(str, (color[ab] for ab in edge)))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
N = int(input())
K = int(input())
p = list(map(int, input().split()))
lists = []
for l in itertools.combinations(p, K):
  sums = sum(list(l))
  return lists.append(sums)

print(min(lists))
  
  


### FIXED CODE ###

S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = []
for l in range(K):
  lists.append(min(p))
  p.remove(min(p))
  
print(sum(lists))
import math
LIM = 182

def is_square(n):
    a = int(math.sqrt(n))
    return a*a == n

def solve(n):
    ans = 0
    if is_square(n):
        ans += 1
    for a in range(1,LIM):
        if a*a*2 > n:
            break
        if is_square(n - a*a):
            ans += 1
        for b in range(a,LIM):
            if b*b*2 > (n - a*a):
                break
            if is_square(n - a*a - b*b):
                ans += 1
            for c in range(b,LIM):
                if c*c*2 > (n - a*a - b*b):
                    break
                tmp = n - a*a - b*b - c*c
                if is_square(tmp) and c*c <= tmp:
                    ans += 1
    return ans

while True:
    N = int(input())
    if N == 0: break
    print(solve(N))

### FIXED CODE ###

MAXN = 2**15
MAXRT = int(MAXN**0.5)
MAXTERM = 4

dp = [[0 for n in range(MAXN+1)] for t in range(MAXTERM+1)]
dp[0][0] = 1
for r in range(MAXRT,0,-1):
    for t in range(MAXTERM):
        for n in range(MAXN+1 - r*r):
            if dp[t][n] == 0: continue
            dp[t+1][n + r*r] += dp[t][n]

while True:
    N = int(input())
    if N == 0: break
    print(sum(map(lambda x:x[N],dp)))
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
from fractions import gcd
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # 到達していないところはFalseにしとこう
    h,w = readInts()
    Field = [[0] * w for _ in range(h)]
    d = deque()
    # 最初左上にいるらしい
    # 移動方向 diagonaaaaaaal!
    dx = [-1,-1,1,1]
    dy = [-1,1,-1,1]
    # dfsしたい
    d.append([0,0]) # 初期値を入れる
    cnt = 0
    while d:
        x,y = d.pop()
        Field[y][x] = 1
        #cnt += 1
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if nx < 0 or w <= nx or ny < 0 or h <= ny:
                continue
            if Field[ny][nx] == 0:
                continue
            # 探索済みならいかない
            d.append([nx,ny])
    for x in range(w):
        for y in range(h):
            if Field[y][x] == 1:
                cnt += 1
    print(cnt)
if __name__ == '__main__':
  main()


### FIXED CODE ###

from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
from fractions import gcd
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # # 到達していないところはFalseにしとこう
    # h,w = readInts()
    # Field = [[0] * w for _ in range(h)]
    # d = deque()
    # # 最初左上にいるらしい
    # # 移動方向 diagonaaaaaaal!
    # dx = [-1,-1,1,1]
    # dy = [-1,1,-1,1]
    # # dfsしたい
    # d.append([0,0]) # 初期値を入れる
    # cnt = 0
    # while d:
    #     x,y = d.pop()
    #     Field[y][x] = 1
    #     #cnt += 1
    #     for i in range(4):
    #         nx = x + dx[i]
    #         ny = y + dy[i]
    #         if nx < 0 or w <= nx or ny < 0 or h <= ny:
    #             continue
    #         if Field[ny][nx] == 0:
    #             continue
    #         # 探索済みならいかない
    #         d.append([nx,ny])
    # for x in range(w):
    #     for y in range(h):
    #         if Field[y][x] == 1:
    #             cnt += 1
    # print(cnt)
    h,w = readInts()
    mul = h * w # multiplication
    if h == 1 or w == 1:
        print(1)
    elif mul % 2 == 0:
        print(mul // 2)
    else:
        print((mul+1)//2)
if __name__ == '__main__':
  main()
#!/usr/bin/env python3
import functools
import math
n, *a = map(int, open(0).read().split())
gcd = functools.reduce(math.gcd, a)
print(gcd)


### FIXED CODE ###

#!/usr/bin/env python3
import functools
import fractions
n, *a = map(int, open(0).read().split())
gcd = functools.reduce(fractions.gcd, a)
print(gcd)
import math
p = math.pi
r = int(input())

print("{} {}",format(2*r*p, r*r*p))



### FIXED CODE ###

import math
p = math.pi
r = float(input())

print("{} {}".format(r*r*p, 2*r*p))
N,K=map(int,input().split())
S = input()
S[K] = S[K].lower()
print(S)

### FIXED CODE ###

N,K=map(int,input().split())
S = input()
list = [b.lower() if a+1==K else b for (a,b) in enumerate(S)]
moji = ''.join(list)
print(moji)
n = int(input())
max = -100000000
min = 1000000000
sum = 0
a= input().split()
for i in range(0,n):
    sum += a[i]
    if int(a[i]) >= max: max = a[i]
    if int(a[i]) <= min: min = a[i]

print(min,max,sum)


### FIXED CODE ###

n = int(input())
a = sorted([int(x) for x in input().split()])
print(a[0],a[-1],sum(a))