Harryxun/stf_run huggingface dataset:
import bisect
n = int(input())
a = list(map(int,input().split()))
t = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v = map(int,input().split())
    t[u].append(v)
    t[v].append(u)

INF = float('inf')
dp = [INF]*(n+1)
ans = [1]*(n+1)
checked = [False]*(n+1)
checked[1] = True
changes = []

def search(v):
    ind = bisect.bisect_left(dp,a[v-1])
    changes.append([ind,dp[ind]])
    dp[ind] = a[v-1]
    ans[v] = bisect.bisect_left(dp,INF)
    
    for i in t[v]:
        if not checked[i]:
            checked[i] = True
            search(i)
    
    b,c = changes.pop()
    dp[b] = c
    
search(1)
print('\n'.join(map(str,ans[1:])))

### FIXED CODE ###

import bisect
import sys
sys.setrecursionlimit(10**7)

n = int(input())
a = [0]+list(map(int,input().split()))
t = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v = map(int,input().split())
    t[u].append(v)
    t[v].append(u)

m = 10**18
dp = [m]*(n+1)
ans = [1]*(n+1)
checked = [False]*(n+1)
checked[1] = True
changes = []

def search(x):
    ind = bisect.bisect_left(dp,a[x])
    changes.append((ind,dp[ind]))
    dp[ind] = a[x]
    ans[x] = bisect.bisect_left(dp,m)
    
    for i in t[x]:
        if not checked[i]:
            checked[i] = True
            search(i)
    
    b,c = changes.pop()
    dp[b] = c
    
search(1)
for i in ans[1:]:
    print(i)
import sys
while 1:
	n=int(input())
	if n==0:
		break
	s=list(int(input().split()))
	cont=0
	while 1:
		tmp=[]
		for i in range(n):
			tmp[i]=[s.count(s[i])]
		if s==temp:
			print(cont)
			break
		else:
			cont+=1
	for i in range(n):
		if i != n-1:
			sys.stdout('{0} '.format(s[i]))
		else:
			print(s[i])

### FIXED CODE ###

while 1:
	n=int(input())
	if n==0:
		break
	s=list(map(int,input().split()))
	cont=0
	while 1:
		tmp=[]
		for i in range(n):
			tmp.append(s.count(s[i]))
		if s==tmp:
			print(cont)
			break
		else:
			s=tmp
			cont+=1
	for i in range(n):
		if i != n-1:
			print(s[i],end=' ')
		else:
			print(s[i])
h, w, k = map(int, input().split())
l = []
ans = []
for i in range(h):
  lll = [0 for x in range(w)]
  ans.append(lll)
for i in range(h):
  ll = list(input())
  l.append(ll)
res = 0
for i in range(h):
  res2 = 0
  res += 1
  if not "#" in l[i]:
    if i == 0:
      fl = True
    else:
      ans[i] = ans [i-1]
      break
  for j in range(w):
    if l[i][j] == "#":
      res2 += 1
      if res2 >= 2:
        res += 1
      ans[i][j] = res     
    else:
      ans[i][j] = res
if fl:
  for i in range(h):
    for j in range(w):
      ans[i][j] -= 1/2
  ans[0] = ans[1]
  for i in range(h):
    for j in range(w):
      ans[i][j] = int(ans[i][j])
for i in range(h):
  print(' '.join(map(str, ans[i])))

### FIXED CODE ###

h, w, k = map(int, input().split())
l = []
ans = []
for i in range(h):
  lll = [0 for x in range(w)]
  ans.append(lll)
for i in range(h):
  ll = list(input())
  l.append(ll)
res = 0
fl = False
for i in range(h):
  res2 = 0
  if not "#" in l[i]:
    if i == 0:
      fl = True
      
    else:
      ans[i] = ans [i-1]
      
  else:
    res += 1
    for j in range(w):
      if l[i][j] == "#":
        res2 += 1
        if res2 >= 2:
          res += 1
        ans[i][j] = res     
      else:
        ans[i][j] = res
if fl:
  ffff = 1
  for i in range(h):
    if "#" in l[i]:
      ffff = i
      break
  for i in reversed(range(1, ffff+1)):
    ans[i-1] = ans[i]
for i in range(h):
  print(' '.join(map(str, ans[i])))
n,k = map(int,input().split())
h = list(map(int,input().split()))

sorted(h)

for i in range(k):
  h.pop()
  
print(sum(h))

### FIXED CODE ###

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

hh = sorted(h)

for i in range(k):
  if(len(hh) == 0):
    break
  hh.pop()
  
print(sum(hh))
# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low)

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

ans_high=0
for i in range(N):
    if X[i] == "1":
        ans_high+=mod_h[i]
ans_high%=high

ans_low=0
for i in range(N):
    if X[i] == "1":
        ans_low+=mod_l[i]
ans_low%=low
        
for i in range(N):
    if X[i]=="0":
        ans=ans_high
        #high_root
        """
        temp=X[:]
        temp[i]="1"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_h[j]
        """
        ans+=mod_h[i]
        ans%=high
    else:
        ans=ans_low
        """
        temp=X[:]
        temp[i]="0"
        for j in range(len(temp)):
            if temp[j] == "1":
                ans+=mod_l[j]
        """
        ans-=mod_l[i]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)
    
    

### FIXED CODE ###

# coding: utf-8
# Your code here!
N=int(input())
X=list(input())

ones=X.count("1")
high=ones+1
low=ones-1

mod_h=[1]
mod_l=[1]
for i in range(N-1):
    mod_h.append((mod_h[-1]*2)%high)
    mod_l.append((mod_l[-1]*2)%low if low!=0 else 0) 

mod_h=mod_h[::-1]
mod_l=mod_l[::-1]

ans_high=0
for i in range(N):
    if X[i] == "1":
        ans_high+=mod_h[i]
ans_high%=high

ans_low=0
for i in range(N):
    if X[i] == "1":
        ans_low+=mod_l[i]
ans_low%=low if low!=0 else 1
        
for i in range(N):
    if X[i]=="0":
        ans=ans_high
        ans+=mod_h[i]
        ans%=high
    else:
        if low==0:
            print(0)
            continue
        ans=ans_low
        ans-=mod_l[i]
        ans%=low
    
    count=1
    while ans!=0:
        ans=ans%(bin(ans).count("1"))
        count+=1
    
    print(count)
stairs = int(input())
stair_status = list(map(int,input().split(" ")))

count = []
for i in range(stairs-1):
    for j in range(stairs):
        if stair_status[i+j]<stair_status[i+j+1]:
            count.append(j)
            break
        else:
            if (i + j + 2)==stairs:
                count.append(j+1)
                break
    if (i + j + 2)==stairs:
        break
    
    if max(count)>=stairs-max(count):
        break
print(max(count))

### FIXED CODE ###

stairs = int(input())
stair_status = list(map(int,input().split(" ")))

move = 0
count = [0]
for i in range(stairs-1):
    if stair_status[i]>=stair_status[i+1]:
        move += 1
        count.append(move)
    else:
        count.append(move)
        move = 0  #reset
    
else:
    print(max(count))
n=int(input())
for i in range(len(n)):
  if n[i] == 1:print(9,end='')
  else:print(print(1,end=''))

### FIXED CODE ###

n=input()
for i in range(3):
  if int(n[i]) == 1:print(9,end='')
  else:print(1,end='')
import math

def overlap(p1, p2, d):
    return (p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 <= d

def intersection(o1,o2):
    a  = 2*(o2[0] - o1[0])
    b  = 2*(o2[1] - o1[1])
    c  = (o1[0] - o2[0])*(o1[0] + o2[0]) + (o1[1] - o2[1])*(o1[1] + o2[1])
    a2 = a**2 + b**2
    b2 = a*c + a*b*o1[1] - b**2*o1[0]
    c2 = b**2*(o1[0]**2 + o1[1]**2 - 1) + c**2 + 2*b*c*o1[1]
    x1 = (-b2 + math.sqrt(b2**2 - a2*c2))/a2
    x2 = (-b2 - math.sqrt(b2**2 - a2*c2))/a2
    if b < 10e-6:
        y1 = (o1[1] + o2[1])/2
        y2 = (o1[1] + o2[1])/2
    else:
        y1 = -(a*x1 + c)/b
        y2 = -(a*x2 + c)/b
    if b2**2 - a2*c2 < 10e-6:
        return [x1, y1], [x2, y2]
    else:
        return [x1, y1], [x2, y2]

while True:
    n = int(input())
    if n == 0:
        break
    p = []
    for i in range(n):
        p.append(list(map(float, input().split(","))))
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if not overlap(p[i], p[j], 4):
                continue
            elif overlap(p[i], p[j], 10e-6):
                continue
            p1, p2 = intersection(p[i], p[j])
            cnt1 = 0
            cnt2 = 0
            for k in range(n):
                if overlap(p1, p[k], 1):
                    cnt1 += 1
                if p2[0] != None and overlap(p2, p[k], 1):
                    cnt2 += 1
            ans = max([ans, cnt1, cnt2])
    print(ans)



### FIXED CODE ###

import math

def dist(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)

def intersection(o1,o2):
    if dist(o1,o2) > 2:
        p1, p2 =  [None, None], [None, None]
    elif dist(o1,o2) == 2:
        p1, p2 =  [(o1[0] + o2[0])/2, (o1[1] + o2[1])/2], [None, None]
    else:
        m = [(o1[0] + o2[0])/2, (o1[1] + o2[1])/2]
        v = [m[0] - o1[0], m[1] - o1[1]]
        v_abs = dist(v,[0,0])
        w = [v[1], -v[0]]
        w_abs = dist(w,[0,0])
        n = [w[0]/w_abs, w[1]/w_abs]
        l = math.sqrt(1 - v_abs**2)
        p1 = [m[0] + l*n[0], m[1] + l*n[1]]
        p2 = [m[0] - l*n[0], m[1] - l*n[1]]
    return p1, p2
err = 1.0e-6
while True:
    n = int(input())
    if n == 0:
        break
    p = []
    for i in range(n):
        p.append(list(map(float, input().split(","))))
    ans = 1
    for i in range(n - 1):
        for j in range(i + 1, n):
            p1, p2 = intersection(p[i], p[j])
            cnt1 = 0
            cnt2 = 0
            for k in range(n):
                if p1[0] and dist(p1, p[k]) <= 1 + err:
                    cnt1 += 1
                if p2[0] and dist(p2, p[k]) <= 1 + err:
                    cnt2 += 1
            ans = max([ans, cnt1, cnt2])
    print(ans)
n = int(input())
s = [int(input()) for i range(n)]
summ = sum(s)
ans = [0]*summ
for i in range(n):
  ans[i] -= s[i]
ans.sort(reverse = True)
for i in ans:
  if i % 10 != 0:
    print(i)
    break
else:
  print(0)

### FIXED CODE ###

N = int(input())
s = [int(input()) for i in range(N)]
s_shadow = [i for i in s if i % 10 != 0]
ans = sum(s)

if ans % 10 == 0:
    if len(s_shadow) == 0:
        ans = 0
    
    else:
        s_can = sorted([ans-i for i in s_shadow])
        ans = s_can[-1]
print(ans)
def main():
    N,M,K=map(int,input().split())

    G=[[] for i in range(N)]
    B = [[] for i in range(N)]

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

    C=[]
    D=[]
    for i in range(K):
        c,d=map(int,input().split())
        C.append(c-1)
        D.append(d-1)
    trace=[-1 for i in range(N)]
    Group=[]
    Group_tmp=[]
    def dfs(n):
        if trace[n]!=-1:
            return 0
        Group_tmp.append(n)
        trace[n]=0
        for dist in G[n]:
            dfs(dist)
        if len(G[n])==0:
            return 0

    for i in range(len(trace)):
        if trace[i]==-1:
            Group_tmp=[]
            dfs(i)
            Group.append(Group_tmp)

    res=[0 for i in range(N)]
    GroupMarker=[-1 for i in range(N)]

    for i in range(len(Group)):
        for j in range(len(Group[i])):
            person=Group[i][j]
            GroupMarker[person]=i
            r=len(Group[i])-len(G[person])-1
            res[person]=r
    for i in range(K):
        if D[i] in Group[GroupMarker[C[i]]]:
            res[D[i]]-=1
            res[C[i]]-=1

    res=list(map(str,res))
    print(" ".join(res))

if __name__=="__main__":
    main()





### FIXED CODE ###

def main():
    N,M,K=map(int,input().split())

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

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

    B=[[] for i in range(N)]
    for i in range(K):
        c,d=map(int,input().split())
        B[c-1].append(d-1)
        B[d-1].append(c-1)
    trace=[-1 for i in range(N)]
    Group=[]

    for i in range(N):
        stack=[]
        if trace[i]==-1:
            trace[i]=0
            stack.append(i)
        Group_tmp=[]
        while len(stack)>0:
            index=stack.pop()
            Group_tmp.append(index)
            for j in G[index]:
                if trace[j]==-1:
                    trace[j]=0
                    stack.append(j)
        if len(Group_tmp)!=0:
            Group.append(Group_tmp)
    res=[0 for i in range(N)]
    GroupMarker=[-1 for i in range(N)]

    for i in range(len(Group)):
        for j in range(len(Group[i])):
            person=Group[i][j]
            GroupMarker[person]=i
            r=len(Group[i])-len(G[person])-1
            res[person]=r

    for i in range(len(B)):
        for j in range(len(B[i])):
            if GroupMarker[i]==GroupMarker[B[i][j]]:
                res[i]-=1
    res=list(map(str,res))
    print(" ".join(res))

if __name__=="__main__":
    main()
from sys import stdin
#from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return [x for x in mi()]
def si(): return stdin.readline()
def dis(x, y, p, q):
    return sqrt((x-p)**2+(y-q)**2)
a=[]
s=0
n=ii()
fn=1
for i in range(1, n+1):
    fn*=i
fn//=2
for _ in range(n):
    x, y=mi()
    a.append([x, y])
for i in range(n-1):
    for j in range(i+1, n):
        s+=dis(a[i][0], a[i][1], a[j][0], a[j][1])
        #print(s)
print(2*s/n)

### FIXED CODE ###

from sys import stdin
#from collections import deque
from math import sqrt
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return [x for x in mi()]
def si(): return stdin.readline()
def dis(x, y, p, q):
    return sqrt((x-p)**2+(y-q)**2)
a=[]
s=0
n=ii()
fn=1
for i in range(1, n+1):
    fn*=i
fn//=2
for _ in range(n):
    x, y=mi()
    a.append([x, y])
for i in range(n-1):
    for j in range(i+1, n):
        s+=dis(a[i][0], a[i][1], a[j][0], a[j][1])
        #print(s)
print(2*s/n)
import sys
sys.setrecursionlimit(10**9)
N,M = map(int, input().split())
input = sys.stdin.readline()
LRD = [ [int(j) for j in input().split()] for _ in range(M)]

data = [-1] * (N+1)
rank = [0]  * (N+1)
diff_weight = [0] * (N+1)

def root(x):
    if data[x] == x:
        return x
    else:
        r = root(x)
        diff_weight[x] += diff_weight[ data[x] ]
        data[x] = r
        return r

def weight(x):
    _ = root(x)
    return diff_weight[x]


def diff(x,y):
    return weight(y) - weight(x)

def merge(x,y,w):
    w  += weight(x); w -= weight(y)
    x = root(x)
    y = root(y)
    if x == y: return False
    if rank[x] < rank[y]: x,y = y,x; w = -w
    if rank[x] == rank[y]: rank[x] += 1
    data[y] = x
    diff_weight[y] = w
    return True

def issame(x,y):
    return root(x) == root(y)

for i in range(M):
    L,R,D = LRD[i]
    if not issame(L,R):
        merge(L,R,D)
    else:
        if weight(L,R) != D:
            print("No")
            exit(0)
            
print("Yes")

    
    


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)
N,M = map(int, input().split())
input = sys.stdin.readline
LRD = [ [int(j) for j in input().split()] for _ in range(M)]

data = [x for x in range(N+1)]
rank = [0]  * (N+1)
diff_weight = [0] * (N+1)

def root(x):
    if data[x] == x:
        return x
    else:
        r = root( data[x] )
        diff_weight[x] += diff_weight[ data[x] ]
        data[x] = r
        return r

def weight(x):
    # _ = root(x)
    return diff_weight[x]


def diff(x,y):
    return weight(y) - weight(x)

def merge(x,y,w):
    w  += weight(x); w -= weight(y)
    x = root(x)
    y = root(y)
    if x == y: return False
    if rank[x] < rank[y]: x,y = y,x; w = -w
    if rank[x] == rank[y]: rank[x] += 1
    data[y] = x
    diff_weight[y] = w
    return True

def issame(x,y):
    return root(x) == root(y)

for i in range(M):
    L,R,D = LRD[i]
    # print(L,R,D)
    if not issame(L,R):
        _  = merge(L,R,D)
    else:
        if diff(L,R) != D:
            print("No")
            exit(0)
            
print("Yes")
a=[]
b=[]
nums=[]
ans="No"

for i in range(3):
    l=list(map(int,input().split()))
    a.append(l)

n=int(input())

for i in range(n):
    s=int(input())
    b.append(s)

for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i]==a[j][k]:
                a[j][k]=0
                num=10*(j+1)+k+1
                nums.append(num)

nums.sort()


if A[0][0]==A[0][1]==A[0][2]==0:
    ans="Yes"
if A[1][0]==A[1][1]==A[1][2]==0:
        ans="Yes"
if A[2][0]==A[2][1]==A[2][2]==0:
    ans="Yes"
if A[0][0]==A[1][0]==A[2][0]==0:
    ans="Yes"
if A[0][1]==A[1][1]==A[2][1]==0:
        ans="Yes"
if A[0][2]==A[1][2]==A[2][2]==0:
    ans="Yes"
        
if 11 in nums and 22 in nums and 33 in nums:
    ans="Yes"

if 13 in nums and 22 in nums and 31 in nums:
    ans="Yes"
    
print(ans)

### FIXED CODE ###

a=[]
b=[]
nums=[]
ans="No"

for i in range(3):
    l=list(map(int,input().split()))
    a.append(l)

n=int(input())

for i in range(n):
    s=int(input())
    b.append(s)

for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i]==a[j][k]:
                a[j][k]=0
                num=10*(j+1)+k+1
                nums.append(num)

nums.sort()


if a[0][0]==a[0][1]==a[0][2]==0:
    ans="Yes"
if a[1][0]==a[1][1]==a[1][2]==0:
        ans="Yes"
if a[2][0]==a[2][1]==a[2][2]==0:
    ans="Yes"
if a[0][0]==a[1][0]==a[2][0]==0:
    ans="Yes"
if a[0][1]==a[1][1]==a[2][1]==0:
        ans="Yes"
if a[0][2]==a[1][2]==a[2][2]==0:
    ans="Yes"
        
if 11 in nums and 22 in nums and 33 in nums:
    ans="Yes"

if 13 in nums and 22 in nums and 31 in nums:
    ans="Yes"
    
print(ans)
#In[]:
a,b,c,k = map(int,input().split())

ans = 0

ans += min(a,k)
k -= min(a,k)
ans += min(b,k)
k -= min(b,k)
ans += min(c,k)
k -= min(c,k)

print(ans)


### FIXED CODE ###

a = [input() for i in range(2)]

s = a[0]
t = a[1]

if s == t[:-1]:
    print('Yes')
else:
    print('No')
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
am = 0
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
if am >= m - 1:
    count -= 1
print(count)

### FIXED CODE ###

n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
if n <= m:
    print(1)
    exit()
count = 0
am = 0
count += i // (m - 1)
am += i % (m - 1)
count += (n - 1 - i) // (m - 1)
am += (n - 1 - i) % (m - 1)
if am <= m - 1 and am > 0:
    count += 1
if am > m - 1:
    count += 2
print(count)
N, M = map(int, input().split())
mod = 1e+9+7
flags = [True  for i in range(N)]
for i in range(M):
    tmp = int(input())
    flags[tmp-1] = False
dp = [0 for i in range(N)]
dp[0] = 1
dp[1] = 2

if not flags[0]:
    dp[0] = 0
    dp[1] = 1
if not flags[1]:
    dp[1] = 0
for i in range(2, N):
    if flags[i]:
        dp[i] = int((dp[i-1] + dp[i-2]) % mod)
print(dp)
    

### FIXED CODE ###

N, M = map(int, input().split())
mod = 1e+9+7
flags = [True  for i in range(N+1)]
for i in range(M):
    tmp = int(input())
    flags[tmp-1] = False
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 2

if not flags[0]:
    dp[0] = 0
    dp[1] = 1
if not flags[1]:
    dp[1] = 0
for i in range(2, N):
    if flags[i]:
        dp[i] = int((dp[i-1] + dp[i-2]) % mod)
print(dp[N-1])
sheep_number=S
wolf_number=W
if sheep_number<=wolf_number:
    print('unsafe')
else:
    print('safe')

### FIXED CODE ###

x,y = map(int,input().split())
if x<=y:
    print('unsafe')
else:
    print('safe')
F_str = input().split()
F = [int(f) for f in F_str]
N = F[0]
M = F[1]

WA_list = [0 for _ in range(N)]
AC_list = []

for i in range(M):
    S_str = input().split()
    S = [str(s) for s in S_str]
    if(S[1] == "AC"):
        AC_list.append(S[0])
        AC_list = list(set(AC_list))
    elif(not(S[0] in AC_list)):
        WA_list[int(S[0])-1] += 1
        
WA_count = 0

for item in AC_list:
    WA_count += WA_list[int(item)-1]

print(str(len(AC_list)) + " " + str(sum(WA_count)))

### FIXED CODE ###

F_str = input().split()
F = [int(f) for f in F_str]
N = F[0]
M = F[1]

WA_list = [0 for _ in range(N)]
AC_list = [0 for _ in range(N)]

for i in range(M):
    S_str = input().split()
    S = [str(s) for s in S_str]
    if(S[1] == "AC"):
        AC_list[int(S[0])-1] = 1
    elif(AC_list[int(S[0])-1] != 1):
        WA_list[int(S[0])-1] += 1

WA_count = 0
AC_count = 0

for i in range(N):
    if(AC_list[i] == 1):
        AC_count += 1
        WA_count += WA_list[i]

print(AC_count, WA_count)
def main():
  	import sys
    input = sys.stdin.readline
    
    n = int(input())
    
    l1 = l2 = l3 = 0
    for i in map(int,input().split()):
        if i == 1:
            l1 += 1
        elif i == 2:
            l2 += 1
        else:
            l3 += 1

    a = l2+l3
  	dp = [[[0.0]*(l3+1) for i in range(a+1)] for j in range(n+1)]

  	for i in range(1,n+1):
      	for j in range(min(i,a)+1):
          	for k in range(min(j,l3)+1):
              	s = i-j
              	t = j-k
              	count = n/(s+t+k)
              	if s > 0:
                  	count += dp[s-1][t][k]*(s/(s+t+k))     
              	if t > 0 :
                  	count += dp[s+1][t-1][k]*(t/(s+t+k))
              	if k > 0 :
                	count += dp[s][t+1][k-1]*(k/(s+t+k))

              	dp[s][t][k] = count

	print(dp[l1][l2][l3])
if __name__ == "__main__":
    main()



### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
I,J,K=0,0,0
for a in A:
    if a==1:
        I+=1
    if a==2:
        J+=1
    if a==3:
        K+=1
L=I+J+K
M=J+K
dp=[[[0.0]*(K+1) for i in range(M+1)] for i in range(L+1)]
for n in range(1,L+1):#n=i+j+k
    for m in range(min(n,M)+1):#m=j+k
        for k in range(min(m,K)+1):
            j=m-k
            i=n-m
            #print(i,j,k)
            ret=N/(i+j+k)
            if i>0:
                ret+=dp[i-1][j][k]*(i/(i+j+k))
            if j>0:
                ret+=dp[i+1][j-1][k]*(j/(i+j+k))
            if k>0:
                ret+=dp[i][j+1][k-1]*(k/(i+j+k))
            dp[i][j][k]=ret
print(dp[I][J][K])
v = input().split()
dif_max = -200000

for i in range(len(v)):
    v[i] = int(v[i])

len = v[0]
for i in range(2, len + 1, 1):
    for j in range(i + 1, len + 1, 1):
        dif = v[j] - v[i]
        dif_max = dif if dif_max < dif else dif_max

print(dif_max)

### FIXED CODE ###

cnt = int(input())
dif_max = -1000000000
v_min = 1000000000

for i in range(cnt):
    buf = int(input())
    if i > 0:
        dif_max = dif_max if buf - v_min < dif_max else buf - v_min
    v_min = buf if buf < v_min else v_min
print(dif_max)
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
A = np.sort(A)
c = 0
while len(A) > 0:
    ai = A[0]
    AL = A[1:]
    if ai != AL[0]:
        c += 1
    mask = AL % ai != 0
    A = AL[mask]
    if len(A) == 1:
        c += 1
        break
print(c)


### FIXED CODE ###

from collections import Counter
n = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)
A = list(set(A))
ok = [True] * (10**6+1)

for a in A:
    temp = a+a
    while temp < 10**6+1:
        ok[temp] = False
        temp += a

c = 0
for a in A:
    if C[a] == 1 and ok[a] == True:
        c += 1
print(c)
N,M = [int(x) for x in input().split()]
k = [0] * (M+1)
for i in range(N):
    a = [int(x) for i in input().split()]
    del a[0]
    for j in a:
        k[j] += 1
print(k.count(N))

### FIXED CODE ###

n,m = map(int, input().split())
ans = list(input().split())
ans = set(ans[1:])
for i in range(n-1):
    b = list(input().split())
    b = set(b[1:])
    ans = ans & b
print(len(ans))