Harryxun/stf_run huggingface dataset:
import sys,math
sys.setrecursionlimit(10**5)

n,k=map(int,input().split())
m=10**9+7
to=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(lambda x:int(x)-1, input().split())
  to[a].append(b)
  to[b].append(a)


def nPk(_n,_k):
  a=math.factorial(_n)
  b=math.factorial(_n-_k)
  return (a//b)%m


def dfs(_v, p=-1):
  global ans
  for u in to[_v]:
    if u==p: continue
    dfs(u, _v)
  p=len(to[_v])
  ans*=nPk(k,p+1) if _v==0 else nPk(k-2,p-1)
  ans%=m
    
    
ans=1
chk=[False]*n
dfs(0)
  
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

n,k=map(int,input().split())
m=10**9+7
to=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(lambda x:int(x)-1, input().split())
  to[a].append(b)
  to[b].append(a)
frac=[1]*(10**5+1)
for i in range(1,10**5+1):
  frac[i]=frac[i-1]*i
  frac[i]%=m


def nPk(_n,_k):
  if _n<0 or _k<0 or _n-_k<0: return 0;
  a=frac[_n]
  b=frac[_n-_k]
  return (a*pow(b,m-2,m))%m


def dfs(_v, _u=-1):
  global ans
  for u in to[_v]:
    if u==_u: continue
    dfs(u, _v)
  p=len(to[_v])
  ans*=nPk(k,p+1) if _v==0 else nPk(k-2,p-1)
  ans%=m
    
    
ans=1
chk=[False]*n
dfs(0)
  
print(ans)
INF = float('inf')

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

memo = [-1] * n

def frog(i):
    if i < 0: return INF
    if memo[i] != -1: return memo[i]

    if i == 0:
        memo[i] = 0
        return 0

    memo[i] = min(abs(a[i] - a[i-1]) + frog(i-1),
                  abs(a[i] - a[i-2]) + frog(i-2))

    return memo[i]

print(frog(n-1))


### FIXED CODE ###

INF = float('inf')

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

memo = [-1] * n
memo[0] = 0

for i in range(1, n):
    memo[i] = min(abs(a[i] - a[i-1]) + memo[i-1],
                  abs(a[i] - a[i-2]) + memo[i-2] if i - 2 >= 0 else INF)

print(memo[n-1])
x,y=map(int,input().split())

if x==0 and y==0:
 brake
i = (x,y)
i=i,sort()

print(i)

### FIXED CODE ###

while True:
 x,y=sorted ([int(x) for x in input().split()])
 if (x,y)==(0,0):
  break
 print(x,y)
li = [int(input()) for i in range(5)]
for i in range(1,10):
    for j in range(5):
        if li[j] % 10 == i:
            a = li[j]
            del li[j]
            break
    else:
        continue
    break

for i in range(4):
    if li[i] % 10 != 0:
        li[i] = (li[i] // 10 + 1) * 10
print(sum(li) + a)

### FIXED CODE ###

li = [int(input()) for i in range(5)]
flag = True
for i in range(5):
    if li[i] % 10 == 0:
        flag = True
    else:
        flag = False
        break

if flag:
    print(sum(li))
else: 
    for i in range(1,10):
        for j in range(5):
            if li[j] % 10 == i:
                a = li[j]
                del li[j]
                break
        else:
            continue
        break

    for i in range(4):
        if li[i] % 10 != 0:
            li[i] = (li[i] // 10 + 1) * 10
    print(sum(li) + a)
N=int(input())

#h=max(H-|X-Cx|-|Y-Cy|,0)
#h=H-|X-Cx|-|Y-Cy|    h=0
#H=h+|X-Cx|+|Y-Cy|
S=[]
for i in range(N):
  x,y,h=map(int, input().split())
  S.append((x,y,h))

for cx in range(100+1):
  for cy in range(100+1):
    isans=True
    preH=0
    late=[]
    for i in range(N):
      x,y,h=S[i]
      if h==0:
        late.append((x,y,z))
      else:
        H=h+abs(x-cx)+abs(y-cy)
        #print(H)
        if preH==0:
          preH=H
        elif preH!=H:
          isans=False
        preH=H
    for i in range(len(late)):
      x,y,h=late[i]
      if preH!=0 and preH>abs(x-cx)+abs(y-cy):
          isans=False
    if isans:
      print(cx, cy, H)



### FIXED CODE ###

N=int(input())

#h=max(H-|X-Cx|-|Y-Cy|,0)
#h=H-|X-Cx|-|Y-Cy|    h=0
#H=h+|X-Cx|+|Y-Cy|
S=[]
for i in range(N):
  x,y,h=map(int, input().split())
  S.append((x,y,h))

for cx in range(100+1):
  for cy in range(100+1):
    isans=True
    preH=0
    late=[]
    for i in range(N):
      x,y,h=S[i]
      if h==0:
        late.append((x,y,h))
      else:
        H=h+abs(x-cx)+abs(y-cy)
        #print(H)
        if preH==0:
          preH=H
        elif preH!=H:
          isans=False
        preH=H
    for i in range(len(late)):
      x,y,h=late[i]
      if preH!=0 and preH>abs(x-cx)+abs(y-cy):
          isans=False
    if isans:
      print(cx, cy, H)
S = input()
count = 0
for s in S:
    if s == o:
        count += 1
print(700 + count*100)

### FIXED CODE ###

S = input()
count = 0
for s in S:
    if s == 'o':
        count += 1
print(700 + count*100)
n = list(map( int, sinput()))
 
h = 3
for i in range(h):
  if( n[i] == 1):
    n[i] = 9
    n[i] = str(n[i])   
  else:
    n[i] = 1
    n[i] = str(n[i])
    
a = "".join(n)
 
print(a)

### FIXED CODE ###

n = list(map( int, input()))
 
h = 3
for i in range(h):
  if( n[i] == 1):
    n[i] = 9
    n[i] = str(n[i])   
  else:
    n[i] = 1
    n[i] = str(n[i])
    
a = "".join(n)
 
print(a)
import math


def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
  

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

gcd = gcd(a, b)

res = set([1])
while gcd % 2 == 0: 
        res.add(2)
        gcd = gcd // 2

for i in range(3,int(math.sqrt(gcd))+1,2): 
    while gcd % i == 0: 
        res.add(i)
        gcd = gcd // i 
            
if gcd > 2: 
    res.add(gcd)

print(len(res))

### FIXED CODE ###

from math import ceil

n = int(input())

if n % 2:
    print(ceil(n/2)/n)
else:
    print((n//2)/n)
Q=int(input())
score=[map(int,input().split()) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))
    if score[i][0]*score[i][1]==max_num:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    elif score[i][0]==score[i][1]:
        print(2*max_num-2)
    else:
        print(2*max_num-2)


### FIXED CODE ###

Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))

    if score[i][0]==score[i][1]:
        print(2*max_num-2)
    elif score[i][0]*score[i][1]==max_num**2:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    else:
        print(2*max_num-2)
code = str(input())
if code = 'A':
	print('T')
elif code = 'T':
    print('A')
elif code = 'G':
    print('C')
elif code = 'C':
    print('G')

### FIXED CODE ###

code = input()
if code == 'A':
	print('T')
elif code == 'T':
    print('A')
elif code == 'G':
    print('C')
elif code == 'C':
    print('G')
count = 1

while True:
       x = int(input())
       if x != 0:
           print("Case {0} : {1}".format(count, x)
           count += 1
       else:
           break

### FIXED CODE ###

count = 1

while True:
       x = int(input())
       if x != 0:
           print("Case {0}: {1}".format(count, x))
           count += 1
       else:
           break
n, m, k = map(int, input().split())
ab = [[] for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab[a].append(b)
  ab[b].append(a)

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

ans = [0 for i in range(n)]

def dfs(s):
  vis[s] = True
  ary.append(s)
  for i in ab[s]:
    if vis[i] == False:
      dfs(i)

for i in range(n):
  vis = [False for i in range(n)]
  vis[i] = True
  x = ab[i]
  for j in x:
    vis[j] = True
  c = 0
  for j in x:
    ary = []
    dfs(j)
    ary.pop(0)
    blo = set(block[i])
    cnt = set(ary) - blo
    c += len(cnt)
  ans[i] = c
print (*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

n, m, k = map(int, input().split())
ab = [[] for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab[a].append(b)
  ab[b].append(a)

block = [set() for i in range(n)]
for i in range(k):
  c, d = map(int, input().split())
  c -= 1
  d -= 1
  block[c].add(d)
  block[d].add(c)

ans = [0 for i in range(n)]

def dfs(s):
  if vis[s] == False:
    vis[s] = True
    r[cnt].add(s)
    for i in ab[s]:
      dfs(i)

vis = [False for i in range(n)]
r = []
cnt = 0
for i in range(n):
  if vis[i] == False:
    r.append(set())
    dfs(i)
    cnt += 1

ans = [0 for i in range(n)]
for i in r:
  l = len(i)
  for j in i:
    ans[j] = l - len(ab[j]) - len(i&block[j]) - 1

print (*ans)
sunuke=[]
for i in range(20):
    for j in range(2,11):
        sunuke.append(j*10**i+-1)

for i in range(int(input())):
    print(sunuke[i])

### FIXED CODE ###

def f(n):
    s=str(n)
    return sum([int(s[i]) for i in range(len(s))])

sunuke=[]
for i in range(16):
    for j in range(1,500):
        sunuke.append(j*(10**i)-1)

sunuke=list(set(sunuke))
sunuke.sort()
sunuke.pop(0)
L=len(sunuke)

tmp1,tmp2=sunuke[L-1],f(sunuke[L-1])
ans=[sunuke[L-1]]
for i in range(len(sunuke)-2,-1,-1):
    x=sunuke[i]
    if x*tmp2<=tmp1*f(x):
        ans.append(x)
        tmp1,tmp2=x,f(x)

ans.sort()

    

for i in range(int(input())):
    print(ans[i])
import numpy as np
n,m = list(map(int, input().split()))
tmp_a = [list(input()) for _ in range(n)]
tmp_b = [list(input()) for _ in range(m)]

a = np.array(tmp_a)
b = np.array(tmp_b)

for a_i in range(n - m + 1):
  for a_j in range(n - m + 1):
      if((a[a_i:a_i + m, a_j:a_j + m] == b).all()):
        print("Yes")
        exit()
print("No")

### FIXED CODE ###

import numpy as np
n,m = list(map(int, input().split()))
tmp_a = [list(input()) for _ in range(n)]
tmp_b = [list(input()) for _ in range(m)]

a = np.array(tmp_a)
b = np.array(tmp_b)

for a_i in range(n - m + 1):
	for a_j in range(n - m + 1):
		if((a[a_i:a_i + m, a_j:a_j + m] == b).all()):
			print("Yes")
			exit()
print("No")
n, k = map(int, input().split())
a = list(map(int, input().split()))
bitcount = []
m = k
while(m > 0):
    odd = sum(list(map(lambda x: x%2, a)))
    bitcount.append(odd)
    a = list(map(lambda x: x//2, a))
    m = m//2
f = []
for keta in range(len(bitcount)+1):
    ans = 0
    for i in range(keta):
        ans += max(bitcount[i], n - bitcount[i]) * 2 ** i
    for i in range(keta, len(bitcount)):
        if k & (2 ** i) == 0
            ans += bitcount[i] * 2 ** i
        else:
            ans += (n - bitcount[i]) * 2 ** i
    f.append(ans)
print(max(f))


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
bitcount = []
k += 1
m = k
f = [sum(a)]
while(m > 0 or max(a) > 0):
    odd = sum(list(map(lambda x: x%2, a)))
    bitcount.append(odd)
    a = list(map(lambda x: x//2, a))
    m = m//2
for keta in range(len(bitcount)):
    if k & (2 ** keta) != 0:
        ans = 0
        for i in range(keta):
            ans += max(bitcount[i], n - bitcount[i]) * 2 ** i
        for i in range(keta + 1, len(bitcount)):
            if k & (2 ** i) == 0:
                ans += bitcount[i] * 2 ** i
            else:
                ans += (n - bitcount[i]) * 2 ** i
        ans += bitcount[keta] * 2 ** keta
        f.append(ans)
print(max(f))
n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
for i in range(n):
	if x[i][1]>max(x[i][0] for i in range(n))-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(a)+1
	print(q+len(c))

### FIXED CODE ###

n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
M = max(x[i][0] for i in range(n))

for i in range(n):
	if x[i][1]>M-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//M+1
	print(q+len(c))
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

cnt = [0]*(2*10**5)#何回出たか
cnt2 = [0]*(2*10**5)#何回目に出てきたか
t = []
nxt = 0
loop = 0

for i in range(10**5):
    cnt[nxt] += 1
    if cnt[nxt] >= 2:
        # print("i: " + str(i))
        # print("nxt: " + str(nxt))
        loop = i - cnt2[nxt]
        modC = cnt2[nxt]
        break
    cnt2[nxt] = i
    t.append(nxt)
    nxt = a[nxt]

modK = (k-modC)%loop
# print("-------")
# print(t)
# print("modC: " + str(modC))
# print("modK: " + str(modK))
# print("loop: " + str(loop))
# print(modK)
# print(loop)
# print("-------")

if k < modC:
    print(t[k] + 1)
else:
    print(t[modC + modK] + 1)

"""
発想はあってる
テストケース公開されたら試してみる！
"""

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

cnt = [0]*(2*10**5)#何回出たか
cnt2 = [0]*(2*10**5)#何回目に出てきたか
t = []
nxt = 0
loop = 0

for i in range(2*10**5):
    cnt[nxt] += 1
    if cnt[nxt] >= 2:
        # print("i: " + str(i))
        # print("nxt: " + str(nxt))
        loop = i - cnt2[nxt]
        modC = cnt2[nxt]
        break
    cnt2[nxt] = i
    t.append(nxt)
    nxt = a[nxt]

modK = (k-modC)%loop
# print("-------")
# print(t)
# print("modC: " + str(modC))
# print("modK: " + str(modK))
# print("loop: " + str(loop))
# print(modK)
# print(loop)
# print("-------")

if k < modC:
    print(t[k] + 1)
else:
    print(t[modC + modK] + 1)

"""
発想はあってる
テストケース公開されたら試してみる！
"""
from numba import njit
import numpy as np


def main(N, P):
    lista = [1, -1, N, -N]
    d = np.zeros((N, N), dtype=np.int32)
    d = d.ravel()
    sit = np.ones_like(d)
    que = []
    count = 0
    for i in range(N*N):
        d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N)
    for player in P:
        sit[player-1] = 0
        count += d[player-1]
        que.append(player)
        for p in que:
            for i in lista:
                if p+i < 1 or p + i > N*N:
                    continue
                if d[p-1]+sit[p-1] < d[p+i-1]:
                    d[p+i-1] = d[p-1]+sit[p-1]
                    que.append(player+i)
    print(count)


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8,i8[:])')(main)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import main
    N = int(input())
    P = list(map(int, input().split()))
    main(N, P)


### FIXED CODE ###

from numba import njit
import numpy as np

@njit
def main(N, P):
    lista = [1, -1, N, -N]
    d = np.zeros((N, N), dtype=np.int32)
    d = d.ravel()
    sit = np.ones_like(d)
    stack = np.empty_like(d)
    count = 0
    for i in range(N*N):
        d[i] = min(i % N, (N-1-i) % N, i//N, N-1-i//N)
    for player in P:
        sit[player-1] = 0
        count += d[player-1]
        stack[0] = player
        num = 0
        while num >= 0:
            p = stack[num]
            num -= 1
            a = d[p-1]+sit[p-1]
            for i in lista:
                if p+i < 1 or p + i > N*N:
                    continue
                if d[p+i-1] > a:
                    d[p+i-1] = a
                    num += 1
                    stack[num] = p+i
    print(count)

N = int(input())
P = np.array(input().split(), np.int32)

main(N, P)
from fractions import Fraction
N = int(input())
l = []

d = {}
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

for i in range(N):
    temp = set([])
    for j in range(i + 1, N):
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        if dx == 0:
            frac = "x=0"
        elif dy == 0:
            frac = "y=0"
        else:
            frac = Fraction(dy, dx)
            frac = str(frac)

        temp.add(frac)
    
    for frac in temp:
        if frac not in d:
            d[frac] = 1
        else:
            d[frac] += 1

print(N - max(d.values()))

### FIXED CODE ###

N = int(input())

d = {}
x = [0] * N
y = [0] * N
from collections import defaultdict
for i in range(N):
    x[i], y[i] = map(int, input().split())

d = defaultdict(int)
for i in range(N):
    for j in range(N):
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        if i == j:
            continue
        d[(dx, dy)] += 1
        
if N == 1:
    print(1)
else:
    print(N - max(d.values()))
trash = input()
input_1 = input().split(' ')
if max(input_1) < (sum(input_1) - max(input_1)):
	print('Yes')
else:
	print('No')

### FIXED CODE ###

trash = input()
input_1 = list(map(int,input().split(' ')))
if max(input_1) < (sum(input_1) - max(input_1)):
	print('Yes')
else:
	print('No')
#C - Energy Drink Collector
n,m = map(int,input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
abSorted = sorted(ab)
sumB = 0
sumMoney = 0
while sumB + abSorted[i][1] < m:
    sumB += abSorted[i][1]
    sumMoney += abSorted[i][0] * abSorted[i][1]
sumMoney += sbSorted[i][0] * (m - sumB)
print(sumMoney)


### FIXED CODE ###

#C - Energy Drink Collector
n,m = map(int,input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
abSorted = sorted(ab)
sumB = 0
sumMoney = 0
i = 0
while sumB + abSorted[i][1] < m:
    sumB += abSorted[i][1]
    sumMoney += abSorted[i][0] * abSorted[i][1]
    i += 1
sumMoney += abSorted[i][0] * (m - sumB)
print(sumMoney)
import collections
import numpy as np
import sys
import copy

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
    A[i]-=1
B=[0]
visited=[0]*N
visited[0]=1
Flag=True
for i in range(0,N*2):
    next=A[B[i]]
    if visited[next]==0:
        B.append(next)
        visited[next]=1
    else:
        C=B[B.index(next):]
        num=B.index(next)
        break
#print(C)
if K>len(C):
    Ans=(K-num)%len(C)
    print(C[Ans]+1)
else:
    print(B[K])

### FIXED CODE ###

import collections
import numpy as np
import sys
import copy

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
    A[i]-=1
B=[0]
visited=[0]*N
visited[0]=1
Flag=True
for i in range(0,N*2):
    next=A[B[i]]
    if visited[next]==0:
        B.append(next)
        visited[next]=1
    else:
        C=B[B.index(next):]
        num=B.index(next)
        break
#print(C)
if K>num:
    Ans=(K-num)%len(C)
    print(C[Ans]+1)
else:
    print(B[K]+1)
t = input()
before_is_zero = True
keeped_ones = 0
n0 = 0
ones = [0] * int(1e5) # (number of zeros before 1, is_odd)
ones_index = 0
for i, x in enumerate(t):
    if x == '0':
        n0 += 1
        before_is_zero = True
    elif x == '1':
        if before_is_zero:
            ones[ones_index] = (n0, (i+1)%2)
            ones_index += 1
            before_is_zero = False
        else:
            keeped_ones += 1
            ones_index -= 1
            before_is_zero = True
if before_is_zero:
    if len(ones) > 0:
        ones = ones[:-1]

ans = keeped_ones * n0
for i in range(ones_index):
    n0_before, is_odd = ones[i]
    ans += (n0_before + is_odd)//2 + (n0 - n0_before)
ans += (keeped_ones + (ones_index+1)//2) * (keeped_ones + ones_index//2 + 1)
print(ans)

### FIXED CODE ###

t = input()
before_is_zero = True
keeped_ones = 0
n0 = 0
ones = [0] * int(1e5+1) # (number of zeros before 1, is_odd)
ones_index = 0
for i, x in enumerate(t):
    if x == '0':
        n0 += 1
        before_is_zero = True
    elif x == '1':
        if before_is_zero:
            ones[ones_index] = (n0, (i+1)%2)
            ones_index += 1
            before_is_zero = False
        else:
            keeped_ones += 1
            ones_index -= 1
            before_is_zero = True

if before_is_zero:
    if len(ones) > 0:
        ones = ones[:-1]

ans = keeped_ones * n0
for i in range(ones_index):
    n0_before, is_odd = ones[i]
    ans += (n0_before + is_odd)//2 + (n0 - n0_before)
ans += (keeped_ones + (ones_index+1)//2) * (keeped_ones + ones_index//2 + 1)
print(ans)
n=input()
a=input()
c=str()
for i in range(0,len(a))
	c+=n[i]+a[i]
print(c if len(n)==len(a) else c+n[len(n)-1])

### FIXED CODE ###

n=input()
a=input()
c=str()
for i in range(0,len(a)):
    c+=n[i]+a[i]
print(c if len(n)==len(a) else c+n[len(n)-1])
S = input()
T = input()
ans = 0

for i in range(len(s)):
  if (s[i] != t[i]):
    ans = ans + 1

print(ans)


### FIXED CODE ###

s = input()
t = input()
ans = 0
 
for i in range(len(s)):
  if (s[i] != t[i]):
    ans = ans + 1
 
print(ans)
n,k=map(int, input().split())
String=input()
String=list(String)
String[k]=String[k].upper()
String="".join(String)
print(String)

### FIXED CODE ###

n,k=map(int, input().split())
String=input()
String=list(String)
String[k-1]=String[k-1].lower()
String="".join(String)
print(String)
n,m = list(map(int,input().split()))
b = [0 for i in range(m)]
for i in range(n):
  ka = list(map(int,input().split()))
  k = ka[0]
  a = ka[1:]
  for j in range(k):
    b[a[j]-1] += 1
c = 0
for i in range(n):
  if b[i] == 10:
    c += 1
print(c)

### FIXED CODE ###

n,m = list(map(int,input().split()))
b = [0 for i in range(m)]
for i in range(n):
  ka = list(map(int,input().split()))
  k = ka[0]
  a = ka[1:]
  for j in range(k):
    b[a[j]-1] += 1
c = 0
for i in range(m):
  if b[i] == n:
    c += 1
print(c)
a, b = map(int, input().split())
l = []
c = a +b
d = a -b
e = a *b
l.append =c
l.append =d
l.append =e
print(max(l[c, d, e]))

### FIXED CODE ###

a, b = map(int, input().split())
l = []
c = a +b
d = a -b
e = a *b
l.append(c)
l.append(d)
l.append(e)
print(max(l))
line=input()
line.split(" ")
 
a=int(line[0])
b=int(line[1])
c=int(line[2])
 
if a+b==c:
 print("Yes")
elif b+c==a:
 print("Yes")
elif c+a==b:
 print("Yes")
else:
 print("No")

### FIXED CODE ###

line=input()
line=line.split(" ")
 
a=int(line[0])
b=int(line[1])
c=int(line[2])
 
if a+b==c:
 print("Yes")
elif b+c==a:
 print("Yes")
elif c+a==b:
 print("Yes")
else:
 print("No")
A,B,C,D = map(int,imput().split())
x = C // B
y = A // D
if x >= y:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

A,B,C,D = map(int,input().split())
x = C // B
if C % B == 0:
    x = x-1
y = A // D
if A % D == 0:
    y = y-1
if x > y:
  print("No")
else:
  print("Yes")
a,b,c = map(int, input().split)
if a < c < b:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

import sys
a, b, c = map(int, input().split())
 
if a > b:
  for i in range(b, a):
    if i == c:
      print('Yes')
      sys.exit(0)
else:
  for i in range(a, b):
    if i == c:
      print('Yes')
      sys.exit(0)

print('No')
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)   

n=int(input())
p=1
for i in range(n):
  m=int(input())
  p=p*m/gcd(p,m)
print(p)

### FIXED CODE ###

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

n=int(input())
p=1
for i in range(n):
  m=int(input())
  p=p*m//gcd(p,m)
print(int(p))
N = int(input())
foods = [int(i) for i in input().split()]
eff = sum([int(i) for i in input().split()])
plus = [int(i) for i in input().split()]
if foods[-1]-2 in plus:
  print(eff + plus[foods[-1]-2])
else:
  print(eff)

### FIXED CODE ###

N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i == 0:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] <= B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                # A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))
inf = float("inf")
N, M = map(int, input().split())
A = map(int, input().split())
C = [2, 5, 5, 4, 5, 6, 3, 7, 6]
costs = {m: C[m - 1] for m in A}
dp = [0]
for i in range(1, N + 1):
    dp.append(
        max([dp[i - c] if i - c >= 0 else -inf for c in costs.values()]) + 1)

digits = list(costs.keys())
digits = sorted(digits, reverse=True)
num = N
result = []
for _ in range(dp[N]):
    for digit in digits:
        if dp[num - costs[digit]] != -inf and dp[num - costs[digit]] == dp[num] - 1:
            result.append(str(digit))
            num -= costs[digit]
            break
print("".join(result))


### FIXED CODE ###

inf = float("inf")
N, M = map(int, input().split())
A = map(int, input().split())
C = [2, 5, 5, 4, 5, 6, 3, 7, 6]
costs = {m: C[m - 1] for m in A}
dp = [0]
for i in range(1, N + 1):
    dp.append(
        max([dp[i - c] if i - c >= 0 else -inf for c in costs.values()]) + 1)

digits = list(costs.keys())
digits = sorted(digits, reverse=True)
num = N
result = []
for _ in range(dp[N]):
    for digit in digits:
        if num >= costs[digit] and dp[num - costs[digit]] != -inf and dp[num - costs[digit]] == dp[num] - 1:
            result.append(str(digit))
            num -= costs[digit]
            break
print("".join(result))