Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
import sys
from collections import deque
INF = float("inf")


def argmost(a, comp, ini):
    m, n = ini, -1
    for i, v in enumerate(a):
        if comp(m, v):
            m, n = v, i
    return m, n


def solve(H: int, W: int, A: "List[str]"):
    # 黒の位置をx, y座標として持つ。黒からの距離も一緒に持つ
    black = []
    B = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                black.append((i, j, 0))
            B[i][j] = 0 if A[i][j] == "#" else -INF  # 黒は1

    black.sort(key=lambda x: x[0])

    q = deque()
    q.extend(black)

    while len(q) > 0:
        cy, cx, dis = q.popleft()
        for y, x in zip([cy-1, cy, cy+1, cy], [cx, cx-1, cx, cx+1]):
            if 0 <= y < H and 0 <= x < W and B[y][x] < 0:
                B[y][x] = dis+1
                q.append((y, x, dis+1))

    m = -INF
    for i in range(H):
        a = max(B[i])
        if m < a:
            m = a
    print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import deque
INF = float("inf")


def solve(H: int, W: int, A: "List[str]"):
    # 黒の位置をx, y座標として持つ。黒からの距離も一緒に持つ
    black = []
    B = [[-1]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                black.append((i, j, 0))
                B[i][j] = 0

    q = deque()
    q.extend(black)

    while len(q) > 0:
        cy, cx, dis = q.popleft()
        for y, x in zip([cy-1, cy, cy+1, cy], [cx, cx-1, cx, cx+1]):
            if 0 <= y < H and 0 <= x < W and B[y][x] < 0:
                B[y][x] = dis+1
                q.append((y, x, dis+1))

    m = -INF
    for i in range(H):
        a = max(B[i])
        if m < a:
            m = a
    print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, A)


if __name__ == '__main__':
    main()
a,b = input().split(" ")
print(a*b,2*(a+b))

### FIXED CODE ###

n = input().split(" ")
a, b = int(n[0]), int(n[1])
print(a * b, 2 * (a + b))
count = 1
while True:
    x = int( input().strip())
    if x == '0':
        break
    else:
        print( 'Case {0}: {1}'.format( count, x))
        count += 1

### FIXED CODE ###

count = 1
while True:
    x = input().strip()
    if x == '0':
        break
    else:
        print( 'Case %s: %s' % ( count, x))
        count += 1
x,y=input().split()
if x=="A":x=10
elif x=="B":X=11
elif x=="C":x=12
elif x=="D":x=13
elif x=="E":x=14
elif x=="F":x=15
if y=="A":y=10
elif y=="B":y=11
elif y=="C":y=12
elif y=="D":y=13
elif y=="E":y=14
elif y=="F":y=15
if x-y<0:print("<")
elif x-y>0:print(">")
elif x-y==0:print("=")

### FIXED CODE ###

x,y=input().split()
lis=["A","B","C","D","E","F"]
for i in range(6):
    if x==lis[i]:x=i+10
    if y==lis[i]:y=i+10
if x<y:print("<")
elif x>y:print(">")
elif x==y:print("=")
N,M = list(map(int,input().split()))
ans = [0 for i in range(N)]
anss = 0

for i in range(M):
    L,R = list(map(int,input().split()))
    if L == R:
      ans[L-1]+=1
    else:
      for j in range(L-1,R,1):
        ans[j]+=1

maxn = 0
for i in range(M):
    if ans[i] > maxn:
        maxn = ans[i]
        
for i in range(M):
    if ans[i] == maxn:
        anss += 1
print(anss)

### FIXED CODE ###

N,M = list(map(int,input().split()))
L = 1
R = N+1
ans = N*2

for i in range(M):
    tL,tR = list(map(int,input().split()))
    if tR < L or R < tL:
        ans = 0
        break
    if tL > L:
        L = tL
    if tR < R:
        R = tR

print(min(ans,R-L+1))
import numpy as np
N,M=map(int, input().split())
A = np.array([input().split() for i in range(M)])


P=A[:,0]
S=A[:,1]

if M>0:
    ans=np.unique(P[S=="AC"])

    wa=0
    for j in ans:
        for i in S[P==j]:
            if i=="WA":
                wa+=1
            else:
                break

    print(len(ans),wa)
else:
    print(0,0)

### FIXED CODE ###

N,M=map(int,input().split())
AC={}
WA={}
for i in range(M):
    a,b=input().split()
    if not(a in AC.keys()):
        if b=="AC":
            AC[a]=1
        else:
            if a in WA.keys():
                WA[a]+=1
            else:
                WA[a]=1
y=0
for i in AC.keys():
    if i in WA.keys():
        y+=WA[i]
print(sum(AC.values()),y)
import fractions
a, b = map(int, input().split())
ans = (a * b) // fractions.gcd(a, b)
print(ans)

### FIXED CODE ###

a = int(input())
b = int(input())
for i in range(1, 4):
    if i != a and i != b:
        print(i)
n = int(input())
X = list(map(int,input().split)())
ans = 10**100
for i in range(1,101):
  count = 0
  for j in X:
    count += (i-j)*2
  ans = min(ans,count)
print(ans)

### FIXED CODE ###

n = int(input())
X = list(map(int,input().split()))
ans = 10**100
for i in range(1,101):
  count = 0
  for j in X:
    count += (i-j)**2
  ans = min(ans,count)
print(ans)
x, y = map(int, raw_input().split())
if(x>=1and x<=9) or (y>=1 and y<=9):
	print(x*y)
else:
	print("-1")

### FIXED CODE ###

x,y = map(int,input().split())
if(x<1 or x>9 or y<1 or y>9):
  print("-1")
else:
  print(x*y)
N = int(input())
a=0
for i in range(N):
  b=input().split()
  if b[1]=="JPY":
    a+=b[0]
  else:
    a+=b[0]*380000
print(a)
  

### FIXED CODE ###

N = int(input())
a=0
for i in range(N):
  b=input().split()
  if b[1]=="JPY":
    a+=float(b[0])
  else:
    a+=float(b[0])*380000
print(a)
line = input().split()
x = line[1]
ans = 0;
 
a = input().split().sort()
 
for i in len(a):
  if a[i] > x:
    print ans
    break
  else:
    x-=a[i]
    ans+=1
    continue
print ans

### FIXED CODE ###

line = input().split()
N = int(line[0])
x = int(line[1])
ans = 0

a = input().split()
a = [int(i) for i in a]
a.sort()

for i in range(N):
    if a[i] > x:
        print(ans)
        break
    else:
        x -= a[i]
        if i != (N - 1):
            ans += 1
        else:
            if x == 0:
                ans += 1
            print(ans)
N = int(input())
X = input()
popcount_X = X.count('1')
numX = int(X, 2)
a = numX % (popcount_X + 1)
b = numX % (popcount_X - 1) if popcount_X != 1 else 0
for i, x in enumerate(X, 1): #リストのインデクス，要素，第二引数に開始位置
    if x == '1' and popcount_X == 1:
        print(0); continue
    ans = 1
    if x == '1':
        temp = (b - pow(2, N - 1, popcount_X - 1)) % (popcount_X - 1)
    else:
        temp = (a + pow(2, N - i, popcount_X - 1)) % (popcount_X + 1)
    while temp:
        p = format(temp, 'b').count('1') #2進数，1の個数
        temp %= p
        ans += 1
    print(ans)

### FIXED CODE ###

N = int(input())
X = input()
popcount_X = X.count('1')
numX = int(X, 2)
a = numX % (popcount_X + 1)
b = numX % (popcount_X - 1) if popcount_X != 1 else 0
for i, x in enumerate(X, 1): #リストのインデクス，要素，第二引数に開始位置
    if x == '1' and popcount_X == 1:
        print(0)
        continue
    ans = 1
    if x == '1':
        temp = (b - pow(2, N - i, popcount_X - 1)) % (popcount_X - 1)
    else:
        temp = (a + pow(2, N - i, popcount_X + 1)) % (popcount_X + 1)
    while temp:
        p = format(temp, 'b').count('1') #2進数，1の個数
        temp %= p
        ans += 1
    print(ans)
n, a, b = map(int, input().split())

d = b - a + 1
print(math.ceil(d/2))

### FIXED CODE ###

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

d = b - a
if d % 2 == 0:
    print(d//2)
else:
    f = min(a - 1, n - b) + d//2 + 1
    print(f)
#!/usr/bin/env python3

A, B, x, mid, count = map(int, input().split()), [], 2, 0
for i in range(A, B):
    while(i > 10):
        x.append(i % 10)
        i = int(i/10)
    count = count+1 if(x[0:mid] == x[mid:len(x)]
                       and len(x) > 0) else None
    x.clear()
print(count)


### FIXED CODE ###

A, B = map(int, input().split())
cnt = 0
for i in range(A, B+1):
    j = list(str(i))
    if j[0] == j[4] and j[1] == j[3]:
        cnt += 1
print(cnt)
#C - Poll
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])

### FIXED CODE ###

#C - Poll
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float('inf')
ans=0
for i in range(h):
    for j in range(w):
        if S[i][j]!='#':
            dp=[[inf for _ in range(w)] for _ in range(h)]
            dp[i][j]=0
            que=deque([(i,j)])
        while que:
            si,sj=que.popleft()
            for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
                if 0<=ni<h and 0<=nj<w and S[ni][nj]!='#':
                    if dp[ni][nj]>dp[si][sj]+1:
                        dp[ni][nj]=dp[si][sj]+1
                        ans=max(ans,dp[si][sj]+1)
                        que.append((ni,nj))
print(ans)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from collections import deque
 
H,W = map(int,readline().split())
H += 2; W += 2
grid = '#' * W
for _ in range(H-2):
    grid += '#' + readline().rstrip().decode() + '#'
grid += '#' * W
 
def bfs(start):
    INF = 10 ** 9
    dist = [INF] * (H*W)
    dist[start] = 0
    q = deque([start])
    while q:
        v = q.popleft()
        dv = dist[v]
        for move in (-1,1,W,-W):
            w = v + move
            if grid[w] == '#':
                continue
            dw = dv + 1
            if dw >= dist[w]:
                continue
            dist[w] = dw
            q.append(w)
    return max(x for x in dist if x < INF)
 
answer = max(bfs(v) for v in range(H*W) if grid[v] != '#')
print(answer)
N, M = map(int, input().split())
stu = []
che = []
for i in range(N):
  stu.append(list(map(int, input().split())))
for i in range(M):
  che.append(list(map(int, input().split())))
  
for i in stu:
  x, y = i[0], i[1]
  ans = 0
  tmp = 99999999999999
  for j in che:
    if abs(x-j[0])+abs(y-j[1]) < tmp:
      tmp = abs(x-j[0])+abs(y-j[1])
      ans = j + 1
  print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
stu = []
che = []
for i in range(N):
  stu.append(list(map(int, input().split())))
for i in range(M):
  che.append(list(map(int, input().split())))
  
for i in stu:
  x, y = i[0], i[1]
  ans = 0
  tmp = 99999999999999
  for num, j in enumerate(che):
    if abs(x-j[0])+abs(y-j[1]) < tmp:
      tmp = abs(x-j[0])+abs(y-j[1])
      ans = num + 1
  print(ans)
list_SP = []
N = int(input())

for i in range(N):
  S, P = input().split()
  list_SP.append([S, 100 - int(P), i+1])
  
  
sorted_listSP = sorted(list_SP)
print(sorted_listSP[2])

### FIXED CODE ###

list_SP = []
N = int(input())

for i in range(N):
  S, P = input().split()
  list_SP.append([S, 100 - int(P), i+1])
  
  
sorted_listSP = sorted(list_SP)
for data in sorted_listSP:
  print(data[2])
n = int(input())
for i in range(1,10):
  for j in range(1,10):
    if i*j == n:
      print(Yes)
      exit()
print(No)

### FIXED CODE ###

n = int(input())
for i in range(1,10):
  for j in range(1,10):
    if i*j == n:
      print("Yes")
      exit()
print("No")
import itertools


def actual(n, D):
    """
    combinations でゴリ押し
    """
    comb = itertools.combinations(D, 2)

    # return sum([x * y for x, y in comb])

    """
    「順番を考慮しない2要素の選び方」を全探索する際のポイント
        内側のループ変数の始点を外側のループ変数 +1 から始めるとよい。
        これにより、内側のループで選ぶインデックスが必ず外側のループで選ぶインデックスより大きくなり、
        同じ選び方を 2 回見てしまうことを回避できます。
    """
    # s = 0
    # for i in range(len(D)):
    #     for j in range(i + 1, len(D)):
    #         s += D[i] * D[j]
    #
    # return s

    """
    O(N)で解くパターン
    
    ex: a, b, c, d
        a*b + a*c + a*d = a * (b + c +d)
              b*c + b*d = b * (    c +d)
                    c*d = c * (       d)
    """
    s = 0
    for i in range(len(D) - 1):
        s += D[i] * sum(D[i + 1:])
    
    return s


n = int(input())
D = list(map(int, input().split()))

print(actual(n, D))


### FIXED CODE ###

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

if a <= b * 2:
	print(0)
else:
	print(a - b * 2)
n,k=map(int,input().split())
l=sorted(list(map(int,input().split())),reversed=True)

l=l[0:k]
max_l=max(l)

num=0
sum_lis=[]
for i in range(1,max_l+1):
  num+=i
  sum_lis.append(num)
  
ans=0
for i in l:
  a=sum_lis[i-1]
  ans+=(a/i)
  print(ans,i,a)
  
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))

for i in range(n):
  l[i]=(l[i]+1)/2

lis=[0]*(n+1)
for i in range(n):
  lis[i+1]=lis[i]+l[i]
  
ans=0
for i in range(n-k+1):
  num=lis[i+k]-lis[i]
  ans=max(num,ans)
  
print(ans)
N,K = map(int,input().split())
S = input()
if S[0] == '0':
  divide = []
else:
  divide = [0]
tmp = 1
for i in range(1,N):
  if S[i] == S[i-1]:
    tmp += 1
  else:
    divide += [tmp]
    tmp = 1
divide += [tmp]
le = len(divide)
zero = [0]*2*le + divide + [0]*2*le
su = [0]
for i in range(0,5*le):
  su += [su[-1]+zero[i]]
del su[0]
lle = len(su)
mxm = 0
for k in range(K,lle):
  if 2*k+1 >= lle:
    break
  cd = su[2*k+1] - su[2*k-2*K]
  if cd > mxm:
    mxm = cd
print(mxm)

### FIXED CODE ###

A,B = map(int,input().split())
if A > B:
  print(2*A-1)
if A == B:
  print(A+B)
if A < B:
  print(2*B-1)
n = int(input())
a = list(map(int, input().split()))
bucket = [0] * max(a)
for i in a:
  bucket[i - 1] += 1
if max(bucket) >= 2:
  print('NO')
else:
  print('YES')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
sorta = sorted(a)
sflag = False
for i in range(n - 1):
  if sorta[i] == sorta[i + 1]:
    sflag = True
    break
if sflag == True:
  print('NO')
else:
  print('YES')
import numpy as np

W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
    
total = W*H

x_list = np.arange(0, W+1)
y_list = np.arange(0, H+1)
for i in range(len(a)):
    if a[i] == 1:
        x_list = x_list[x[i]:]
    elif a[i] == 2:
        x_list = x_list[:x[i]+1]
    elif a[i] == 3:
        y_list = y_list[y[i]:]
    else:
        y_list = y_list[:y[i]+1]
        
x_len = x_list[-1]-x_list[0]
y_len = y_list[-1]-y_list[0]

print(x_len*y_len)

### FIXED CODE ###

W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())

x_min = 0
x_max = W
y_min = 0
y_max = H
for i in range(len(a)):
    if a[i] == 1:
        if x_min < x[i]:
            x_min = x[i]
    elif a[i] == 2:
        if x_max > x[i]:
            x_max = x[i]
    elif a[i] == 3:
        if y_min < y[i]:
            y_min = y[i]
    else:
        if y_max > y[i]:
            y_max = y[i]
        
x_len = x_max-x_min
y_len = y_max-y_min
result = x_len*y_len
if (x_len<0)|(y_len<0):
    result = 0

print(result)
a = -1
n,m = map(int, input().split())
s_and_c = [tuple(map(int,input().split())) for i in range(m)]
s = []
c = []
l = [0]*m
for t in s_and_c:
  l[t[0]-1] = t[1]
for _ in s_and_c:
  s.append(_[0])
  c.append(_[1])
if max(s) == n and l[0] != 0:
  a = "".join([str(i) for i in l])
else:
  pass
print(a)

### FIXED CODE ###

n,m = map(int,input().split())
x = [tuple(map(int,input().split())) for i in range(m)]
f=True
for i in range(0,1001):
    i = str(i)
    if len(i)==n:
        if all([i[t[0]-1]==str(t[1]) for t in x]):
            print(i)
            f=False
            break
if f:
    print(-1)
import bisect


h, w, n = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]

set_ = set()
tate = [[] for i in range(w + 1)]
for i, j in info:
    tate[j].append(i)
    set_.add((i, j))
for j in range(w + 1):
    tate[j].append(h + 1)

i, j = 1, 1
ans = 10 ** 18
while True:
    if i == w + 1:
        break
    ind = bisect.bisect_right(tate[j], i)
    ans = min(ans, tate[j][ind] - 1)

    i += 1
    if (i, j + 1) in set_ or j == w:
        pass
    else:
        j += 1

print(ans)

### FIXED CODE ###

from operator import itemgetter
import bisect


h, w, n = map(int, input().split())
info = [tuple(map(int, input().split())) for i in range(n)]

memo = set()
for i, j in info:
    memo.add(i * 10**6 + j)

pos = [[] for _ in range(w + 1)]
info = sorted(info, key = itemgetter(0))
for i, j in info:
    pos[j].append(i)

ans = 10**18
pos_i, pos_j = 1, 1
ind = bisect.bisect_right(pos[pos_j], pos_i)
try:
    ans = min(pos[pos_j][ind] - 1, ans)
except:
    pass

while True:
    if (pos_i + 1) * 10**6 + pos_j in memo or pos_i == h:
        ans = min(ans, pos_i)
        break
    pos_i += 1

    if pos_i * 10**6 + (pos_j + 1) in memo or pos_j == w:
        continue
    else:
        pos_j += 1
    ind = bisect.bisect_right(pos[pos_j], pos_i)
    try:
        ans = min(pos[pos_j][ind] - 1, ans)
    except:
        pass
print(ans)
N=(int)(input())
p=(input()).split(' ')

count=0


now=1
for k in p:
    if (int)(k)==now:
        p[now-1:(now+1 if now<len(p) else now-3)]=[p[now],p[now-1]]
        count=count+1
    now=now+1

print(count)

### FIXED CODE ###

N=(int)(input())
p=(input()).split(' ')

count=0


now=1
for k in p:
    if (int)(k)==now:
        p[now-1:(now+1 if now<len(p) else now-3)]=[p[now-2],p[now-1]]
        count=count+1
    now=now+1

print(count)
s = input()[::-1]

while True:
  if s[:5] == "maerd":
    s = s[5:]
  elif s[:7] == "remaerd":
    s - s[7:]
  elif s[:5] == "esare":
    s = s[5:]
  elif s[:6] == "resare":
    s - s[6:]
  else:
    break

if s == "":
  print("YES")
else:
  print("NO")

### FIXED CODE ###

#C - 白昼夢 / Daydream

s = input()[::-1]

while True:
  if s[:5] == "maerd":
    s = s[5:]
  elif s[:7] == "remaerd":
    s = s[7:]
  elif s[:5] == "esare":
    s = s[5:]
  elif s[:6] == "resare":
    s = s[6:]
  else:
    break

if s == "":
  print("YES")
else:
  print("NO")
N,M,A = map(int,input().split())
amd = [{} for i in range(1001)]
for i in range(M):
    h,p,q = map(int,input().split())
    amd[h][p] = q
    amd[h][q] = p
raw_input() #ignore

now = A
for d in reversed(amd):
    if now in d:
        now = d[now]
print(now)

### FIXED CODE ###

while True:
    N,M,A = map(int,input().split())
    if N == 0: break
    amd = [{} for i in range(1001)]
    for i in range(M):
        h,p,q = map(int,input().split())
        amd[h][p] = q
        amd[h][q] = p

    now = A
    for d in reversed(amd):
        if now in d:
            now = d[now]
    print(now)
N,K = map(int, input().split())
List = list(map(int, input().split()))

a=[]

for i in range(N):
    a.append(-1)
print(a)
b=1
for i in range(N):
    if not b in a:
        a[i]=b
        b=List[b-1]
    else:
        c=i
        break
print(a)
print(b,c)
num=a.index(b)
print(T,num)
T=c-num
if K<num:
    print(a[K])
else:
    print(a[num:][(K-num)%T])

### FIXED CODE ###

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

a=[]

for i in range(N):
    a.append(-1)
#print(a)
b=1
for i in range(N):
    if a[b-1]==-1:
        a[b-1]=i+1
        b=List[b-1]
        
    else:
        c=i
        break
#print(a)
#print(b,c)

num=a[b-1]-1
T=c-num
#print(T)
e=1
if K<num:
    for i in range(K):
        e=List[e-1]
    print(e)
else:
    qw=(K-num)%T
    List_new=[]
    for i in range(T):
        List_new.append(b)
        b=List[b-1]
    print(List_new[qw])
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

def p(length): # p = 1 => その長さに切り分けることは可能
    tmp = 0
    for a in A:
        if a % length == 0:
            tmp += (a // length) - 1
        else:
            tmp += a // length
        if tmp > K:
            return 0
    
    # print("length", length, "tmp ", tmp)
    
    return 1
    

def bin_search(arr): #答え(最長の丸太の最小値)として取りうる最大値
    lb = 0
    ub = 1000000000

    while ub - lb > 1:
        mid = (ub + lb) // 2
        if p(mid) == 1:
            ub = mid
        else:
            lb = mid
    
    return lb

def just(num):
    tmp = 0
    for a in A:
        if a % num != 0:
            return 0
        else:
            tmp += a // num
    if tmp != K:
        return 0
    else:
        return 1

ans_tmp = bin_search(A)
if just(ans_tmp) == 1:
    print(ans_tmp)
else:
    print(ans_tmp + 1)


### FIXED CODE ###

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

def p(length): # p = 1 => その長さに切り分けることは可能
    if length == 0:
        return 1

    tmp = 0
    for a in A:
        if a % length == 0:
            tmp += (a // length) - 1
        else:
            tmp += a // length
        if tmp > K:
            return 0
    
    # print("length", length, "tmp ", tmp)
    
    return 1
    

def bin_search(arr): #答え(最長の丸太の最小値)として取りうる最大値
    lb = 0
    ub = 1000000000

    while ub - lb > 1:
        mid = (ub + lb) // 2
        if p(mid) == 1:
            ub = mid
        else:
            lb = mid
    
    return lb

def just(num):
    if num == 0:
        return 0
        
    tmp = 0
    for a in A:
        if a % num != 0:
            return 0
        else:
            tmp += a // num
    if tmp != K:
        return 0
    else:
        return 1

ans_tmp = bin_search(A)
if just(ans_tmp) == 1:
    print(ans_tmp)
else:
    print(ans_tmp + 1)
N = int(input())
S = str(input())

if N % 2 == 0:
  NN = N/2
  for i in range(0, NN):
    if S[i] != S[i+NN]:
      print('No')
  else:
    print('Yes')
    
else:
  print('No')

### FIXED CODE ###

N = int(input())
S = str(input())
 
if N % 2 == 0:
  NN = int(N/2)
  for i in range(0, NN):
    if S[i] != S[i+NN]:
      print('No')
      break
  else:
    print('Yes')
    
else:
  print('No')
from collections import deque as dq
s = input()
nq = int(input())

s = dq(s)

jun = True
for i in range(nq):
  query = input().split()
  if query[0] == '1':
    jun = not jun
    continue
  if jun:
    if query[1] == '1':
      s.appendleft(query[2])
    else:
      s.append(query[2])
  else:
    if query[1] == '1':
      s.append(query[2])
    else:
      s.appendleft(query[2])
if jun:
  print(''.join(s))
else:
  print(''.join(s[::-1]))
    

### FIXED CODE ###

from collections import deque as dq
s = input()
nq = int(input())

s = dq(s)

jun = True
for i in range(nq):
  query = input().split()
  if query[0] == '1':
    jun = not jun
    continue
  if jun:
    if query[1] == '1':
      s.appendleft(query[2])
    else:
      s.append(query[2])
  else:
    if query[1] == '1':
      s.append(query[2])
    else:
      s.appendleft(query[2])
if jun:
  print(''.join(s))
else:
  print(''.join(list(s)[::-1]))
n,k=int(input()).split()
h=list(map(int,input().split(' ')))
h.sort()
if(k!=0):
  print(sum(h[:-k]))
else:
  print(sum(h))

### FIXED CODE ###

n,k=list(map(int,input().strip().split(' ')))
h=list(map(int,input().strip().split(' ')))
h.sort()
if(k!=0): print(sum(h[:-k]))
else: print(sum(h))
a,b,c=map(int,input().split();print(a*b//2)

### FIXED CODE ###

a,b,c=map(int,input().split());print(a*b//2)
s = input()
s_sorted = ''.join(sorted(s))
if s_sorted[0]==s_sorted[1] and s_sorted[2]==s_sorted[3] and S[1]!=S[2]:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = input()
s_sorted = ''.join(sorted(s))
if (s_sorted[0]==s_sorted[1]) and (s_sorted[2]==s_sorted[3]) and (s_sorted[1]!=s_sorted[2]):
  print('Yes')
else:
  print('No')