Harryxun/stf_run huggingface dataset:
from collections import deque
h, w = map(int, input().split())
cnt_b = 0
s = []
for i in range(h):
    si = input()
    cnt_b += si.count('#')
    s.append(si)

def bfs(i0, j0):
    INF = 1000
    search = deque([(i0, j0)])
    d = [[INF] * w for i in range(h)]
    d[i0][j0] = 1
    while search:
        i, j = search.popleft()
        if (i, j) == (h - 1, w - 1):
            break
        for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < h and 0 <= nj < w and s[ni][nj] == '.' and d[ni][nj] == INF:
                search.append((ni, nj))
                d[ni][nj] = d[i][j] + 1
    return d[i][j] if d[i][j] != INF else 0 
solvable = bds(0, 0)
print(h*w - cnt_b - solvable if solvable else -1)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
cnt_b = 0
s = []
for i in range(h):
    si = input()
    cnt_b += si.count('#')
    s.append(si)

def bfs(i0, j0):
    INF = 1000
    search = deque([(i0, j0)])
    d = [[INF] * w for i in range(h)]
    d[i0][j0] = 1
    while search:
        i, j = search.popleft()
        if (i, j) == (h - 1, w - 1):
            break
        for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < h and 0 <= nj < w and s[ni][nj] == '.' and d[ni][nj] == INF:
                search.append((ni, nj))
                d[ni][nj] = d[i][j] + 1
    return d[i][j] if d[h - 1][w - 1] != INF else 0 
solvable = bfs(0, 0)
print(h*w - cnt_b - solvable if solvable else -1)
a, b = map(int, input().split())
def curtain(a,b):
    if a <= b*2:
        return 0
    else:
        return a - b * 2
print(curtain(a,b))

### FIXED CODE ###

a, b = map(int, input().split())
def curtain(a,b):
    if a <= b*2:
        return 0
    else:
        return a - b * 2
print(curtain(a,b))
result=[]
N = int(input())
W = list(map(int,input().split()))
for i in range(1:N+1):
  a = W[:i]
  b = W[i+1:N]
  c = sum(a)
  d = sum(b)
  e = abs(c-d)
  result.append(e)
 
print(min(result))

### FIXED CODE ###

i = list(map(int,input().split()))
a = i[0]+i[1]
b = i[0]+i[2]
c = i[1]+i[2]
d = [a,b,c]
print(min(d))
k_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(k_list[K])

### FIXED CODE ###

k_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(k_list[K-1])
n,k=map(int,input().split())
p=list(map(intinput().split()))
p.sort()
q=p[:k]
print(sum(q))
       

### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
q=p[:k]
print(sum(q))
import math


def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    mul = a[0]
    for i in range(1, n):
        mul = mul * a[i] // math.gcd(mul, a[i])
    ans = (m - mul / 2) // mul + 1
    print(int(ans))


if __name__ == '__main__':
    main()


### 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)
*a,=map(int,open(0))

### FIXED CODE ###

print('bwuisnt'[sum(map(int,input().split()))<22::2])
# -*- coding: utf-8 -*-
A = input();
B = input();
K = input();

for lop in range(int(A),int(A)+int(K)):
    if lop > int(B):
        break;
    print(lop);
    fg = lop;
        
if int(B)-int(K)+1 >= int(A):
    if fg+1 < int(B)-int(K)+1:
        fg = int(B)-int(K)+1;
    else:
        fg+=1
    for lop in range(fg,int(B)):
        print(lop);
    print(B);

### FIXED CODE ###

# -*- coding: utf-8 -*-
data = input().split(" ");
A = data[0];
B = data[1];
K = data[2];

for lop in range(int(A),int(A)+int(K)):
    if lop > int(B):
        break;
    print(lop);
    fg = lop;
        
if int(B)-int(K)+1 >= int(A):
    if fg+1 < int(B)-int(K)+1:
        fg = int(B)-int(K)+1;
    else:
        fg+=1
    for lop in range(fg,int(B)+1):
        print(lop);
#スペース区切りの整数の入力
A, B, C = map(int, input().split())

A = float(A)
B = float(B)
C = float(C)


A_sq = pow(A, 0.5)
B_sq = pow(B, 0.5)
C_sq = pow(C, 0.5)

if(A_sq+B_sq < C_sq):
  print("Yes")
else:
  print("No")




### FIXED CODE ###

#整数の入力
A = int(input())

list_a = [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]

print(list_a[A-1])
a, b, c, d = map(int, input())
print("Yes" if abs(c - a) <= d or (abs(c - b) <= d and abs(a - b) <= d) else "No")

### FIXED CODE ###

a, b, c, d = map(int, input().split())
print("Yes" if abs(c - a) <= d or (abs(c - b) <= d and abs(a - b) <= d) else "No")
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
BC = [tuple(int(_) for _ in input().split()) for i in range(M)]


A = sorted(A)
BC = sorted(BC, key=lambda x:-x[1])

#print(A, BC)

i = 0
for b, c in BC:
    if i > N:
        break
    for j in range(b):
        if i > N or A[i] >= c:
            break
        A[i] = c
        i += 1
    
#print(A, BC)

result = sum(A)

print(result)


### FIXED CODE ###

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
BC = [tuple(int(_) for _ in input().split()) for i in range(M)]


A = sorted(A)
BC = sorted(BC, key=lambda x:-x[1])

#print(A, BC)

i = 0
for b, c in BC:
    if i > N:
        break
    for j in range(b):
        if i >= N or A[i] >= c:
            break
        A[i] = c
        i += 1
    
#print(A, BC)

result = sum(A)

print(result)
s = list(input())
print(len(set(s))

### FIXED CODE ###

s = list(input().split())
print(len(set(s)))
from math import gcd
a, b = map(int, input().split())
print(gcd(a,b))

### FIXED CODE ###

from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b = map(int, input().split())
print(lcm(a,b))
import numpy as np

s = input()
N = len(s)

# 縦：じゃんけんの回数(0回含む）、横：パーを出した回数 そのときの最大スコア
# 1回目のじゃんけんではパーは出せない
scores = np.zeros((N + 1, N + 1), np.int64)

for i in range(2, N + 1):
    if s[i - 1] == 'g':
        scores[i, 0] = scores[i - 1, 0]
        scores[i, 1:i // 2 + 1] = np.maximum(scores[i - 1, :i // 2] + 1, scores[i - 1, 1:i // 2 + 1])
    else:
        scores[i, 0] = scores[i - 1, 0] - 1
        scores[i, 1:i // 2 + 1] = np.maximum(scores[i - 1, :i // 2], scores[i - 1, 1:i // 2 + 1] - 1)

print(scores[-1].max())

### FIXED CODE ###

s = input()

print(-s.count('p') + len(s) // 2)
x = int(raw_input("Enter number:"))
print int(x**3)

### FIXED CODE ###

print ((int(raw_input()))**3)
H, W = map(int, input().split())

INPUT = [list(input()) for i in range(H)]
OUTPUT = INPUT.copy()

for i in range(H):
    for j in range(W):
        if INPUT[i][j] == '#':
            OUTPUT[i][j] = '#'a
        else:
            OUTPUT[i][j] = 0
            for I in (i-1, i, i+1):
                if not (I < 0 or H <= I):
                    for J in (j-1, j, j+1):H, W = map(int, input().split())

INPUT = [list(input()) for i in range(H)]
OUTPUT = INPUT.copy()

for i in range(H):
    for j in range(W):
        if INPUT[i][j] == '#':
            OUTPUT[i][j] = '#'
        else:
            OUTPUT[i][j] = 0
            for I in (i-1, i, i+1):
                if not (I < 0 or H <= I):
                    for J in (j-1, j, j+1):
                        if not (J < 0 or W <= J):
                            if INPUT[I][J] == '#':
                                OUTPUT[i][j] += 1


for i in range(H):
    print(''.join(map(str, OUTPUT[i])))

                        if not (J < 0 or W <= J):
                            if INPUT[I][J] == '#':
                                OUTPUT[i][j] += 1


for i in range(H):
    print(''.join(map(str, OUTPUT[i])))


### FIXED CODE ###

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

INPUT = [list(input()) for i in range(H)]
OUTPUT = INPUT.copy()

for i in range(H):
    for j in range(W):
        if INPUT[i][j] == '#':
            OUTPUT[i][j] = '#'
            continue
        else:
            OUTPUT[i][j] = 0
            for I in (i-1, i, i+1):
                if (I < 0 or H <= I):
                    continue
                for J in (j-1, j, j+1):
                    if (J < 0 or W <= J):
                        continue
                    if INPUT[I][J] == '#':
                        OUTPUT[i][j] += 1


for i in range(H):
    print(''.join(map(str, OUTPUT[i])))
def cross(x, y):
    return (x.conjugate() * y).imag
 
def area_polygon(points):
    area = 0
    n = len(points)
    for i in range(n):
        area += cross(points[i], points[(i+1)%n])
    return area / 2
     
     
import sys
 
p = []
for line in sys.stdin:
    x, y = map(float, line.split(','))
    p.append(x+y*1j))
 
print(abs(area_polygon(p)))

### FIXED CODE ###

def op(u,v):
    return (complex.conjugate(u)*v).imag

f = []
while True:
    try:
        st = input().strip().split(',')
        x,y = list(map(float,st ))
        f.append(x + y*1j)
    except EOFError:
        break

s = 0.0
fo = f[0]
for j in range(2,len(f)):
    i = j - 1
    s += op(f[i]-fo,f[j]-fo)/2.0
print("%.6f" % abs(s))
S = int(input())
h = S//3600
m = (S//60)-(S//3600)
s = S//60
print(h,:,m,:,s)



### FIXED CODE ###

S = int(input())
h = S//3600
m = (S//60)-60*(S//3600)
s = S%60
print('{}:{}:{}'.format(h,m,s))
t = [int(input()) for i in range(5)]
r = [x%10 for x in t]
if all(x==0 for x in r):
  print(sum(t))
else:
  y = sorted(set(r))[1]
  print(sum(x if x%10==0 else 10*(1+x//10) for x in t) -10+y)

### FIXED CODE ###

t = [int(input()) for i in range(5)]
r = [x%10 for x in t]
if all(x==0 for x in r):
  print(sum(t))
else:
  y = min(set(r)-{0})
  print(sum(x if x%10==0 else 10*(1+x//10) for x in t) -10+y)
n,m = map(int,input().split())
ali = [int(input()) for _ in range(m)]
dif = []
cap = 0
for num in ali:
  dif.append(num-cap)
  cap = num
dif.append(n-cap+1)
dif[0] += 1
ref = [0,0,1,1]
a,b = 1,1
if m <= 10000:
  nnn = 1000
else:
  nnn = 100000
for i in range(nnn):
  a,b = b,a+b 
  ref.append(b)
ans = 1
for num in dif:
  ans *= (ref[num] % 1000000007)
print(ans % 1000000007)

### FIXED CODE ###

n,m = map(int,input().split())
ali = [int(input()) for _ in range(m)]
dif = []
cap = 0
for num in ali:
  dif.append(num-cap)
  cap = num
dif.append(n-cap+1)
dif[0] += 1
ref = [0,0,1,1]
a,b = 1,1
for i in range(100000):
  a,b = b,a+b 
  ref.append(b)
ans = 1
for num in dif:
  ans *= (ref[num] % 1000000007)
print(ans % 1000000007)
#解説解法
n = int(input())
xp = []
xm = []
yp = []
ym = []
for _ in range(n):
  x,y = map(int,input().split())
  if x == 0:
    if y == 0:
      n -= 1
    elif y > 0:
      yp.append([0,x,y])
    else:
      ym.append([0,x,y])
  elif x > 0:
    xp.append([y/x,x,y])
  else:
    xm.append([y/x,x,y])
xp.sort()
xm.sort()
xy = xp + yp + xm + ym
can = []
for i in range(-n,0):
  for j in range(i+1,i+n+1):
    X = 0
    Y = 0
    for k in range(i,j):
      x,y = xy[k][1],xy[k][2]
      X += x
      Y += y
    can.append(X**2+Y**2)
print(max(can)**.5)

### FIXED CODE ###

#解説解法
n = int(input())
xp = []
xm = []
yp = []
ym = []
for _ in range(n):
  x,y = map(int,input().split())
  if x == 0:
    if y == 0:
      n -= 1
    elif y > 0:
      yp.append([0,x,y])
    else:
      ym.append([0,x,y])
  elif x > 0:
    xp.append([y/x,x,y])
  else:
    xm.append([y/x,x,y])
xp.sort()
xm.sort()
xy = xp + yp + xm + ym
can = []
for i in range(-n,0):
  for j in range(i+1,i+n+1):
    X = 0
    Y = 0
    for k in range(i,j):
      x,y = xy[k][1],xy[k][2]
      X += x
      Y += y
    can.append(X**2+Y**2)
if n == 0:
  print(0)
else:
  print(max(can)**.5)
X=int(input())
import numpy as np
t=int(X**(1/5))+10
a=[]
for i in range(t):
    a.append(i**5)

b=[]
for i in range(t):
    for j in range(i+1,t):
        if a[i]+a[j]==X:
            b.append([i,-j])
        if a[j]-a[i]==X:
            b.append([i,j])
        
print(b[0][0],b[0][1])




### FIXED CODE ###

x = int(input())
a=0
b=0
for i in range(-400,400):
    for j in range(-400,400):
        if i**5 - j**5 == x:
            a = i
            b = j
            exit

print(a,b)
h = int(input())
w = int(input())
n = int(input())
count = 0
if(h >= w):
    while(n > h):
    n -= h
    count += 1
print(count)
else:
    while(n > w):
    n -= w
    count += 1
print(count)

### FIXED CODE ###

h = int(input())
w = int(input())
n = int(input())
ha = h
wa = w
count = 1
if(h >= w):
    while(n > ha):
        ha += h
        count += 1
    print(count)
else:
    while(n > wa):
        wa += w
        count += 1
    print(count)
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
dif=[]
count=0
for i in range(N):
    dif.append(V[i]-C[i])

dif.sort(reverse=True)

i=0
while (dif[i]>=0)and(i<=N-1):
    count=count+dif[i]
    i=i+1

print(count)

### FIXED CODE ###

N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
dif=[]
count=0
for i in range(N):
    dif.append(int(V[i]-C[i]))

dif.sort(reverse=True)

i=0
for i in range(N):
    if dif[i]>=0:
        count=count+dif[i]
    else:
        break

print(count)
<?php
//https://stackoverflow.com/questions/5506888/permutations-all-possible-sets-of-numbers

function pc_permute($items, $perms = array( )) {
    if (empty($items)) {
        // もう取り出すものがなければその時点の$permsが順列の一つなのでそのまま返却 
        $return = array($perms);
    } else {
        $return = array();
        // 並んでる数字を順番にみてく
        for ($i =  0; $i < count($items); $i++) {
            // 処理対象の配列と、組み合わせを保持してる変数を別変数にコピー
            // array_spliceなどは破壊的なメソッドなので退避しないと元配列が変更される
            $newitems = $items;
            $newperms = $perms;
            // インデックスが$iの値を$fooにとる。($newitemsからは削除される)
            list($foo) = array_splice($newitems, $i, 1);
            // 取り除いた値（$foo)を組み合わせの候補の先頭に持ってくる
            array_unshift($newperms, $foo);
            // 最終的に呼び出し元に返却する配列に追加する
            // 追加する配列は、一文字削ったあとの$newitems,
            // 現段階での組み合わせの$newpermsを引数に、再帰的に自分を呼び出した結果
            $return = array_merge($return, pc_permute($newitems, $newperms));
        }
    }
    return $return;
}

// ----------------------------------------------------
// こっから実際に解く
// ----------------------------------------------------

// 入力値の取得（int変換)
$N = intval(trim(fgets(STDIN)));
// 入力値の取得（配列化）
$P = explode(" ",trim(fgets(STDIN));
$Q = explode(" ",trim(fgets(STDIN));

// 順列の生成
$a = range(1,$N);
$permutated = pc_permute($a);
sort($permutated);

$p_index = -1;
$q_index = -1;

// 列挙した順列をfor文で確認していき、PとQの位置を確認する
for ($i=0; $i < count($permutated); $i++){
  if ($permutated[$i] == $P){
    $p_index = $i;
  }
  if ($permutated[$i] == $Q){
    $q_index = $i;
  }
}

// 答えの計算
$ans = abs($p_index - $q_index);
printf("%d\n",$ans);


### FIXED CODE ###

import itertools

def main():
    N = int(input())
    
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    
    combi = list(itertools.permutations(range(1, N+1)))
    
    pi = 0
    qi = 0
    for i in range(len(combi)):
        if list(combi[i]) == P:
            pi = i + 1
        if list(combi[i]) == Q:
            qi = i + 1
            
            
    print(abs(qi - pi))
    
main()
n = int(input())
data = [list(map(int, input().split())) for _ in range(n)]
nums = [[[0 for i in range(10)] for i in range(3)] for i in range(4)]
for d in data:
    nums[d[0] - 1][d[1] - 1][d[2] - 1] += d[3]
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(' ' + nums[i][j][k], end='')
        print('')
    if i != 3:
        print('#' * 20)

### FIXED CODE ###

n = int(input())
data = [list(map(int, input().split())) for _ in range(n)]
nums = [[[0 for i in range(10)] for i in range(3)] for i in range(4)]
for d in data:
    nums[d[0] - 1][d[1] - 1][d[2] - 1] += d[3]
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(' ' + str(nums[i][j][k]), end='')
        print('')
    if i != 3:
        print('#' * 20)
import math

n = int(input())
a = [int(i) for i in input().split()]
mn1 = min(a)
a.remove(mn1)
mn2 = min(a)
ko = math.gcd(mn2,mn1)
print(ko)

### FIXED CODE ###

import fractions

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

for i in range(1,n):
    if i==1:
        ko = fractions.gcd(a[1],a[0])
    else:
        ko = fractions.gcd(ko,a[i])
print(ko)
import sys

def match(a, b):
    for i in range(len(a)):
        if a[i] != '?' and b[i] != '?' and a[i] != b[i]:
            return False
    return True


Y=str(input())
T=str(input())
S = ''
if match(T,Y[-len(T):]):
    S = Y[:-len(T)] + T
    A = S.replace('?','a')
    print(A)
    sys.exit()
else:
    for i in range(len(Y) - len(T)):
        i += 1
        k = -(len(T)+i)
        if match(T, Y[k:-i]):
            S = Y[:k] + T + Y[-i:]
            A = S.replace('?','a')
            print(A)
            sys.exit()

print('UNRESTORABLE')

### FIXED CODE ###

import sys

def match(a, b):
    for i in range(len(a)):
        if a[i] != '?' and b[i] != '?' and a[i] != b[i]:
            return False
    return True


Y=str(input())
T=str(input())
S = ''
if len(Y) < len(T):
    print('UNRESTORABLE')
    sys.exit()

if match(T,Y[-len(T):]):
    S = Y[:-len(T)] + T
    A = S.replace('?','a')
    print(A)
    sys.exit()
else:
    for i in range(len(Y) - len(T)):
        i += 1
        k = -(len(T)+i)
        if match(T, Y[k:-i]):
            S = Y[:k] + T + Y[-i:]
            A = S.replace('?','a')
            print(A)
            sys.exit()

print('UNRESTORABLE')
n = input()
a = list(input().split())

b = set(a)

if len(a) == len(b):
  print(YES)
else:
  print(NO)

### FIXED CODE ###

n = input()
a = list(input().split())

b = set(a)

if len(a) == len(b):
  print("YES")
else:
  print("NO")
a = list.map(int, input().split())

a.sort()

print(a[0], a[1], a[2])



### FIXED CODE ###

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

a.sort()

print(a[0], a[1], a[2])
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    c = get_pity_sum(int((N - 1) / 2))
    if N == 1:
        print(c)
    print(min(c, get_pity_sum(int((N - 1) / 2 - 1)), c + (A[int((N - 1) / 2) + 1] - A[int((N - 1) / 2)]) * 2, c + (A[int((N - 1) / 2)] - A[int((N - 1) / 2 - 1)]) * 2))
else:
    d = get_pity_sum(int(N / 2))
    print(min(get_pity_sum(int(N / 2)), d + (A[int(N / 2) + 1] - A[int(N / 2)]) * 2))

### FIXED CODE ###

from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    c = get_pity_sum(int((N - 1) / 2))
    if N == 1:
        print(c)
    else:
        print(min(c, get_pity_sum(int((N - 1) / 2 - 1)), c + (A[int((N - 1) / 2) + 1] - A[int((N - 1) / 2)]) * 2, c + (A[int((N - 1) / 2)] - A[int((N - 1) / 2 - 1)]) * 2))
else:
    d = get_pity_sum(int(N / 2))
    print(min(get_pity_sum(int(N / 2)), d + (A[int(N / 2) + 1] - A[int(N / 2)]) * 2))
from collections import deque
n=int(input())
S=list(input())
G=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
ans=10**10
for i in range(n):#根
  D=deque([i])
  A=[i]
  V=[0]*n
  V[i]=1
  C=[[] for i in range(n)]
  while len(D)>0:
    x=D[0]
    D.popleft()
    for j in range(len(G[x])):
      if V[G[x][j]]==0:
        V[G[x][j]]=1
        D.append(G[x][j])
        A.append(G[x][j])
        C[x].append(G[x][j])
  A=A[::-1]
  Ans=[[0]*3 for i in range(n)]
  for v in A:
    if len(C[v])==1:
      vc=C[v][0]
      Ans[v]=[Ans[vc][0],Ans[vc][1]+Ans[vc][2],Ans[vc][2]]
    elif len(C[v])!=0:
      L=[]
      LL=[]
      cc=0
      s=0
      M=0
      for vc in C[v]:
        m=Ans[vc][1]+Ans[vc][2]
        if m>M:
          M=m
          MM=Ans[vc][0]
        L.append(Ans[vc][1]+Ans[vc][2])
        LL.append(2*Ans[vc][0]+Ans[vc][1]+Ans[vc][2])
        cc=cc+Ans[vc][2]
        s=s+Ans[vc][0]
      if sum(LL)-M-2*MM>=M:
        ss=sum(L)//2
      else:
        ss=sum(LL)-M-2*MM-s
      Ans[v]=[s+ss,sum(L)-2*ss,cc]
    if S[v]=="1":
      Ans[v][2]+=1
  if Ans[i][1]==0:
    if Ans[i][0]<ans:
      ans=Ans[i][0]
if ans==10**10:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

from collections import deque
n=int(input())
S=list(input())
G=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
ans=10**10
AAA=10**10
for i in range(n):#根
  D=deque([i])
  A=[i]
  V=[0]*n
  V[i]=1
  C=[[] for i in range(n)]
  while len(D)>0:
    x=D[0]
    D.popleft()
    for j in range(len(G[x])):
      if V[G[x][j]]==0:
        V[G[x][j]]=1
        D.append(G[x][j])
        A.append(G[x][j])
        C[x].append(G[x][j])
  A=A[::-1]
  Ans=[[0]*3 for i in range(n)]
  for v in A:
    if len(C[v])==1:
      vc=C[v][0]
      Ans[v]=[Ans[vc][0],Ans[vc][1]+Ans[vc][2],Ans[vc][2]]
    elif len(C[v])!=0:
      L=[]
      LL=[]
      cc=0
      s=0
      M=0
      MM=0
      for vc in C[v]:
        m=Ans[vc][1]+Ans[vc][2]
        if m>M:
          M=m
          MM=Ans[vc][0]
        L.append(Ans[vc][1]+Ans[vc][2])
        LL.append(2*Ans[vc][0]+Ans[vc][1]+Ans[vc][2])
        cc=cc+Ans[vc][2]
        s=s+Ans[vc][0]
      if sum(LL)-M-2*MM>=M:
        ss=sum(L)//2
      else:
        ss=sum(LL)-M-2*MM-s+MM
      Ans[v]=[s+ss,sum(L)-2*ss,cc]
    if S[v]=="1":
      Ans[v][2]+=1
  if Ans[i][1]==0:
    if Ans[i][0]<ans:
      ans=Ans[i][0]
if ans==10**10:
  print(-1)
else:
  print(ans)
s = list(map(int,input()))

print(2*mmin(s.count(0), s.count(1))

### FIXED CODE ###

s = input()

one = s.count("1")
zero = s.count("0")

print(2 * min(one, zero))
A,B,C,D = input().split(' ')
A,B,C,D = [int(A),int(B),int(C),int(D)]

L= A + B
R = C + D

if L>R:
	print("Left")
elif L=R:
	print("Balanced")
else:
	print("Right")


### FIXED CODE ###

A,B,C,D = input().split(' ')
A,B,C,D = [int(A),int(B),int(C),int(D)]

L= A + B
R = C + D

if L>R:
	print("Left")
elif L==R:
	print("Balanced")
else:
	print("Right")
n=int(input())
t,a=map(int,input().split())
h=map(int,input().split())
x=100000
ans=0
for i in h:
  if abs(t-i*0.006-a)<x:
    ans=index(i)
print(ans)


### FIXED CODE ###

n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
min = 1000
for i in range(n):
  T = t - h[i] * 0.006
  if abs(T-a) < min:
    min = abs(T-a)
    ans = i + 1
print(ans)
mod=int(1e9+7)
n,k=map(int,input().split())
g=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  a-=1; b-=1
  g[a].append(b); g[b].append(a);

dp=[-1 for x in range(n)]
def f(v,p):
  if dp[v]!=-1:
    return dp[v]
  
  s=0
  if p>=0:
    s=len(g[p])

  dp[v]=max(k-s,0)
  for i in g[v]:
    if i!=p:
      dp[v]=(dp[v]*f(i,v))%mod
  return dp[v]

print(f(0,-1))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)

mod=int(1e9+7)
n,k=map(int,input().split())
g=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  a-=1; b-=1
  g[a].append(b); g[b].append(a);
 
dp=[-1 for x in range(n)]
def f(v,p):
  if dp[v]!=-1:
    return dp[v]

  dp[v]=1
  j=1+int(v!=0)
  for i in g[v]:
    if i!=p:
      dp[v]=(dp[v]*f(i,v)*max(k-j,0))%mod
      j+=1
  return dp[v]
 
print(f(0,-1)*k%mod)
n,d=[int(i) for i in input().strip().split(" ")]
ans=0
for _ in range(n):
  x,y=[int(i) for i in input().strip().split(" ")]
  if x*x+y*y=d*d:
    ans+=1
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Aug 24 12:23:05 2020

@author: vivek
"""

n,d=[int(i) for i in input().strip().split(" ")]
ans=0
for _ in range(n):
  x,y=[int(i) for i in input().strip().split(" ")]
  if x*x+y*y<=d*d:
    ans+=1
print(ans)