Harryxun/stf_run huggingface dataset:
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
y = [num for num in range(1, n+1)]
permutation_n = list(itertools.permutations(y, 3))

a=b=0
count=1
for permu in permutation_n:
  if permu == p:
    a = count
  if permu == q:
    b = count
  if a != 0 and b != 0:
    break
  count+=1
print(abs(a-b))

### FIXED CODE ###

k,x = map(int, input().split())
if 500*k >= x:
  print('Yes')
  exit()
print('No')
n = input()
print(input[:4] + "8" + [5:])

### FIXED CODE ###

str = input()
print(str[:3] + "8" + str[4:])
N=int(input())
alist=[0]+list(map(int,input().split()))

answer=0
for i in range(1,N+1):
  if alist[i]==i:
    alist[i],alist[i+1]=alist[i+1],alist[i]
    answer+=1
    
print(answer)

### FIXED CODE ###

N=int(input())
alist=[0]+list(map(int,input().split()))

answer=0
if alist[N]==N:
  alist[N-1],alist[N]=alist[N],alist[N-1]
  answer+=1

for i in range(1,N+1):
  if alist[i]==i:
    alist[i],alist[i+1]=alist[i+1],alist[i]
    answer+=1
    
print(answer)
print("YNeos"[len(set(map(int,open(0))))!=2::2])

### FIXED CODE ###

print("YNeos"[len(set(map(int,input().split())))!=2::2])
import heapq

#dg = 10**7#ノード数より多く取る

n,m, S = map(int,input().split()) #n:頂点数　m:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列


Cs=[]
Ds=[]
amax=0
for _ in range(m):
    u, v, a, b = map(int,input().split())
    edge[u-1].append([v-1,a,b])
    edge[v-1].append([u-1,a,b])#有向グラフの場合コメント
    amax=max(a,amax)

for _ in range(n):
    c, d = map(int,input().split())
    Cs.append(c)
    Ds.append(d)

dg=(n-1)*amax

def cut(S): 
    if S>dg:
        return dg
    else: return S

S=cut(S)

def dijkstra(start):

    #dijkstra
    # d : minimum distance from s
    d = [[10**20]*(dg+1) for _ in range(n)]
    d[start][cut(S)] = 0
    edgelist = []

    heapq.heappush(edgelist,(Ds[0], 0, cut(S+Cs[0])))

    for e in edge[start]:
        if S-e[1]>=0:
            heapq.heappush(edgelist,[e[2],e[0],S-e[1]])

    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        t,ce,cs = minedge[0],minedge[1],minedge[2]
        #print(t,ce,cs)
        if  d[ce][cs]== 10**20:
            d[ce][cs] = t
            ns=cut(cs+Cs[ce])
            #print(ce,ns)
            if d[ce][ns]==10**20:
                #d[ce][ns]=t+Ds[ce]
                heapq.heappush(edgelist, [t+Ds[ce],ce,ns])

            for e in edge[ce]:
                if cs>=e[1]:
                    #print(e)
                    ne=e[0]
                    ns=cs-e[1]
                    if d[ne][ns]==10**20:
                        #print(ne)
                        heapq.heappush(edgelist, [t+e[2],ne,ns])
    return d

d=dijkstra(start=0)
for x in d[1:]:
    print(min(x))
#print(d)


### FIXED CODE ###

import heapq

#dg = 10**7#ノード数より多く取る

n,m, S = map(int,input().split()) #n:頂点数　m:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列


Cs=[]
Ds=[]
amax=0
for _ in range(m):
    u, v, a, b = map(int,input().split())
    edge[u-1].append([v-1,a,b])
    edge[v-1].append([u-1,a,b])#有向グラフの場合コメント
    amax=max(a,amax)

for _ in range(n):
    c, d = map(int,input().split())
    Cs.append(c)
    Ds.append(d)

dg=(n-1)*amax

def cut(S): 
    if S>dg:
        return dg
    else: return S

S=cut(S)

def dijkstra(start):

    #dijkstra
    # d : minimum distance from s
    d = [[10**20]*(dg+1) for _ in range(n)]
    d[start][cut(S)] = 0
    edgelist = []

    heapq.heappush(edgelist,(Ds[0], 0, cut(S+Cs[0])))

    for e in edge[start]:
        if S-e[1]>=0:
            heapq.heappush(edgelist,(e[2],e[0],S-e[1]))

    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        t,ce,cs = minedge[0],minedge[1],minedge[2]
        #print(t,ce,cs)
        if  d[ce][cs]== 10**20:
            d[ce][cs] = t
            ns=cut(cs+Cs[ce])
            #print(ce,ns)
            if d[ce][ns]==10**20:
                #d[ce][ns]=t+Ds[ce]
                heapq.heappush(edgelist, (t+Ds[ce],ce,ns))

            for e in edge[ce]:
                if cs>=e[1]:
                    #print(e)
                    ne=e[0]
                    ns=cs-e[1]
                    if d[ne][ns]==10**20:
                        #print(ne)
                        heapq.heappush(edgelist, (t+e[2],ne,ns))
    return d

d=dijkstra(start=0)
for x in d[1:]:
    print(min(x))
#print(d)
import math

X , Y =map(int,input().split())
X1=X
Y1=Y
x=0
y=0
if(X>Y):
    x=X-Y
    X1-=2*x
    Y1-=x
else:
    y=Y-X
    X1-=y
    Y1-=2*y
if(X1<0 or Y1<0 or X1%3!=0 or Y1%3!=0):
    print(0)
x+=X1//3
y+=X1//3


print((math.factorial(x+y)//(math.factorial(x)*math.factorial(y)))//((10**9)+7))

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

x, y = map(int, input().split())

mod = 10**9+7 #出力の制限
g1 = [1]*(x+y) # 元テーブル
g2 = [1]*(x+y) #逆元テーブル
inverse = [1]*(x+y)
inverse[0] = 1

if (x+y)%3 != 0 :
  print(0)
else:
  n = (x + y) // 3
  if x >= n and y >= n:
    a = x - n
    b = y - n
    
    for i in range(2, n + 1):
      g1[i]=( g1[i-1] * i ) % mod 
      inverse[i]=( -inverse[mod % i] * (mod//i) ) % mod 
      g2[i]=(g2[i-1] * inverse[i]) % mod
    
    answer = cmb(a+b,a,mod)
    print(answer)
  else:
    print(0)
import itertools
P,Q = list(map(int,input().split()))
N = int(input())
L = [list(i) for i in itertools.permutations(range(1, N+1), r=N)]
print(abs(L.index(P) - L.index(Q)))

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
import itertools
L = [list(i) for i in itertools.permutations(range(1, N+1), r=N)]
print(abs(L.index(P) - L.index(Q)))
l,r = map(int,input().split())


from itertools import combinations

A = list(range(l,r+1))

ans_L = [i[0]*i[1]%2019 for i in combinations(A,2)]
print(sorted(ans_L)[0])

### FIXED CODE ###

from itertools import combinations
import sys

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

if r-l> 2019:
    print(0)
    sys.exit(0)

A = list(range(l,r+1))

ans_L = [i[0]*i[1]%2019 for i in combinations(A,2)]
print(sorted(ans_L)[0])
N=int(input())
s=list(input() for _ in range(N))
ans=0
count=0
a_count=0
b_count=0
ab_count=0
for i in s:
    ans+=i.count('AB')
    if i[0]=='B'and i[-1]=='A':
        ab_count+=1
    elif i[0]=='B':
        b_count+=1
    elif i[-1]=='A':
        a_count+=1
print(ans+min(a_count,b_count)+ab_count if a_count+b_count!=0 else ans+max(ab_count-1,0))

### FIXED CODE ###

m=int(input())
pf={m:1}
a=[0]
for i in range(2,int(m**0.5)+1):
    if m ==1:
        break
    pf[i]=pf.get(i,0)+1
    if i!=m//i:
        pf[m//i]=pf.get(m//i,0)+1
for i in pf:
    if m!=1and m//(i-1)==m%(i-1):
        a.append(a[-1]+i-1)
print(a[-1])
MOD = 10**9 + 7

N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)

def dfs(pos: int, par: int):
    # posが白の時 -> 子はなんでも良い
    # posが黒の時 -> 子は全て白
    all = 1
    black = 1
    for v in G[pos]:
        if v != par:
            tmp = dfs(v, pos)
            all *= sum(tmp)
            black *= tmp[0]
            all %= MOD
            black %= MOD
    return [all, black]  # [白, 黒]

print(sum(dfs(0, 0)))

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(10**6)

MOD = 10**9 + 7

N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)

def dfs(pos: int, par: int):
    # posが白の時 -> 子はなんでも良い
    # posが黒の時 -> 子は全て白
    white = 1
    black = 1
    for v in G[pos]:
        if v != par:
            tmp = dfs(v, pos)
            white *= sum(tmp)
            black *= tmp[0]
            white %= MOD
            black %= MOD
    return [white, black]  # [白, 黒]

print(sum(dfs(0, 0))%MOD)
#!/usr/bin/env python3
import sys
import bisect

MOD = 1000000007  # type: int

def is_ok(i,a):
    ii = bisect.bisect_left(a,i)
    if ii >= len(a):
        return True
    return i != a[ii]


def solve(N: int, M: int, a: "List[int]"):
    dp = [0]*N
    dp[0] = 1 if is_ok(1,a) else 0
    if is_ok(2,a):
        if is_ok(1,a):
            dp[1] = 2
        else:
            dp[1] = 1

    for i in range(2,N):
        if is_ok(i+1,a):
            dp[i] = dp[i-1] + dp[i-2]

    print(dp[N-1] % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import bisect

MOD = 1000000007  # type: int

def is_ok(i,a):
    ii = bisect.bisect_left(a,i)
    if ii >= len(a):
        return True
    return i != a[ii]


def solve(N: int, M: int, a: "List[int]"):
    dp = [0]*N
    dp[0] = 1 if is_ok(1,a) else 0

    if N > 1:
        if is_ok(2,a):
            if is_ok(1,a):
                dp[1] = 2
            else:
                dp[1] = 1

    if N > 2:
        for i in range(2,N):
            if is_ok(i+1,a):
                dp[i] = dp[i-1] + dp[i-2]
                dp[i] %= MOD

    print(dp[N-1] % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()
word = input()

flag = True
if len(word)%2 == 1:
    flag = False
tab = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
i = 0
leng = len(word)
while flag and (i<leng):
    if word.count(tab[i])%2 == 1:
        flag = False
        break
    i += 1
if flag:print("Yes")
else: print("No")


### FIXED CODE ###

word = input()

flag = True
if len(word)%2 == 1:
    flag = False

wordset = set(word)
leng = len(wordset)
for s in wordset:
    if word.count(s)%2 == 1:
        flag = False
        break
if flag:print("Yes")
else: print("No")
import sys
from collections import defaultdict


def dfs(tree, p, cnt, visited):
    visited[p] = True
    cnt_here = cnt[p]
    for c in tree[p]:
        if visited[c]:
            continue
        cnt[c] += cnt_here
        dfs(tree, c, cnt, visited)
    return 0


def main():
    input = sys.stdin.buffer.readline
    n, q = map(int, input().split())
    tree = defaultdict(list)
    for _ in range(n - 1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)

    cnt = [0] * (n + 1)

    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p] += x
    visited = [False] * (n + 1)
    dfs(tree, 1, cnt, visited)
    print(*cnt[1:])


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import defaultdict


def dfs(tree, p, cnt, visited):
    visited[p] = True
    cnt_here = cnt[p]
    for c in tree.get(p):
        if visited[c]:
            continue
        cnt[c] += cnt_here
        dfs(tree, c, cnt, visited)


def main():
    input = sys.stdin.buffer.readline
    sys.setrecursionlimit(10 ** 9)
    n, q = map(int, input().split())
    tree = defaultdict(list)
    for _ in range(n - 1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    tree = dict(tree)
    cnt = [0] * (n + 1)

    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p] += x
    visited = [False] * (n + 1)
    dfs(tree, 1, cnt, visited)
    print(*cnt[1:])


if __name__ == "__main__":
    main()
N, K = map(int, input().split())

def init_max(init_max_val):
    #set_val
    for i in range(N):
        seg_max[i+num_max-1]=init_max_val[i]    
    #built
    for i in range(num_max-2,-1,-1) :
        seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2]) 
    
def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])
    
def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res

#####単位元######
ide_ele_max = -1

#num_max:n以上の最小の2のべき乗
num_max =2**(N-1).bit_length()
seg_max=[ide_ele_max]*2*num_max

a = [0]*N
init_max(a)

for _ in range(N):
    a = int(input())-1
    x = query_max(max(0, a-K), min(N, a+K+1))
    update_max(a, x+1)

print(query_max(0, N))

### FIXED CODE ###

N, K = map(int, input().split())
 
lm = 300001
 
# N: 処理する区間の長さ
N0 = 2**(lm-1).bit_length()
INF = 0
data = [INF]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])
# 区間[l, r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
 
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s
 
for _ in range(N):
    a = int(input())
    x = query(max(0, a-K), min(lm, a+K+1))
    update(a, x+1)
 
print(query(0, lm))
N = int(input())
H = map(int, input().split())

i = N
while i > 0:
  if H[i-1] > H[i] + 1:
    print('No')
    break
  if H[i-1] == H[i] + 1:
    H[i-1] -= 1
  i -= 1
print('Yes')

### FIXED CODE ###

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

i = N - 1
while i > 0:
  if H[i-1] > H[i] + 1:
    print('No')
    break
  if H[i-1] == H[i] + 1:
    H[i-1] -= 1
  i -= 1
if i==0:
  print('Yes')
import heapq
from collections import Counter
n, k = map(int, input().split())

dset = [[] for i in range(n)]
for i in range(n):
    t, d = map(int, input().split())
    dset[t-1].append(d)

for dd in dset:
    if dd: dd.sort(reverse=True)
    else: dd.append(-float('inf'))

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

cur = 0
hq = []
# k種類の先頭を除いて格納
for i in range(k):
    cur+=dset[i][0]
    for d in dset[i][1:]: heapq.heappush(hq, -d)

# 残りの種類のすべてを格納
for dd in dset[k:]:
    for d in dd:
        heapq.heappush(hq, -d)

ans = cur + k*k
for i in range(k-1, -1, -1):
    v = dset[i][0] # 削除候補
    w = -heapq.heappop(hq)
    if v < w:
        cur += w - v
    else:
        heapq.heappush(hq, -w)
    ans = max(ans, cur + i*i)
print(ans)

### FIXED CODE ###

import heapq
from collections import Counter
inf = 10**10
n, k = map(int, input().split())

dset = [[] for i in range(n)]
for i in range(n):
    t, d = map(int, input().split())
    dset[t-1].append(d)

for dd in dset:
    if dd: dd.sort(reverse=True)
    else: dd.append(-inf)

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

cur = 0
hq = []
# k種類の先頭を除いて格納
for i in range(k):
    cur+=dset[i][0]
    for d in dset[i][1:]: heapq.heappush(hq, -d)

# 残りの種類のすべてを格納
for dd in dset[k:]:
    for d in dd:
        heapq.heappush(hq, -d)

ans = cur + k*k
for i in range(k-1, -1, -1):
    v = dset[i][0] # 削除候補
    if hq:
        w = -heapq.heappop(hq)
    else:
        break
    if v < w:
        cur += w - v
        # heapq.heappush(hq, -v)
    else:
        heapq.heappush(hq, -w)
    ans = max(ans, cur + i*i)
print(ans)
##### 解けた #####

A,B,C=list(map(int,input().split(" ")))

if (len(A)==5 and len(B)==7 and len(C)==5) or (len(A)==7 and len(B)==5 and len(C)==5) or (len(A)==5 and len(B)==5 and len(C)==7):
    print("YES")
else:
    print("NO")

### FIXED CODE ###

##### 解けた #####

A,B,C=list(map(int,input().split(" ")))

if (A==5 and B==7 and C==5) or (A==7 and B==5 and C==5) or (A==5 and B==5 and C==7):
    print("YES")
else:
    print("NO")
import sys
import math
from array import array

M = 1000000
B = int(math.sqrt(M)+1)//6+1
N = M//6
N1 = N+1 if M % 6 == 5 else N
N2 = N+1 if M % 6 >= 1 else N
l = array('I',[1]) * N1
m = array('I',[1]) * N2
i = 5
ini = 4
for p in range(B):
    if l[p] == 1:
        l[p+i::i] = [0] * len(l[p+i::i])
        m[ini-1::i] = [0] * len(m[ini-1::i])
    if m[p] == 1:
        m[p+i+2::i+2] = [0] * len(m[p+i+2::i+2])
        l[ini+1::i+2] = [0] * len(l[ini+1::i+2])
    i += 6
    ini += 5
 
for i in sys.stdin:
    n = int(i)
    r =  n-1 if n < 3 else sum(l[0:(n+1)//6])+sum(m[0:(n-1)//6])+2
    print(r)

### FIXED CODE ###

import sys
from array import array

N = 1000000
primes = array('I',[1]) * (N//2)
primes[0] = 0

for i in range(3,int(N**0.5),2):
    if primes[i//2]:
        primes[(i*i)//2::i] = array('I',[0]) * len(primes[(i*i)//2::i])

for i in sys.stdin:
    n = int(i)
    if n < 4:
        print(n-1)
    else:
        print(sum(primes[:(n+1)//2])+1)
a = input().split()
elif a[0] < a[1]:
    print('a < b')
elif a[0] > a[1]:
    print('a > b')
elif a[0] == a[1]:
    print('a == b')



### FIXED CODE ###

a = input().split()
if -1000 > int(a[0]):
    print('')
elif 1000 < int(a[0]):
    print('')    
elif -1000 > int(a[1]):
    print('')
elif 1000 < int(a[1]):
    print('')    
elif int(a[0]) < int(a[1]):
    print('a < b')
elif int(a[0]) > int(a[1]):
    print('a > b')
elif int(a[0]) == int(a[1]):
    print('a == b')
S=input()
result1=0
result2=0
if S[0]=='1':
    for i in range(len(S)):
        if i%2==0:
            if S[i]=='0':
                result1+=1
            if S[i]=='1':
                result2+=1
        else:
            if S[i]=='1':
                result1+=1
            if S[i]=='0':
                result2+=1
    print(min(result1,result2))
else:
     for i in range(len(S)):
        if i%2==0:
            if S[i]=='0':
                result1+=1
            if S[i]=='1':
                result2+=1
        else:
            if S[i]=='1':
                result1+=1
            if S[i]=='0':
                result2+=1
    print(min(result1,result2))

### FIXED CODE ###

S=input()
result1=0
result2=0
if S[0]=='1':
    for i in range(len(S)):
        if i%2==0:
            if S[i]=='0':
                result1+=1
            if S[i]=='1':
                result2+=1
        else:
            if S[i]=='1':
                result1+=1
            if S[i]=='0':
                result2+=1
    print(min(result1,result2))
else:
    for i in range(len(S)):
        if i%2==0:
            if S[i]=='0':
                result1+=1
            if S[i]=='1':
                result2+=1
        else:
            if S[i]=='1':
                result1+=1
            if S[i]=='0':
                result2+=1
    print(min(result1,result2))
S = input()

if S == ABC:
    print("ARC")
else:
    print("ABC")

### FIXED CODE ###

S = input()

if S == "ABC":
    print("ARC")
else:
    print("ABC")
import bisect

n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(m)]  # 市iの順番を保つ
py_list = [[] for _ in range(m)]  # 市iの(属する県, 誕生年)

for p, y in data:
    py_list[p-1].append(y)

for i in range(n):
    py_list[i].sort()

for p, y in data:
    pos = bisect.bisect_left(py_list[p-1], y) + 1
    print("%06d%06d" % (p, pos))

### FIXED CODE ###

import bisect

n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(m)]  # 市iの順番を保つ
py_list = [[] for _ in range(n)]  # 市iの(属する県, 誕生年)

for p, y in data:
    py_list[p-1].append(y)

for i in range(n):
    py_list[i].sort()

for p, y in data:
    pos = bisect.bisect_left(py_list[p-1], y) + 1
    print("%06d%06d" % (p, pos))
#! /usr/bin/env python
# -*- coding: utf-8 -*-

def rec(y, x, used, TILE):
    if (not(0<=x<W)) or (not(0<=y<H)) or (TILE[y][x]==0) or (used[y][x]==1):
        return 0
    else:
        used[y][x] = 1
        rec(y-1, x-1, used, TILE)
        rec(y-1, x, used, TILE)
        rec(y-1, x+1, used, TILE)
        rec(y, x-1, used, TILE)
        rec(y, x, used, TILE)
        rec(y, x+1, used, TILE)
        rec(y+1, x-1, used, TILE)
        rec(y+1, x, used, TILE)
        rec(y+1, x+1, used, TILE)
    return 1

(W, H) = map(int, raw_input().split())
while W!=0:
    used = [[0]*W for i in range(H)]
    TILE = []
    s = []
    for i in range(H):
        TILE.append(map(int, raw_input().split()))

    Sum = 0
    for i in range(H):
        for j in range(W):
            Sum += rec(i, j, used, TILE)
    print Sum
    #print used.count(1)

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

### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-

def rec(y, x, used, TILE):
    if (not(0<=x<W)) or (not(0<=y<H)) or (TILE[y][x]==0) or (used[y][x]==1):
        return 0
    else:
        used[y][x] = 1
        rec(y-1, x-1, used, TILE)
        rec(y-1, x, used, TILE)
        rec(y-1, x+1, used, TILE)
        rec(y, x-1, used, TILE)
        rec(y, x, used, TILE)
        rec(y, x+1, used, TILE)
        rec(y+1, x-1, used, TILE)
        rec(y+1, x, used, TILE)
        rec(y+1, x+1, used, TILE)
    return 1

(W, H) = map(int, raw_input().split())
while W!=0 :
    used = [[0]*W for i in range(H)]
    TILE = []
    stack = []
    for i in range(H):
        TILE.append(map(int, raw_input().split()))
    Sum = 0
    for i in range(H):
        for j in range(W):
            if used[i][j] == 0 and TILE[i][j] == 1:
                Sum += 1
                stack.append([i, j])
                while len(stack)>0:
                    cur = stack[len(stack)-1]
                    stack.pop()
                    for y in [-1, 0, 1]:
                        for x in [-1, 0, 1]:
                            if 0<=cur[0]+y<H and 0<=cur[1]+x<W and TILE[cur[0]+y][cur[1]+x]==1 \
                                    and used[cur[0]+y][cur[1]+x]==0:
                                stack.append([cur[0]+y, cur[1]+x])
                                used[cur[0]+y][cur[1]+x] = 1

    """for i in range(H):
        for j in range(W):
            if used[i][j] == 0 and TILE[i][j] == 1:
                Sum += rec(i, j, used, TILE)
    print Sum"""
    print Sum
    #print used.count(1)

    (W, H) = map(int, raw_input().split())
n = input().split()
N = int(n[0])
A = int(n[1])
B = int(n[2])

if A > B or A == B:
    a = A
    b = B
elif B < A:
    a = B
    b = A

if a != b:
    if a+b < N:
        print(str(b) + ' ' + str(0))
    elif a+b > N:
        print(str(b) + ' ' + str(a - (N-b)))
elif a < N//2:
    print(str(a) + ' ' + str(0))
elif a > N//2:
    print(str(a) + ' ' + str(a-(N-b)))


### FIXED CODE ###

n = input().split()
N = int(n[0])
A = int(n[1])
B = int(n[2])

if A > B:
    a = A
    b = B
elif A < B:
    a = B
    b = A
elif A == B:
    a = A
    b = B

if a != b:
    if a+b <= N:
        print(str(b) + ' ' + str(0))
    elif a+b > N:
        print(str(b) + ' ' + str(a - (N-b)))
elif a+b <= N:
    print(str(a) + ' ' + str(0))
elif a+b > N:
    print(str(a) + ' ' + str(a-(N-b)))
import numpy as np
T = np.array([int(input()) for i in range(5)])

T_0 = T[np.mod(T, 10) == 0]
T_o = T[np.mod(T, 10) != 0]
T_c = T_o + 10 - np.mod(T_o, 10)
T_s = np.sort(np.mod(T_o, 10))
print(T_0,T_o,T_c,T_s)
if T_0 != np.array([0,0,0,0,0]):
    A = np.sum(T_c) - 10 + np.sum(T_0) + T_s[0]
    print(A)
else:
    A = np.sum(T_0)
    print(A)

### FIXED CODE ###

import numpy as np
T = np.array([int(input()) for i in range(5)])

T_0 = T[np.mod(T, 10) == 0]
T_o = T[np.mod(T, 10) != 0]

T_c = T_o + 10 - np.mod(T_o, 10)
T_s = np.sort(np.mod(T_o, 10))
if T_0.size == 5:
    print(np.sum(T_0))
else:
    print(np.sum(T_c) - 10 + np.sum(T_0) + T_s[0])