Harryxun/stf_run huggingface dataset:
if __name__ == '__main__':

	n,m = map(int,input().split())
	
	A = [0 for _ in range(m)]

	for i in range(m):
		s,c = map(int,input().split())
		if A[s-1] != 0:
			A[s-1] = min(A[s-1],c)
		else:
			A[s-1] = c
	
	ans = ""
	if A[0] == 0:
		print(-1)
	else:
		for j in range(m):
			ans += str(A[j])
		print(int(ans))

### FIXED CODE ###

if __name__ == '__main__':

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

	A = [-1 for _ in range(n)]
	B = []
	for i in range(m):
		x,y = map(int,input().split())
		B.append([x,y])

	flg = True
	
	for a in B:
		x = a[0]
		y = a[1]

		if A[x-1] == -1:
			A[x-1] = y
		else:
			if A[x-1] != y:
				flg = False
				break

	ans = 0
	if flg:
		#穴埋め
		for i,j in enumerate(A):
			if j == -1:
				if i == 0 and len(A) != 1:
					A[i] = 1
				else:
					A[i] = 0

		tmp = ""
		for k in range(n):
			tmp += str(A[k])
		tmp = str(int(tmp))
		if len(tmp) == n :
			ans = int(tmp)
		else:
			ans = -1
	else:
		ans = -1

	print(ans)
import sys

drops = [None,
         [(-1,0),(1,0),(0,-1),(0,1)],
         [(-1,0),(1,0),(0,-1),(0,1),(-1,1),(-1,-1),(1,-1),(1,1)],
         [(-1,0),(1,0),(0,-1),(0,1),(-1,1),(-1,-1),(1,-1),(1,1),(-2,0),(2,0),(0,-2),(0,2)]]

B = [[0 for j in xrange(10)] for i in xrange(10)]

for line in sys.stdin:
    x, y, s = map(int, line.rstrip().split(','))
    B[x][y] += 1
    for dx, dy in drops[s]:
        nx, ny = x+dx, y+dy
        if (0 <= nx <= 9 or 0 <= ny <= 9):
            B[ny][nx] += 1

emp, m = 0, 0
for i in xrange(10):
    for j in xrange(10):
        if B[i][j] == 0:
            emp += 1
        m = max(m, B[i][j])
print emp
print m

### FIXED CODE ###

import sys

drops = [None,
         [(0,0),(-1,0),(1,0),(0,-1),(0,1)],
         [(0,0),(-1,0),(1,0),(0,-1),(0,1),(-1,1),(-1,-1),(1,-1),(1,1)],
         [(0,0),(-1,0),(1,0),(0,-1),(0,1),(-1,1),(-1,-1),(1,-1),(1,1),(-2,0),(2,0),(0,-2),(0,2)]]

B = [[0 for j in xrange(10)] for i in xrange(10)]

for line in sys.stdin:
    x, y, s = map(int, line.rstrip().split(','))
    for dx, dy in drops[s]:
        nx, ny = x+dx, y+dy
        if (0 <= nx <= 9 and 0 <= ny <= 9):
            B[ny][nx] += 1

emp, m = 0, 0
for i in xrange(10):
    for j in xrange(10):
        if B[i][j] == 0:
            emp += 1
        m = max(m, B[i][j])
print emp
print m
n,k,q = map(int,input().split())
points = [int(input()) for _ in range(q)]
for i in range(q):
    winner = int(input())
    points[winner - 1] += 1
for i in points:
    if i >0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k,q = map(int,input().split())
points = [k-q]*n
for i in range(q):
    winner = int(input())
    points[winner - 1] += 1
for i in points:
    if i >0:
        print("Yes")
    else:
        print("No")
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

def check(t):
    c=0
    for i in range(n):
        c+=1+(max(0,h[i]-b*t)-1)//(a-b)
    return t>=c

l=1
r=1+max(h)//b
while r-l>1:
    mid=(r-l)//2+l
    if check(mid):
        r=mid
    else:
        l=mid
ans=l
if check(r):
    #ans=r
print(ans)



### FIXED CODE ###

# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

def check(t):
    c=0
    for i in range(n):
        c+=1+(max(0,h[i]-b*t)-1)//(a-b)
    return t>=c

l=0
r=3+max(h)//b
while r-l>1:
    mid=(r-l)//2+l
    if check(mid):
        r=mid
    else:
        l=mid
ans=l
if check(r):
    ans=r
print(ans)
n = int(input())
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
        
def lcm(a,b):
    return int(a/gcd(a,b)*b)
    
ans=1

for i in range(n):
    t = int(input())
    ans = lcm(ans,t)
    
print(ans)

### FIXED CODE ###

n = int(raw_input())

def gcd(a,b):
    if a > b:
        a,b = b,a
    # a <= b
    while a > 0:
        a,b = b%a, a
    return b

def lcm(a,b):
    g = gcd(a,b)
    return a/g * b

x = 1
for i in range(n):
    ti = int(raw_input())
    x = lcm(x, ti)

print x
from collections import deque
from bisect import bisect_left as bile

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    arr = list(map(int, input().split()))
    adj = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        adj[a].append(b)
        adj[b].append(a)

    ans = [0]*n
    inf = 1e18
    dp = [inf]*(n+10)
    parent = [-1]*n
    def dfs(s):
        idx = bile(dp, arr[s])
        tmp = dp[idx]
        dp[idx] = arr[s]
        ans[s] = bile(dp, inf)

        for v in adj[s]:
            if v == parent[s]:
                continue
            parent[v] = s
            dfs(v)
        dp[idx] = tmp
        return ans
        
    ans = dfs(0)
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque
from bisect import bisect_left as bile

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    sys.setrecursionlimit(10**6)
    n = int(input())
    arr = list(map(int, input().split()))
    adj = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        adj[a].append(b)
        adj[b].append(a)

    ans = [0]*n
    inf = 1e18
    dp = [inf]*(n+10)
    parent = [-1]*n
    def dfs(s):
        idx = bile(dp, arr[s])
        tmp = dp[idx]
        dp[idx] = arr[s]
        ans[s] = bile(dp, inf)

        for v in adj[s]:
            if v == parent[s]:
                continue
            parent[v] = s
            dfs(v)
        dp[idx] = tmp
        return ans
        
    ans = dfs(0)
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()
n,k=map(int,input().split())
v=list(map(int,input().split()))

ans=0

for a in range(50):
  for b in range(50):
    if a+b <= min(n,k):
      li=v[:a]+v[n-b:]
      sumv = sum(li)
      li.sort()
      for i in range(min(k-a-b,len(li))):
        if li[i] < 0:
          li[i] = 0:
        else:
          break:
      ans=max(ans,sum(li))
      
print(ans)
            
      

### FIXED CODE ###

n,k=map(int,input().split())
v=list(map(int,input().split()))
 
ans=0
 
for a in range(50):
  for b in range(50):
    if a+b <= min(n,k):
      li=v[:a]+v[n-b:]
      sumv = sum(li)
      li.sort()
      for i in range(min(k-a-b,len(li))):
        if li[i] < 0:
          li[i] = 0
        else:
          break
      ans=max(ans,sum(li))
      
print(ans)
def gcd(a, b):
    if a>b:
        c = a%b
    else:
        c = b%a
    if c==0:
        return b
    else:
        return gcd(b,c)

[n,m]=[int(i) for i in input().split()]
s=input()
t=input()
g=gcd(n,m)

lcm=int(n*m/g)

s1=int(lcm/n)
s2=int(lcm/m)

#print(s1, s2)

c=max(int(n/m), int(m/n))
f=1
for i in range(c):
    if s[s1*i] != t[s2*i]:
        f=0

if f:
    print(lcm)
else:
    print("-1")


### FIXED CODE ###

def gcd(a, b):
    if a>b:
        c = a%b
    else:
        c = b%a
    if c==0:
        return b
    else:
        return gcd(b,c)

[n,m]=[int(i) for i in input().split()]
s=input()
t=input()
g=gcd(n,m)

lcm=int(n*m/g)

s1=int(lcm/n)
s2=int(lcm/m)

#print(s1, s2, int(n/s2))

f=1
for i in range(int(n/s2)):
    #print(s2*i, s[s2*i], s1*i, t[s1*i])
    if s[s2*i] != t[s1*i]:
        f=0

if f:
    print(lcm)
else:
    print("-1")
N,K = map(int, input().split())
MOD = 10**9 + 7
es = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)



checked = [False] * N

colors = [None] * N

def solve(curr, step):
    # step=0のとき、そのノードの色を何個選べるか確認する
    if step == 0:
        used = 0
        for nxt in es[curr]:
            used += solve(nxt, 1)
        colors[curr] = K - used
        # 次を探索する
        for nxt in es[curr]:
            if colors[nxt] == None:
                solve(nxt, 0)
    # step=1のとき、自分とその次のノードについて色が何個選べるか分かっているノード数を戻す
    elif step == 1:
        used = 0
        if colors[curr] != None:
            used += 1
        for nxt in es[curr]:
            used += solve(nxt, 2)
        return used

    # step=2の場合、自分について色が何個選べるか分かっている場合に１を戻す
    elif step == 2:
        if colors[curr] != None:
            return 1
        else:
            return 0

solve(0,0)

#print(colors)

ans = 1
for c in colors:
    ans *= c
    ans %= MOD

print(ans)

### FIXED CODE ###



MOD = 10**9 + 7
N,K = map(int, input().split())
es = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

MAXN = K+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def nPr(n,r):
    if n < r:
        return 0
    return fac[n] * finv[n-r]

# 「距離が２以内は異なる色 = あるノードとそれに隣接するノードはそれぞれ異なる色」の言い換えがポイント
# 根はK通り、根の子の数をmとすると、根の子の塗り方は、K-1個の中からm個並べる方法なので、nPr(K-1, m)通り
# それ以降についてあるノードを見るとき、そのノードと親には既に色が塗られている場合を考える。
# 親とその親の２色は使われてるから、そのノードのこの塗り方はK-2のうちから子の数だけ並べるときなので、nPr(K-2, 子の数)


ans = (K * nPr(K-1, len(es[0]))) % MOD
stack = []
for nxt in es[0]:
    stack.append(nxt)

checked = [False] * N
checked[0] = True

# ノード0の子から見ていって、その子の塗り方をかけ合わせていく
while stack:
    curr = stack.pop()
    checked[curr] = True
    # currの親はすでに塗ってあるので、r = len(es[curr])-1
    ans *= nPr(K-2, len(es[curr])-1)
    ans %= MOD
    for nxt in es[curr]:
        if not checked[nxt]:
            stack.append(nxt)

print(ans % MOD)
N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]

d = 0
for i in range(N-1):
    for j in range(i+1, N):
        tempd = ((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2)**0.5
        if d < tempd:
            d = tempd
            p = (i, j)

c = [(L[p[0]][0]+L[p[1]][0])/2, (L[p[0]][1]+L[p[1]][1])/2]
dc = 0
for i in range(N):
    if i == p[0] or i == p[1]:
        continue
    tempd = ((c[0]-L[i][0])**2+(c[1]-L[i][1])**2)**0.5
    if dc < tempd:
        dc = tempd
        pc = i

if dc <= d/2:
    ans = d/2
else:
    i = p[0]
    j = p[1]
    k = pc

    a = L[i][0]
    b = L[i][1]
    c = L[j][0]
    d = L[j][1]
    e = L[k][0]
    f = L[k][1]

    aa = a * a
    bb = b * b
    cc = c * c
    dd = d * d
    ee = e * e
    ff = f * f
    py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))

    if c == a:
        px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a))
    else:
        px = (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a))

    ans = math.hypot(px - a, py - b)

print(ans)

### FIXED CODE ###

N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]

def dist(x, y, x0, y0):
    return ((x-x0)**2 + (y-y0)**2)**0.5

def f(x, y):
    res = 0
    for i in range(N):
        res = max(res, dist(L[i][0], L[i][1], x, y))
    return res

lx = -10**4
rx = 10**4
for _ in range(100):
    cx1 = (lx*2 + rx) / 3
    ly = -10**4
    ry = 10**4
    for _ in range(100):
        cy1 = (ly*2 + ry) / 3
        cy2 = (ly + ry*2) / 3
        if f(cx1, cy1) < f(cx1, cy2):
            ry = cy2
        else:
            ly = cy1
    y = (ly + ry) / 2
    
    cx2 = (lx + rx*2) / 3
    ly = -10**4
    ry = 10**4
    for _ in range(100):
        cy1 = (ly*2 + ry) / 3
        cy2 = (ly + ry*2) / 3
        if f(cx2, cy1) < f(cx2, cy2):
            ry = cy2
        else:
            ly = cy1

    if f(cx1, y) < f(cx2, ly):
        rx = cx2
        ans = f(cx1, y)
    else:
        lx = cx1
        ans = f(cx2, ly)

print(ans)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(a)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]
 
for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(A)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)


### FIXED CODE ###

n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]

for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])

num,x = 0,m

for i in range(n+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)
import heapq
n,m = map(int, input().split())
job = {}
for i in range(n):
    a,b = map(int, input().split())
    if a not in job.keys():
        job[a] = [(-b,a)]
    else:
        job[a].append((-b,a))

hq = []

max_income = 0
for i in range(1,m+1):
    if i in job.keys():
        for j in job[i]:
            heapq.heappush(hq,(j))
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i

print(max_income)

### FIXED CODE ###

import heapq
n,m = map(int, input().split())
job_list = []
for i in range(n):
    a,b = map(int, input().split())
    job_list.append((a,b))
job_list.sort(key=lambda x:x[0])
# print(job_list)

hq = []
max_income = 0
j = 0
for i in range(1,m+1):
    while j < n and job_list[j][0] <= i:
        heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))
        j += 1
    if len(hq) < 1:
        continue
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i

print(max_income)
N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]

diff = [0] * 100001
for k in l :
    diff[k[0] - 1] += 1
    diff[k[1]] -= 1

hist = [0,0]
for i in range(2, N + 1) :
    hist.append(hist[-1] + diff[i-1])

print(max([0] + [y - 1 for (x,y) in zip(hist, range(N + 1)) if x + 1 >= y]))

### FIXED CODE ###

N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]

diff = [0] * 100002
for k in l :
    diff[k[0] - 1] += 1
    diff[k[1]] -= 1

hist = [0,0]
for i in range(2, N + 2) :
    hist.append(hist[-1] + diff[i-1])

print(max([0] + [y - 1 for (x,y) in zip(hist, range(N + 2)) if x + 1 >= y]))
N = input()
D = [int(i) for i in input()]
M = input()
T = [int(i) for i in input()]

for t in T:
    try:
        D.remove(t)
    except:
        print("NO")
        quit()
print("YES")

### FIXED CODE ###

from collections import Counter
N = input()
D = Counter([i for i in input().split()])
M = input()
T = Counter([i for i in input().split()])
for key, value in T.items():
    try:
        if D[key] < value:
            print("NO")
            break
    except:
        print("NO")
        break
else:
    print("YES")
#C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
i = 0
j = 0
while n > i or m > j:
    # print(i,j,k)
    if n <= i:
        k -= b[j]
        j += 1
        ans+=1
        continue
    elif n <= j:
        k -= a[i]
        i += 1
        ans+=1
        continue
    if a[i] < b[j]:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k < 0:
        break
    ans += 1
    if k == 0:
        break
print(ans)
   

### FIXED CODE ###

#C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
#読書時間A,B
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans = 0
j = m
#Aを増やしたときA+Bがkより小さくなるようなi,jを決めて最大値を決めてる
for i in range(n + 1):
    if A[i] > k:
        break
    #K<=A[i]+B[j]となるまでjを引く>>k-A<=B
    while A[i] + B[j] > k:
        j -= 1
    ans = max(ans, i + j)
print(ans)
S, T = input().split()
A, B= map(int, input().split())
U = input()
if S == U:
    print(A - 1, B)
elif T==U:
    print(A, B - 1)
else:

### FIXED CODE ###

S, T = input().split()
A, B= map(int, input().split())
U = input()
if S == U:
    print(A - 1, B)
else:
    print(A, B - 1)
def see_next(N, M, As, Bs, a, b):
  if a == N and b == M:
    return 1
  elif As[a] < Bs[b]:
    return 1
  elif As[a] > Bs[b]:
    return 0
  elif As[a] == Bs[b]:
    return see_next(N, M, As, Bs, a+1, b+1)

N, M, K = map(int,input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
As.append(K+1)
Bs.append(K+1)
a = 0
b = 0
time = 0
ans = -1
while time <= K:
  ans += 1
  if a == N and b == M:
    break
  elif As[a] < Bs[b]:
    time += As[a]
    # print(As[a])
    a += 1
  elif As[a] > Bs[b]:
    time += Bs[b]
    # print(Bs[b])
    b += 1
  elif As[a] == Bs[b]:
    if see_next(N, M, As, Bs, a+1, b+1):
      time += As[a]
      a += 1
    else:
      time += Bs[b]
      b += 1
  
print(ans)



### FIXED CODE ###

N, M, K = map(int, input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
a, b = [0], [0]
for i in range(N):
  # a[i+1]: i番目のものまで読むのにかかる総時間
  a.append(a[i]+As[i]) # 累積和の考え方
for i in range(M):
  # aのBバージョン
  b.append(b[i] + Bs[i])

ans = 0
j = M # Bから読める冊数の最大値を入れておく
for i in range(N+1):
  if a[i] > K: # 読めない
    break
  while b[j] > K-a[i]: #すべてのiに対して、a[i]+b[j]<=K になるjを求めたい
    j -= 1
  ans = max(ans, i+j) # i+jが最大値を更新したら記録

print(ans)
#dp[i][sum_v]:= i-1以下の品物の中から、価値をsum_v以上になる時の重さの最小値

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

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[10**12 for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i+1]]+w[i+1],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]

ans=0

for sum_v in range(N*max(v)+1):
    if dp[N+1][sum_v]<=W:
        ans=max(ans,sum_v)
print(ans)   

### FIXED CODE ###

#dp[i][sum_v]:= i-1以下の品物の中から、価値をsum_v以上になる時の重さの最小値

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

w,v=[0],[0]

for _ in range(N):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)

dp=[[10**12 for _ in range(N*max(v)+1)] for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(N*max(v)+1):
        if sum_v-v[i+1]>=0:
            dp[i+1][sum_v]=min(dp[i][sum_v-v[i+1]]+w[i+1],dp[i][sum_v])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]

ans=0

for sum_v in range(N*max(v)+1):
    if dp[N][sum_v]<=W:
        ans=max(ans,sum_v)
print(ans)
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
flag=0
if b==a:
    flag=1
elif (v-w)<0:
    pass
elif a>b:
    pass
elif abs((b-a)/(v-w))<=t:
    flag=1
if flag==1:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
flag=0
ky=abs(a-b)
if b==a:
    flag=1
elif w>=v:
    pass
elif abs((b-a)/(v-w))<=t:
    flag=1
if flag==1:
    print('YES')
else:
    print('NO')
h,w = map(int, input().split())
sl = []
for _ in range(h):
    row = list(input())
    sl.append(row)


dp = [ [10000]*h for _ in range(w) ]
dp[0][0] = 0

for wi in range(w):
    for hi in range(h):
        if wi+1 < w:
            if sl[wi][hi] == '.' and sl[wi+1][hi] == '#':
                dp[wi+1][hi] = min( dp[wi+1][hi], dp[wi][hi]+1 )
            else:
                dp[wi+1][hi] = min( dp[wi+1][hi], dp[wi][hi] )

        if hi+1 < h:
            if sl[wi][hi] == '.' and sl[wi][hi+1] == '#':
                dp[wi][hi+1] = min( dp[wi][hi+1], dp[wi][hi]+1 )
            else:
                dp[wi][hi+1] = min( dp[wi][hi+1], dp[wi][hi] )


ans = dp[w-1][h-1]
if sl[0][0] == '#': ans += 1
print(ans)


### FIXED CODE ###

from bisect import bisect_left, bisect_right

n = int(input())
al = list(map(int, input().split()))
al.sort()
ai = al[-1]
if ai%2 == 0:
    aj_best = ai//2
    ind = bisect_right(al, aj_best) - 1
    ind = ind if 0 <= ind < n else None
    val1 = al[ind] if ind is not None else 0

    ind = bisect_left(al, aj_best)
    ind = ind if 0 <= ind < n else None
    val2 = al[ind] if ind is not None else ai

    if abs(aj_best-val1) <= abs(aj_best-val2):
        aj = val1
    else:
        aj = val2


else:
    aj_best = ai//2
    ind = bisect_right(al, aj_best) - 1
    ind = ind if 0 <= ind < n else None
    val1 = al[ind] if ind is not None else 0

    ind = bisect_left(al, aj_best)
    ind = ind if 0 <= ind < n else None
    val2 = al[ind] if ind is not None else ai

    if abs(aj_best-val1) <= abs(aj_best+1-val2):
        aj = val1
    else:
        aj = val2

print(ai,aj)
# -*- coding: utf-8 -*-
import sys

N = input()
an = input()

s = set(sorted(an.split()))
print(sum(s))


### FIXED CODE ###

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

N = input()
an = input()
s = sorted(set(map(int, an.split())))
print(s[-1] - s[0])
n = int(input())
s = input()

if n%2==1:
  print('No')
else:
  if s[:n/2]==s[n/2:]:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

n = int(input())
s = str(input())
t = int(n/2)

if n%2==1:
  print('No')
else:
  if s[:t]==s[t:]:
    print('Yes')
  else:
    print('No')
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, (numbers))

n = int(input())
A = list(map(int, input().split()))
ans = gcd(*A)
print(str(ans))

### FIXED CODE ###

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
A = list(map(int, input().split()))
ans = gcd(*A)
print(str(ans))
while(1):
    e = int(input())
    if e == 0:
        break
    m = e
    for z in range(100):
        for y in range(1000):
            x = e - y * y - z * z * z
            if 0 > x:
                break
            if m > x + y + z:
                m = x + y + z
    print(m)


### FIXED CODE ###

while(1):
    e = int(input())
    if e == 0:
        break
    m, z = 10 ** 15, 0
    while z**3 <= e:
        y = int((e - z**3) ** 0.5)
        x = e - z**3 - y ** 2
        m = min(m, x + y + z)
        z += 1
    print(m)
N = int(input())

class edge:
    def __init__(self,_to,_cost):
        self.to = _to;
        self.cost = _cost;

tree = [[] for i in range(N)]

for i in range(N-1):
    a,b,c = list(map(int, input().split()))
    a = a - 1
    b = b - 1
    tree[a].append(edge(b,c))
    tree[b].append(edge(a,c))

Q, K = list(map(int, input().split()))
K = K - 1
depth = [0]*N

def DFS(v,p,d):
    depth[v] = d
    for e in tree[v]:
        if e.to==p :
            continue
        DFS(e.to, v, d + e.cost)

DFS(K,-1,0)

for q in range(Q):
    x,y = list(map(int, input().split()))
    x = x - 1
    y = y - 1
    print(depth[x] + depth[y])


### FIXED CODE ###

import sys;sys.setrecursionlimit(int(1e7))

class edge():
    def __init__(self,_to,_cost):
        self.to = _to;
        self.cost = _cost;

N = int(input())
tree = [[] for i in range(N+1)]

for i in range(N-1):
    a,b,c = map(int,input().split())
    a = a - 1
    b = b - 1
    tree[a].append(edge(b,c))
    tree[b].append(edge(a,c))
Q,K = map(int,input().split())
K = K - 1
depth = [None]*N

def DFS(v,p,d):
    depth[v] = d
    for e in tree[v]:
        if e.to == p:
            continue
        DFS(e.to, v, d + e.cost)
DFS(K,-1,0)

for _ in range(Q):
    x,y = map(int, input().split())
    x = x - 1
    y = y - 1
    print(depth[x] + depth[y])
a, b = map(raw_input().split(" "))
print a*b, (a+b)*2

### FIXED CODE ###

a, b = map(int, raw_input().split(" "))
print a*b, (a+b)*2
a = input()
a = int(a)

b = input()
b = int(b)

c = input()
c = int(c)

d = input()
d = int(d)

ans = 0

for i in range(0, a+1):
  for j in range(0, b+1):
    for k in range(0, c+1):
      if x == i*500 + j*100 + k*50:
        ans = ans + 1

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if d == 500*i + 100*j + 50*k:
        ans += 1
print(ans)
n,m = map(int,input().split())
l = list(int(input() for i in range(1,n+1)))
cnt = 0
for j in range(0,n):
  if l[j]/(sum(l)) >= 1/(4*m):
    cnt += 1
if cnt >= m:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n,m = map(int,input().split())
l = list(map(int,input().split()))
cnt = 0
for i in l:
  if i >= sum(l)/(4*m):
    cnt += 1
if cnt >= m:
  print('Yes')
else:
  print('No')