Harryxun/stf_run huggingface dataset:
ans = 0
for bit in range(1<<N):
    count = [0]*M
    for i in range(N):
        if (bit >> i) & 1:
            for a in range(M):
                if i in ks[a][1:]:
                    count[a] +=1
    a = 0
    for i in range(M):
        if count[i] % 2 == p[i]:
            a += 1
            if a == M:
                ans += 1

print(ans)


### FIXED CODE ###

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

ans = 0
for bit in range(1<<N):
    count = [0]*M
    for i in range(N):
        if (bit >> i) & 1:
            for a in range(M):
                if i+1 in ks[a][1:]:
                    count[a] +=1
    a = 0
    for i in range(M):
        if count[i] % 2 == p[i]:
            a += 1
            if a == M:
                ans += 1

print(ans)
A, B, T = map(int, input().split())
int sum = 0
int t = 0
while(t < T+0.5):
  if t%A == 0:
    sum += B
  t += 1
print(sum)

### FIXED CODE ###

A, B, T = map(int, input().split())
cnt = T // A
ans = B * cnt
print(ans)
def solve():
    N, K = list(map(int, input().split()))

    TABLE = [[-1 for x in range(K + 3)] for y in range(N + 3)]

    def recur(i, k):
        if not TABLE[i][k] == -1:
            return TABLE[i][k]

        if not i < N:
            return 1

        ans = 0
        for a in range(K):
            if not a == k:
                ans += recur(i + 1, a)

        TABLE[i][k] = ans
        return TABLE[i][k]

    return recur(0, -1)


if __name__ == '__main__':
    res = solve()
    print(res)


### FIXED CODE ###

def solve():
    N, K = list(map(int, input().split()))

    TABLE = [[-1 for x in range(K + 3)] for y in range(N + 3)]

    def recur(i, k):
        if not i < N:
            return 1

        if not TABLE[i][k] == -1:
            return TABLE[i][k]

        ans = 0
        for a in range(K):
            if not a == k:
                ans += recur(i + 1, a)

        TABLE[i][k] = ans
        return TABLE[i][k]

    return recur(0, -1)


if __name__ == '__main__':
    res = solve()
    print(res)
import sys

def findminsum(lst,K,N):
    inf=10**10
    dp=[[inf]*N for s in range(K+1)]
    for s in range(K+1):
        for j in range(N):
            if j==0 and s<=lst[j]:
                ds[s][j]=lst[0]
            elif s>lst[j] and j>0:
                dp[s][j]=min(dp[s-lst[j]][j-1]+lst[j], dp[s][j-1])
            elif s<=lst[j] and j>0:
                dp[s][j]=min(lst[j],dp[s][j-1])
    # print(lst)
    # print(dp[0][:])
    # print(dp[1][:])
    # print(dp[K][:])
    return dp[K][N-1]

def main():
    N,K=map(int,sys.stdin.readline().strip().split())
    cards=list(map(int,sys.stdin.readline().strip().split()))
    cards.sort()
    nn=0
    for i in range(N):
        if cards[i]<K:
            c=cards[i]
            cards[i]=0
            if findminsum(cards,K-c,N)>=K:
                nn+=1
            cards[i]=c
        else:
            break
    print(nn)

if __name__=='__main__':
    main()


### FIXED CODE ###

#4 9
#1 3 5 6
#の時に1（正解は0）と出力されるがACになる

N, K = map(int, input().split())
a=list(map(int, input().split()))
a.sort()
ans = N
t = 0
for i in range(N-1, -1, -1) :
  if t+a[i] < K:
    t += a[i]
  else:
    ans = min(ans, i)
print(ans)
a,b = map(int, input().split())
if a > b:
 print('a > b')
else a < b:
 print('a < b')
else a=b:
 print('a = b')

### FIXED CODE ###

a,b = map(int, input().split())
if a > b:
 print("a > b")
elif a < b:
 print("a < b")
else:
 print("a == b")
from collections import deque, Counter


class UnionFind:
    def __init__(self, v):
        self.v = v
        self._tree = list(range(v + 1))
        self._counter = Counter(self._tree)

    def _root(self, a):
        queue = deque()
        while self._tree[a] != a:
            queue.append(a)
            a = self._tree[a]
        while queue:
            index = queue.popleft()
            self._tree[index] = a
        return a

    def union(self, a, b):
        root_a = self._root(a)
        root_b = self._root(b)
        if root_a == root_b:
            return

        self._tree[root_b] = root_a
        ca = self._counter[root_a]
        cb = self._counter[root_b]
        self._counter[root_a] += cb
        self._counter[root_b] = 0
        return ca * cb

    def find(self, a, b):
        return self._root(a) == self._root(b)


N, M = map(int, input().split(' '))
edges = [tuple(map(int, input().split(' '))) for _ in range(M)]

dp = [0] * (M + 1)
dp[-1] = N * (N - 1) // 2
union_find = UnionFind(N)

for i in range(M - 1, 0, -1):
    if dp[i + 1] == 0:
        break
    a, b = edges[i]
    minus = union_find.union(a, b)
    dp[i] = dp[i + 1] - minus

for i in range(M):
    print(dp[i + 1])


### FIXED CODE ###

from collections import deque, Counter


class UnionFind:
    def __init__(self, v):
        self.v = v
        self._tree = list(range(v + 1))
        self._counter = Counter(self._tree)

    def _root(self, a):
        queue = deque()
        while self._tree[a] != a:
            queue.append(a)
            a = self._tree[a]
        while queue:
            index = queue.popleft()
            self._tree[index] = a
        return a

    def union(self, a, b):
        root_a = self._root(a)
        root_b = self._root(b)
        if root_a == root_b:
            return 0

        self._tree[root_b] = root_a
        ca = self._counter[root_a]
        cb = self._counter[root_b]
        self._counter[root_a] += cb
        self._counter[root_b] = 0
        return ca * cb

    def find(self, a, b):
        return self._root(a) == self._root(b)


N, M = map(int, input().split(' '))
edges = [tuple(map(int, input().split(' '))) for _ in range(M)]

score = N * (N - 1) // 2
union_find = UnionFind(N)
scores = []

for a, b in reversed(edges):
    scores.append(score)
    if score == 0:
        continue
    minus = union_find.union(a, b)
    score -= minus

for s in reversed(scores):
    print(s)
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n == 2:
    dp = [-10**15]*(n+1)
    dp[2] = max(a[0], a[1])
    if n > 2:
        dp[3] = max(a[:3])
        aa = a[0]+a[2]
        for i in range(4, n+1):
            if i%2:
                aa += a[i-1]
                dp[i] = max(dp[i-1], dp[i-2]+a[i-1])
            else:
                dp[i] = max(aa, dp[i-2]+a[i-1])
    print(dp[n])

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))
    dp = [-10**15]*(n+1)
    dp[2] = max(a[0], a[1])
    if n > 2:
        dp[3] = max(a[:3])
        aa = a[0]+a[2]
        for i in range(4, n+1):
            if i%2:
                aa += a[i-1]
                dp[i] = max(dp[i-1], dp[i-2]+a[i-1])
            else:
                dp[i] = max(aa, dp[i-2]+a[i-1])
    print(dp[n])

if __name__ == "__main__":
    main()
while 1:
    a = int(input())
    if a ==0:
    break
    a = str(a)
    if a =
    print([a[i] for i in range(len(a))])
    
    


### FIXED CODE ###

while 1:
    n = input()
    if n == '0':
        break
    print(sum(int(x) for x in n))
S = input()
if S == 'SUN':
    print(7)
elif S = 'MON':
    print(6)
elif S = 'TUE':
    print(5)
elif S = 'WED':
    print(4)
elif S = 'THU':
    print(3)
elif S = 'FRI':
    print(2)
else:
    print(1)


### FIXED CODE ###

S = input()
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
else:
    print(1)
a, b, x = map(int, input())
if a <= x <= a+b:
    ans = "YES"
else:
    ans = "NO"
print(ans)

### FIXED CODE ###

a, b, x = map(int, input().split())
if a <= x <= a+b:
    ans = "YES"
else:
    ans = "NO"
print(ans)
N=int(input())
#G=[set() for _ in [0]*N]
G=[[]for i in range(N)]
#print(G)

for i in range(N-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1

    G[a].append((b,c))
    G[b].append((a,c))

#print(G)
#print(G)
ans=[-1]*N
#ルートでは親はいないから-1
#q=[(0,0,-1)]
"""
Q=[(0,0,-1)]
a,b,c=Q.pop()
print(a)
print(b)
print(c)
"""
"""
#print(q)
while q:
    #v：現在見ている点
    #p：vの親のノード
    #d：距離
    v,d,p=q.pop()
    if d%2==0:
        ans[v]=0
    else:
        ans[v]=1
    ans[v]=d
    for u,w in G[v]:
        #逆流を防ぐ
        if u==p:
            continue
        if w%2==0:
            pass
        else:
            d=1-d
        q.append((u,d,v))
    #print(q)
"""
def dfs(v,p,c):
    ans[v]=c
    #print(G[v])
    for u,w in G[v]:
        if u==p:
            continue
        if w%2==0:
            dfs(u,v,c)
        else:
            dfs(u,v,1-c)
dfs(0,-1,1)
print("\n".join(map(str,ans)))

### FIXED CODE ###

import sys
 
n = int(input())
links = [set() for _ in [0] * n]
for line in sys.stdin:
    u, v, w = map(int, line.split())
    u -= 1
    v -= 1
    links[u].add((v, w))
    links[v].add((u, w))
ans = [-1] * n
q = [(0, 0, -1)]
while q:
    v, d, p = q.pop()
    if d % 2 == 0:
        ans[v] = 0
    else:
        ans[v] = 1
    for u, w in links[v]:
        if u == p:
            continue
        q.append((u, d + w, v))
print('\n'.join(map(str, ans)))
while True:
    (n, x) =  [int(i) for i in input().split()]
    if n == x == 0:
        break

    for a in range(1, n+1):
        for b in range(a+1, n+1):
            for c in range(b+1, n+1):
                count = 0
                if (a + b + c) == x:
                    count += 1
                elif (a + b + c) > x:
                    break
    print(count)
~                 

### FIXED CODE ###

while True:
    (n, x) =  [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            for c in range(b+1, n+1):
                if (a + b + c) == x:
                    count += 1
                elif (a + b + c) > x:
                    break
    print(count)
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

dp = [-1 for _ in range(n)]

def checker(s, g):
    if s > g:
        return 0
    elif s == g:
        return 1
    else:
        if dp[g - s] != -1:
            return dp[g - s]
        else:
            ret = checker(s + 1, g) + checker(s + 2, g)
            dp[g - s] = ret
            return ret

if m == 0:
    c = checker(0, n)
else:
    s = 0
    g = a[0] - 1
    if g - s > 0:
        c = checker(s, g)
    else:
        c = 1
    if m == 1:
        s = a[0] + 1
        g = n
    else:
        for i in range(1, m):
            if a[i - 1] + 1 == a[i]:
                c = 0
                break
            else:
                s = a[i - 1] + 1
                g = a[i] - 1
                if g - s > 0:
                    c *= checker(s, g)
                s = a[m - 1] + 1
                g = n
    if g - s > 0:
        c *= checker(s, g)

print(c % 1000000007)


### FIXED CODE ###

n, m = map(int, input().split())
a = [True for _ in range(n + 1)]
for _ in range(m):
    a[int(input())] = False

dp = [0] * (n + 1)
dp[0] = 1

for now in range(n):
    for next in range(now + 1, min(n + 1, now + 3)):
        if a[next]:
            dp[next] += dp[now]
            dp[next] %= 1000000007

print(dp[n])
import sympy,math

N = int(input())
ttl = 0
tempNum = 0
count = 0

for i in range(1,N):
    tempNum = N - i
    count = len(sympy.divisors(tempNum))
    ttl += count

print(ttl)


### FIXED CODE ###

def make_divisors(n):
    cnt = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            cnt += 1
            if i != n // i:
                cnt += 1
        i += 1
    return cnt
numbers = [1,10, 100, 1000, 10000, 100000, 150000,200000, 250000,300000,350000, 400000,450000, 500000,550000,600000,630000,675000,700000,720000,750000,800000,825000,850000,875000,900000,912500,925000,950000,975000,987500,1000000]
datas = [0,23,473,7053,93643,1166714, 1810893, 2472071, 3145923, 3829761, 4522005,5221424,5927120,6638407,7354651,8075420,8509899,9164377,9529244,9821778,10261678,10997400,11366472,11736253,12106789,12478098,12664043,12850013,13222660,13595947,13782871,13969985]

N = int(input())
ttl = 0
numPin = 0

for i in range(len(numbers)):
    if N == 1000000:
        numPin = len(numbers) - 1
        break
    if numbers[i] <= N < numbers[i+1]:
        numPin = i
        break

if numPin != len(numbers)-1:
    if N - numbers[numPin] < numbers[numPin + 1] - N:
        for i in range(numbers[numPin], N):
            ttl += make_divisors(i)
        print(ttl + datas[numPin])
    else:
        for i in range(N,numbers[numPin+1]):
            ttl -= make_divisors(i)
        print(ttl + datas[numPin + 1])
else:
    print(datas[numPin])
import math

a, b= map(int, input().split())
def lcm(x, y):
    return (x * y)/math.gcd(x, y)

print(int(lcm(a, b)))


### FIXED CODE ###

import fractions as fr

a, b= map(int, input().split())
def lcm(x,y):
    return (x*y/fr.gcd(x,y))

print(int(lcm(a,b)))
def intinput(): return map(int,input().split())

def ab(i):
    global c,l,x
    while len(l[i])>0:
        if x[l[i][0]]==0:
            x[l[i][0]] = c.pop(0)
        else:
            return
        l[l[i][0]].remove(i)
        ab(l[i][0])
        l[i].pop(0)
    return

n=int(input())
l = [[] for _ in range(n+1)]
for i in range(n-1):
    a,b=intinput()
    l[a].append(b)
    l[b].append(a)
c = list(intinput())
c.sort(reverse=1)
x = [0 for _ in range(n+1)]
x[1]=c.pop(0)
for i in range(1,n+1):
    ab(i)
print(sum(x[2:]))
f = ""
q= len(x[1:])
for i in range(q):
    if i != q-1:
        f += str(x[i+1])+" "
    else:
        f += str(x[i+1])
print(f)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000) 

def intinput(): return map(int,input().split())

def ab(i):
    global c,l,x
    while len(l[i])>0:
        x[l[i][0]] = c.pop(0)
        l[l[i][0]].remove(i)
        ab(l[i][0])
        l[i].pop(0)
    return

n=int(input())
l = [[] for _ in range(n+1)]
for i in range(n-1):
    a,b=intinput()
    l[a].append(b)
    l[b].append(a)
c = list(intinput())
c.sort(reverse=1)
x = [0 for _ in range(n+1)]
x[1]=c.pop(0)
for i in range(1,n+1):
    ab(i)
print(sum(x[2:]))
f = ""
q= len(x[1:])
for i in range(q):
    if i != q-1:
        f += str(x[i+1])+" "
    else:
        f += str(x[i+1])
print(f)
n, k = map(int, input().split())

s = (input())

if s[k] is 'A':
	o = s[:k] + 'a' +s[k:] 
elif s[k] is 'B':
	o = s[:k] + 'b' +s[k:] 
elif s[k] is 'C':
	o = s[:k] + 'c' +s[k:] 

print(o)


### FIXED CODE ###

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

s = (input())

if s[k-1] is 'A':
	o = s[:k-1] + 'a' +s[k:] 
elif s[k-1] is 'B':
	o = s[:k-1] + 'b' +s[k:] 
elif s[k-1] is 'C':
	o = s[:k-1] + 'c' +s[k:] 

print(o)
N, M = map(int, input().split(' '))

data = []
l = 1
r = 10**5
for m in range(M):
    li, ri = map(int, input().split(' '))
    if li > l:
      l = li
    if ri < r:
      r = ri

if l<= N <= r:
  cnt = (N - l) + 1
elif r >= N:
  cnt = (r - l) + 1
else N < l:
  cnt = 0
  

### FIXED CODE ###

N, M = map(int, input().split(' '))
 
data = []
l = 1
r = 10**5
for m in range(M):
    li, ri = map(int, input().split(' '))
    if li > l:
      l = li
    if ri < r:
      r = ri
 
if l<= N <= r:
  cnt = (N - l) + 1
elif l > r:
  cnt = 0
elif r < N:
  cnt = (r - l) + 1
else:
  cnt = 0
 
print(cnt)
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
    t, a = list(map(int, input().split()))
    if ti == t and ai == a:
        continue
    ti = t
    ai = a
    niv = vp/(ti+ai)
    nit = tp/ti
    nia = ap/ai
    ni = math.ceil(max(niv, nit, nia))
    vi = ni*(ti+ai)
    if vi <= vp:
        ni += 1
        vi = ni*(ti+ai)
    vp = vi
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    #nit = math.ceil(tp/ti)
    #nia = math.ceil(ap/ai)
    nit = -tp//ti
    nia = -ap//ai
    ni = max(-nit, -nia)
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)
a,b=list(map(int,input().split()))
c=input().split()
d=c[b].swapecase()
c[b]=d
print(c)


### FIXED CODE ###

a,b=list(map(int,input().split()))
c=list(input())
d=c[b-1].swapcase()
c[b-1]=d
c=''.join(c)
print(c)
A,B,X=map(int,input().split())
if A>X:
    print("NO")
elif A<=X=<A+B:
    print("YES")
else :
    print("NO")

### FIXED CODE ###

A,B,X=map(int,input().split())
if A>X:
    print("NO")
elif A<=X<=A+B:
    print("YES")
else :
    print("NO")
n = int(input())
a = list(map(int,input().split()))
a.sort()
b = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 
     131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 
     67108864, 134217728, 268435456, 536870912]

t = []
bIdx = 0
for aa in a :
    while b[bIdx] <= aa:
        bIdx += 1   
    t.append(b[bIdx]-aa)

t.reverse()
a.sort(reverse=True)

#print(t,a)
sum = 0
i = 0

u = [0 for i in range(len(a))]

for i in range(len(a)-1):

    if u[i] > 0:
        continue

    for j in range(i+1,len(a)):
        if a[j] == t[i] and u[j] <= 0:
            sum += 1
            u[j] += 1
    #print(a)
    
print(sum)

### FIXED CODE ###

from bisect  import bisect_left

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

sum = 0
for i in range (len(a)-1,-1,-1):

    b = 1
    while b <= a[i]:
        b = b<<1
    t = b - a[i]
    #print("2^",t)

    k = bisect_left(a,t)
    if a[k] == t and k < i:
        sum += 1
        a[k] -= 0.1
        a[i] += 0.1
print(sum)
from math import math

K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += gcd(gcd(i,j),k)
print(cnt)

### FIXED CODE ###

from math import gcd

K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += gcd(gcd(i,j),k)
print(cnt)
n,T = map(int,input().split())
c = list(map(int,input().split()))
t = list(map(int,input().split()))
min = 1000
for i in range(n):
    if T > t[i] and min > c[i]:
        min = c[i]
if min ==1000:
    print('TLE')
else:
    print(min)

### FIXED CODE ###

n,T= map(int,input().split())
min = 1001
for i in range(n):
    c,t = map(int,input().split())
    if T >= t and min > c:
        min = c
if min > 1000:
    print('TLE')
else:
    print(min)
def comb1(n, r):
    if n == 0 or r == 0: return 1
    return comb1(n, r-1) * (n-r+1) / r 
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
# N, M = 10, 400000000
# A = [int(i) for i in '1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000'.split()]
surplus = {0:0}
res = 0
tmp = 0
B = []
for i in range(0, N):
    tmp += A[i] % M
    B.append(tmp)
    surplus[tmp] = 0
for i in B:
    surplus[i] += 1
for tmp_key in surplus.keys():
    res += comb1(surplus[tmp_key], 2)

corner = surplus[0]
if corner == 0:
    res -= 1
else:
    res += corner
print(int(res))

### FIXED CODE ###

N, K = map(int, input().split())
if N % K==0:
    print(0)
else:
    print(1)
# https://atcoder.jp/contests/dp/tasks/dp_c
N = int(input())
Max_List=[]
N_List=[i for i in range(3)]
for i in range(N):
    Current_Max_List = []
    Current_List=list(map(int,input().split())) 
    if i == 0:
        Max_List.append(Current_List)
    else:
        for j in range(3):
            Index_List=np.array(Max_List[i-1])
            ind = np.ones(3, dtype=bool)
            ind[j] = False
            Current_Max_List.append(max(Index_List[ind])+Current_List[j])
            
        Max_List.append(Current_Max_List)
 
print(max(Max_List[-1]))

### FIXED CODE ###

# https://atcoder.jp/contests/dp/tasks/dp_c
import numpy as np
N = int(input())
Max_List=[]
N_List=[i for i in range(3)]
for i in range(N):
    Current_List=list(map(int,input().split())) 
    if i == 0:
        Max_List.append(Current_List)
    else:
        Current_Max_List = []
        for j in range(3):
            Index_List=np.array(Max_List[i-1])
            ind = np.ones(3, dtype=bool)
            ind[j] = False
            Current_Max_List.append(max(Index_List[ind])+Current_List[j])
            
        Max_List.append(Current_Max_List)
        
    
print(max(Max_List[-1]))
K,A,B=map(int,input().split())


ans=1+K
count=0
count=(K-(A))//2
ANS=1+(K-2*count)+abs(A-B)*count

print(max(ANS,ans))


### FIXED CODE ###

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

ans='NO'

if N%2==0 and K<=(N/2):
    ans='YES'
if N%2==1 and K<=((N+1)/2) :
    ans='YES'

print(ans)
import sys
input = sys.stdin.readline
n = int(input())
A = []
for i in range(n):
    rs = list(map(int, input().split()))
    rs = [r-1 for r in rs]
    A.append(rs)

cnts = [0] * n
days = 1
while True:
    tekis = []
    # print("Day",days, cnts)
    fin = 0
    for cnt,a in zip(cnts, A):
        if cnt == n-1: 
            tekis.append(-1)
            fin += 1
        else: 
            tekis.append(a[cnt])
    if fin == n: 
        print(days-1)
        exit()
    # 敵の敵が自分だったらマッチング成立
    flg = False
    matched = [False] * n
    for i,teki in enumerate(tekis):
        if matched[teki] or teki==-1:continue
        if tekis[teki] == i:
            cnts[i] += 1
            matched[i] = True
            cnts[teki] += 1
            matched[teki] = True
            flg = True
            # print("{}vs{}".format(i,teki))
    # マッチングが一つも成立しない
    days > 50000:
        print(-1)
    if not flg:
        print(-1)
        exit()
    days += 1


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict, deque
n = int(input())
X = 10000
INF = 1 << 50
edges = defaultdict(list)
edges_r = defaultdict(list)
def topological_sort(G):

    cnt_in = defaultdict(int)
    for k in G.keys():
        for v in G[k]:
            cnt_in[v] += 1
    # print(cnt_in)
    res = []
    # 入次数==0
    q = deque([i for i in list(G.keys()) if cnt_in[i]==0])
    while len(q) > 0:
        v = q.popleft()
        res.append(v)
        for next_v in G[v]:
            # 入次数を下げていく
            cnt_in[next_v] -= 1
            # 入次数が0に残ったところを次に追加
            if cnt_in[next_v] == 0:
                q.append(next_v)
    # トポソ不可能！
    if len(G) != len(res):
        print(-1)
        exit()
    return res

for i in range(n):
    r = list(map(int, input().split()))
    # 初期
    mn = min(i, r[0]-1)
    mx = max(i, r[0]-1)
    prev = mn * n + mx
    for e in r[1:]:
        e -= 1
        mn = min(i,e)
        mx = max(i,e)
        now = mn*n+mx
        edges[prev].append(now)
        edges_r[now].append(prev)
        prev = now
vs = topological_sort(edges)

# トポソの順番で経路長を入れていく
used = [0] * n**2
# for V in vs:
#     if used[V]: continue
#     used[V] = 1
#     q = deque([V])
#     while len(q) > 0:
#         v = q.popleft()
#         for u in edges[v]: 
#             if used[u] <= used[v]:
#                 q.append(u)
#                 used[u] = max(used[u], used[v] + 1)

for V in vs:
    if used[V]:continue
    used[V] = 1
    mx = 1
    for b in edges_r[V]:
        mx = max(mx, used[b]+1)
    used[V] = mx
# print(used)
print(max(used))
n = int(input())

if n%2 = 0:
    ans = n//2
else:
    ans = (n+1)//2

print(ans)ß

### FIXED CODE ###

n = int(input())

if n%2 == 0:
    ans = n//2
else:
    ans = (n+1)//2

print(ans)
[a,b,c]=list(map(int,input().split())
if a<b<c
  print:{"true"}

### FIXED CODE ###

[a,b,c]=list(map(int,input().split()))
if a<=c<=b:
  print("Yes")
else:
  print("No")
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
ans=[]
n=int(raw_input())
for _ in range(n):
    a=raw_input().split()
    if a[0]=='insert': ans.insert(0,a[1])
    elif a[0]=='deleteFirst': del ans[0]
    elif a[0]=='deleteLast': del ans[-1]
    else: ans.remove(a[1])
print ' '.join(ans)

### FIXED CODE ###

import sys
import collections
n=int(raw_input())
ans=collections.deque()
while n:
    n-=1
    s=sys.stdin.readline().rstrip().split(' ')
    if s[0][0]=='i':
        ans.appendleft(s[1])
    elif s[0][-3]=='r':
        ans.popleft()
    elif s[0][-3]=='a':
        ans.pop()
    else:
        try:
            ans.remove(s[1])
        except:
            pass
sys.stdout.write(' '.join(ans))
print