Harryxun/stf_run huggingface dataset:
from collections import deque

N,M=map(int, raw_input().split())


par=[ i for i in range(N+1)  ]

def root(x):
	if par[x]==x:
		return x
	else:
		par[x]=root( par[x] )
		return par[x]

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

def unite(x,y):
	x=root(x)
	y=root(y)
	if x==y: return
	par[x]=y



for i in range(M):
	x,y,z=map(int, raw_input().split())
	unite(x,y)


S=set()
for i in range(1,N+1):
	S.add(root(i))


print len(S)



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N,M=map(int, raw_input().split())
par=[ i for i in range(N+1)  ]

def root(x):
	if par[x]==x:
		return x
	else:
		par[x]=root( par[x] )
		return par[x]

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

def unite(x,y):
	x=root(x)
	y=root(y)
	if x==y: return
	par[x]=y


for i in range(M):
	x,y,z=map(int, raw_input().split())
	unite(x,y)


S=set()
for i in range(1,N+1):
	S.add(root(i))

print len(S)
a, b = map(int, input().split())
if a>b:
    print('a>b')
elif a<b:
    print('a<b')
else:
    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')
# -*- coding: utf-8 -*-
n = int(input())
arr = [int(i) for i in input().split(" ")]
l = len(arr)
count = 1
for i in range(0, l-3):
    if arr[i] < arr[i+1] and arr[i*1] < arr[i*2]:
        count += 1

print(count)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
arr = [int(i) for i in input().split(" ")]
l = len(arr)
count = 0
for i in range(0, l-2):
    m = arr[i+1]
    tmp = [arr[i], arr[i+1], arr[i+2]]
    tmp.sort()
    if m == tmp[1]:
        count += 1
print(count)
a,b = map(int,input().split())
if (a=='H' and b == 'H')or(a == 'D'an b =='D'):
    print('H')
else:
    print('D')

### FIXED CODE ###

a,b = input().split()
if (a=='H' and b == 'H')or(a == 'D'and b =='D'):
    print('H')
else:
    print('D')
n = int(input())
A = list(map(int, input().split()))
B = [0]*N

for i in A:
    B[i-1] += 1

for i in B:
    print(i)


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
B = [0]*n

for i in A:
    B[i-1] += 1

for i in B:
    print(i)
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 21 20:39:09 2019

@author: Yamazaki Kenichi
"""

N,K = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

A.sort(reverse = True,key=lambda x:x[1])
eat,noteat =[],[]
a = [0 for i in range(N+1)]
k = K
for i in range(N):
    if k == 0:
        break    
    if a[A[i][0]] ==0:
        a[A[i][0]] = 1
        eat.append(A[i][1])
        k -= 1
    else:
        noteat.append(A[i][1])
ans = sum(eat)+ sum(noteat[:k])+ pow(K-k,2)

for i in range(1,min(K-k,len(noteat))):
    if pow(K-k,2)+eat[-i] < pow(K-k-i,2)+noteat[k:][i-1]:
        ans = ans-(pow(K-k,2)+eat[-i]) +(pow(K-k-i,2)+noteat[k:][i-1])
    else:
        break
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Jan 21 20:39:09 2019

@author: Yamazaki Kenichi
"""

N,K = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

A.sort(reverse = True,key=lambda x:x[1])
eat,noteat =[],[]
a = [0 for i in range(N+1)]
k = K
for i in range(N):
    if k != 0:
        if a[A[i][0]] ==0:
            a[A[i][0]] = 1
            eat.append(A[i][1])
            k -= 1
        else:
            noteat.append(A[i][1])
    else:
        noteat.append(A[i][1])
        
ans = [0 for i in range(min(K-k,len(noteat))+2)]
ans[0] = sum(eat)+ sum(noteat[:k])+ pow(K-k,2)

for i in range(1,min(K-k,len(noteat[k:])+1)):
    ans[i] = ans[i-1]-(pow(K-k-(i-1),2)+eat[-i]) +(pow(K-k-i,2)+noteat[k+i-1])

print(max(ans))
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
K = int(input())
t = 0
t1 = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            t1 = gcd(i,j)
            t = t + gcd(t1,l)
print(t)

### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
t = 0
t1 = 0
t2 = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for l in range(j,K+1):
            if i == j == l:
                t = t + i
            elif i == j or j ==l or l ==i:
                t = t + 3 * gcd(i, j,l)
            else:
                t = t + 6 * gcd(i,j,l)
             
           
           
print(t)
s =　input()
if s == 'AAA' or 'BBB':
  print('No')
else:
  print('Yes')


### FIXED CODE ###

s = input()
if s == 'AAA' or s == 'BBB':
  print('No')
else:
  print('Yes')
w,h,n=map(int,input().split())
w1=0
w2=w
h1=0
h2=h
for i in range(n):
    a,b,c=map(int,input().split())
    if c==1:
        w1=a
    elif c==2:
        w2=a
    elif c==3:
        h1=b
    elif c==4:
        h2=b
if w2<=w1 or h2<=h1:
    print(0)
else:
    print(max(0,(w2-w1)*(h2-h1))

### FIXED CODE ###

w,h,n=map(int,input().split())
w1=0
w2=w
h1=0
h2=h
for i in range(n):
    a,b,c=map(int,input().split())
    if c==1:
        w1=max(a,w1)
    elif c==2:
        w2=min(a,w2)
    elif c==3:
        h1=max(b,h1)
    elif c==4:
        h2=min(b,h2)
if w2<=w1 or h2<=h1:
    print(0)
else:
    print(max(0,(w2-w1)*(h2-h1)))
S = input()
if S[3] == S[4] and S[5] == S[6]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
if s[2] == s[3] and s[4] == s[5]:
  print("Yes")
else:
  print("No")
# coding: utf-8
# Your code here!
N=int(input())
l=[1]
count=0

def cand(num):
    i=1
    while N>=num**i:
        l.append(num**i)
        i+=1

def sub(target,index):
    i=0
    if target==0:
        
    elif index==0:
        
    while target-l[index]>0:
        sub(target-l[index]**i,l[index-1])
        

cand(6)
cand(9)

l.sort()
print(l)

#メモ　この方針があってるのかもわからん

### FIXED CODE ###

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

def saiki(tgt,i,count,ans):
    #print(tgt,i,count,ans,temp[i])

    if i==0 or tgt==0:
        ans=min((tgt+count),ans)
        return ans
        
    num=tgt//temp[i]
    while num>=0:
        ans=saiki(tgt-num*temp[i],i-1,count+num,ans)
        if ans<(count+num):
            return ans
        num-=1
    return ans

temp=[1]
n=1
while N>=6**n:
    temp.append(6**n)
    n+=1
    
n=1
while N>=9**n:
    temp.append(9**n)
    n+=1

temp.sort()
#print(temp)

print(saiki(N,len(temp)-1,0,10**9))
S,T = map(str, input().split())
A,B = map(int, input().split())
U = input()

if U = S:
    print({}""{},(A-1)+B)
else:
    print({}""{},A+(B-1))

### FIXED CODE ###

S,T = input().split()
A,B = map(int, input().split())
U = input()

if U == S: A-=1
else: B-=1
print(A,B)
a = int(input())

print(a * a * pi, 2* a * pi)


### FIXED CODE ###

import math

a = float(input())

print(a*a*math.pi, 2*a*math.pi)
N=int(input())
s=[]
total=0
A=0
B=0
for i in range(N):
    tmp=input()
    while True:
        if len(tmp)>=2:
            if "AB" in tmp[:2]:
                total+=1
                tmp=tmp[2:]
            else:
                break
        else:
            break
    while True:
        
        if len(tmp)>=2:
            if "AB" in tmp[-2:]:
                total+=1
                tmp=tmp[-2:]
            else:
                break
        else:
            break
    total+=tmp.count("AB")
    if len(tmp)>0:
        if tmp[0]=="B":
            B+=1
        if tmp[-1]=="A":
            A+=1"A":
            A+=1

print(total+min(A,B))


### FIXED CODE ###

N=int(input())
s=[]
total=0
A=0
B=0
BA=0
for i in range(N):
    tmp=input()
    while True:
        if len(tmp)>=2:
            if "AB" in tmp[:2]:
                total+=1
                tmp=tmp[2:]
            else:
                break
        else:
            break
    while True:
        
        if len(tmp)>=2:
            if "AB" in tmp[-2:]:
                total+=1
                tmp=tmp[-2:]
            else:
                break
        else:
            break
    total+=tmp.count("AB")
    if len(tmp)>0:
        if tmp[0]=="B" and tmp[-1]=="A":
            BA+=1
        elif tmp[0]=="B":
            B+=1
        elif tmp[-1]=="A":
            A+=1

if BA>0:
    if B>0 and A>0:
        total+=BA+1
        B-=1
        A-=1
    elif A>0:
        total+=BA
    elif B>0:
        total+=BA
    else:
        total+=BA-1
        
        
print(total+min(A,B))
a = input().split()
print(a[3] +' ' +a[1]+' ' + a[2])

### FIXED CODE ###

a = input().split()
print(a[2] +' ' +a[0]+' ' + a[1])
weather = ["Sunny","Cloudy","Rainly"]
S = input()
print(weather[(weather.index(S)+1)%3])


### FIXED CODE ###

weather = ["Sunny","Cloudy","Rainy"]
S = input()
print(weather[(weather.index(S)+1)%3])
print("please input W")
w=int(input())

print("please input N")
n=int(input())

i=0
j=0

if(h>=w):
  s=h
else:
  s=w

while j<n:
  i+=1
  j=j+s

print(i)

### FIXED CODE ###

h=int(input())

w=int(input())

n=int(input())

i=0
j=0

if(h>=w):
  s=h
else:
  s=w

while j<n:
  i+=1
  j=j+s

print(i)
import fractions
from functions import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = [int(i) for i in input().split()]
ans = 0
l,r = [],[]
for i in range(n):
	l = gcd_list([a[i] for m in range(i)])
	r = gcd_list([a[i] for m in range(n-1,i,-1)])
	ans = max(ans,l,r)
print(ans)


### FIXED CODE ###

from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(1,n):
    l.append(gcd(l[i-1],a[i-1]))
    r.append(gcd(r[i-1],a[-i]))
r = r[::-1]
ans = 0

for i in range(n):
    ans = max(ans,gcd(l[i],r[i]))
print(ans)
import numpy as np

n, k = map(int, input().split())
l = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1, n):
  start_index = max(i-k, 0)
  dp[i] = np.min(dp[start_index:i]+np.abs(l[start_index:i]-l[i]))

print(dp[-1])

### FIXED CODE ###

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

ans = [0, abs(l[0]-l[1])]
for i in range(2, n):
  ans.append(min(abs(l[i]-l[i-1])+ans[i-1], abs(l[i]-l[i-2])+ans[i-2]))

print(ans[n-1])
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int P = scanner.nextInt();
        int ans = (A*3+P)/2;
        System.out.println(ans);
    }
}

### FIXED CODE ###

A,P = map(int,input().split())
print(int((A*3+P)/2))
n = int(input())
s = list(i, int(j) for i, j in input().split()
ans = [s.index(i)+1 for i in sorted(s, key=lambda x:(x[0], -x[1]))]
print(i) for i in ans


### FIXED CODE ###

n = int(input())
s = list(list(input().split()) for _ in range(n))
ans = [s.index(i)+1 for i in sorted(s, key=lambda x:(x[0], -int(x[1])))]
for i in ans: print(i)
r = int(input())
PI = 3.141592653589793238462647950288419
S = r * r * PI
L = 2 * r * PI
print("%f %f" % (S, L))


### FIXED CODE ###

r = float(input())
import math
PI = math.pi
S = r * r * PI
L = 2 * r * PI
print("%f %f" % (S, L))
if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    leftList = []
    rightList =[]
    alist =[]

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]

    for i in alist:
        if len(i) == 3:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    rightList.append(i[2])
                else:
                    leftList.append(i[2])

            else:
                if rev_count % 2 == 1:
                    leftList.append(i[2])
                else:
                    rightList.append(i[2])

    ans = leftList.join + ans+rightList.join

    print(ans)



### FIXED CODE ###

from collections import deque

if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    leftList = deque()
    rightList =[]
    alist =[]

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]

    for i in alist:
        if len(i) == 1:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    rightList.append(i[2])
                else:
                    leftList.appendleft(i[2])

            else:
                if rev_count % 2 == 1:
                    leftList.appendleft(i[2])
                else:
                    rightList.append(i[2])

    ans = ''.join(leftList)+ ans+''.join(rightList)

    print(ans)
import sys
import numpy as np

def dijk(edge_list, start):
    queue = []
    dist = [100000 for i in range(10)]
    dist[start] = 0
    queue.append([i for i in range(10)])
    while len(queue) != 0:
        index = np.argmin(map(lambda x: dist[x], queue))
        node = queue.pop(index)
        for child in edge_list[node]:
            dist[child[0]] = min(dist[child[0]], child[1] + dist[node])

    return dist

H, W = list(map(int, sys.stdin.readline().strip().split(" ")))

edge_list = []
for i in range(10):
    l = list(map(int, sys.stdin.readline().strip().split(" ")))
    ll = []
    for j in range(10):
        ll.append((j, l[j]))
    edge_list.append(ll)

cost = []
for i in range(10):
    cost.append(dijk(edge_list, i)[1])

res = 0
for i in range(H):
    input_list = list(map(int, sys.stdin.readline().strip().split(" ")))
    res += np.sum(list(map(lambda x: 0 if (x == -1) else cost[x], input_list)))

print(res)


### FIXED CODE ###

import sys
import numpy as np

def dijk(edge_list, start):
    checked = []
    queue = []
    dist = [100000 for i in range(10)]
    dist[start] = 0
    queue.append(start)
    while len(queue) != 0:
        index = np.argmin(list(map(lambda x: dist[x], queue)))
        node = queue.pop(index)
        checked.append(node)
        for child in edge_list[node]:
            dist[child[0]] = min(dist[child[0]], child[1] + dist[node])
            if (child[0] not in queue) and (child[0] not in checked):
                queue.append(child[0])
    return dist

H, W = list(map(int, sys.stdin.readline().strip().split(" ")))

edge_list = []
for i in range(10):
    l = list(map(int, sys.stdin.readline().strip().split(" ")))
    ll = []
    for j in range(10):
        ll.append((j, l[j]))
    edge_list.append(ll)

cost = []
for i in range(10):
    cost.append(dijk(edge_list, i)[1])

res = 0
for i in range(H):
    input_list = list(map(int, sys.stdin.readline().strip().split(" ")))
    res += np.sum(list(map(lambda x: 0 if (x == -1) else cost[x], input_list)))

print(res)
s = input()
def dfs(t):
    if t==s:
        return True
    if len(t)>=len(s):
        return False
    for i in ['dream', 'dreamer', 'erase', 'eraser']:
        if dfs(t+i):
            return True
    return False
if dfs(''):
    print('YES')
else:
    print('NO')

### FIXED CODE ###

import sys 
sys.setrecursionlimit(10**6)
s = input()
def dfs(s):
    while True:
        f = True
        for i in ['erase', 'eraser', 'dream', 'dreamer']:
            if s[-len(i):]==i:
                s = s[:-len(i)]
                if s=='':
                    return True
                f = False
        if f: return False
    
if dfs(s):
    print('YES')
else:
    print('NO')
print(r.text[:300] + '...')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
i, j = b[n // 2 - 1], b[n // 2]
for x in a:
    if x <= i:
        print(j)
    else:
        print(i)
import fractions
  
def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)

N,M = map(int,input().split())
S = input()
T = input()

if M > N:
  N,M = M,N
  S,T = T,S

X = lcm(N,M)

n = N // fractions.gcd(N,M)
m = M // fractions.gcd(N,M)

for i in range(0,X,n):
  if S[0] != T[0]:
    print(-1)
    break
  elif i % m == 0:
    if S[n] != T[m]:
      print(-1)
      break
else:
  print(X)


### FIXED CODE ###

import fractions
  
def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)

N,M = map(int,input().split())
S = input()
T = input()

if M > N:
  N,M = M,N
  S,T = T,S

X = lcm(N,M)

n = N // fractions.gcd(N,M)
m = M // fractions.gcd(N,M)

for i in range(0,X,m):
  if S[0] != T[0]:
    print(-1)
    break
  elif i % n == 0:
    s = i // n
    t = i // m
    if S[t] != T[s]:
      print(-1)
      break
else:
  print(X)
N = int(input())
C = dict()
i, cp, lr = 0, 0, []
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            lr.append([C[c], i])
        C[c] = i
        cp = c
        i += 1
length = i
lr.sort()
hist, add, i, ans = [0] * length, [0] * length, 0, 0
for l, r in lr:
    while i <= l:
        hist[i] = hist[i-1] + add[i]
        ans += add[i]
        i += 1
    add[r] += hist[l] + 1
for i in range(l+1, length):
    ans += add[i]
print((ans+1) % (10**9+7))

### FIXED CODE ###

N = int(input())
C = dict()
i, cp, hist, ans = 0, 0, [0]*N, 0
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            temp = hist[C[c]] + 1
            hist[i] = hist[i-1] + temp
            ans += temp
        else:
            hist[i] += hist[i-1]
        C[c], cp = i, c
        i += 1
print((ans+1) % (10**9+7))
#coding:UTF-8
def Rec(N,List):
    for i in range(N):
        a=int(List[i].split(" ")[0])
        b=int(List[i].split(" ")[1])
        c=int(List[i].split(" ")[2])
        if a*a+b*b==c*c or a*a+c*c==b*b or b*b+c*c==a*a:
            print("YES")
        else:
            print("NO")
if __name__=="__main__":
    List=[]
    N=int(input())
    for i in range(N):
        List.append(input())
    Rec(N,List

### FIXED CODE ###

#coding:UTF-8
def Rec(N,List):
    for i in range(N):
        a=int(List[i].split(" ")[0])
        b=int(List[i].split(" ")[1])
        c=int(List[i].split(" ")[2])
        if a*a+b*b==c*c or a*a+c*c==b*b or b*b+c*c==a*a:
            print("YES")
        else:
            print("NO")

if __name__=="__main__":
    List=[]
    N=int(input())
    for i in range(N):
        List.append(input())
    Rec(N,List)
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**5
for i in range(1,n):
    if k>abs(a[0]//2-a[i]):
        k=abs(a[0]//2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**9
for i in range(1,n):
    if k>abs(a[0]/2-a[i]):
        k=abs(a[0]/2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
r1,c1,r2,c2=map(int,input().split())
mod=10**9+7
A=10**6+100
P=[0 for i in range(A+1)]

P[1]=1
for i in range(2,A):
    P[i]=P[i-1]*i%mod
gP=[pow(P[i],mod-2,mod) for i in range(len(P))]


def comb(x,y):
    if y>x or x<=0:
        return(0)
    elif y==0:
        return(1)
    else:
        return(P[x]*gP[x-y]%mod*gP[y]%mod)

count=0
for i in range(c1+1,c2+1 +1):
    count=(count+comb(i+r2,r2)-comb(i+r1-1,r1-1))%mod
print(count%mod)


### FIXED CODE ###

r1,c1,r2,c2=map(int,input().split())
mod=10**9+7
A=2*(10**6)+3
P=[0 for i in range(A+1)]
P[1]=1
for i in range(2,A):
    P[i]=P[i-1]*i%mod

dr2=pow(P[r2],mod-2,mod)
dr1=pow(P[r1-1],mod-2,mod)
def combr2(x):
    y=r2
    if y>x or x<=0:
        return(0)
    elif y==0:
        return(1)
    else:
        return(P[x]*pow(P[x-y],mod-2,mod)%mod*dr2%mod)

def combr1(x):
    y=r1-1
    if y>x or x<=0:
        return(0)
    elif y==0:
        return(1)
    else:
        return(P[x]*pow(P[x-y],mod-2,mod)%mod*dr1%mod)
count=0
for i in range(c1+1,c2+2):
    count=(count+combr2(i+r2)-combr1(i+r1-1))%mod
print(count%mod)
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(1, n+1):
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > k:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break
        if max(memo) <= k:
            print(k)
            exit()



### FIXED CODE ###

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

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

num = a[0]
for i in range(1, n):
    num = gcd(num, a[i])

if k > max(a):
    print("IMPOSSIBLE")
    exit()

if k % num == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
import numpy as np

n = int(input())
li = [np.full(n, -1, dtype=np.int) for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        li[i][x-1] = y

ans = 0
for i in range(2**n):
    s = 0
    t = [0]*n
    for j in range(n):
        if i>>j & 1:
            t[j]=1
    is_contradict = 0
    for j in range(n):
        if t[j]:
            for k in range(n):
                if li[j][k]==-1:
                    continue
                if li[j][k] != t[k]:
                    is_contradict = 1
    if not is_contradict:
        ans = max(ans, sum(t))

print(ans)


### FIXED CODE ###

n = int(input())
li = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        li[i][x-1] = y

ans = 0
for i in range(2**n):
    s = 0
    t = [0]*n
    for j in range(n):
        if i>>j & 1:
            t[j]=1
    is_contradict = 0
    for j in range(n):
        if t[j]:
            for k in range(n):
                if li[j][k]==-1:
                    continue
                if li[j][k] != t[k]:
                    is_contradict = 1
    if not is_contradict:
        ans = max(ans, sum(t))

print(ans)
def test(x):
print x*x*x

### FIXED CODE ###

x = raw_input()
x = int(x)
print x*x*x
n = input()
negBase = -2

if (n == 0): 
    converted = "0"

else:
    converted = "01"
    while (n != 0):           
        remainder = n % (negBase) 
        n = int(n/negBase) 
  
        if (remainder < 0): 
            remainder += ((-1) * negBase) 
            n += 1
  
        converted = str(remainder) + converted 
          
    converted = converted[0:len(converted)-2]

print(converted)

### FIXED CODE ###

n = int(input())
if n == 0:
  print('0')
  exit()
s = ''
while n != 0:
    s = str(n%2)+s
    n //= 2
    n *= -1
print(s)
t = list(input())

if t[0] == "?":
    if t[1] == "P":
        t[0] = "D"
    else:
        t[0] = "P"
for i in range(1, len(t)-1):
    if t[i] == "?" and t[i-1] == "P":
        t[i] = "D"
    elif t[i] == "?" and t[i+1] == "D":
        t[i] = "P"
    elif t[i] == "?" and t[i+1] == "?":
        t[i] = "P"
        t[i+1] = "D"
    elif t[i] == "?":
        t[i] = "D"
if t[-1] == "?":
    t[-1] = "D"

print("".join(t))

### FIXED CODE ###

t = list(input())

if len(t) == 1 and t[0] == "?":
    t[0] = "D"
    print(t[0])
    exit()

if t[0] == "?":
    if t[1] == "P":
        t[0] = "D"
    else:
        t[0] = "P"
for i in range(1, len(t)-1):
    if t[i] == "?" and t[i-1] == "P":
        t[i] = "D"
    elif t[i] == "?" and t[i+1] == "D":
        t[i] = "P"
    elif t[i] == "?" and t[i+1] == "?":
        t[i] = "P"
        t[i+1] = "D"
    elif t[i] == "?":
        t[i] = "D"
if len(t) > 1:
    if t[-1] == "?":
        t[-1] = "D"

print("".join(t))
a,b=input().split()
a=str(int(a)-1)
def f(x):
  c=int(x[0])
  d=int(x[1])
  m=(c-1)*100+d*10
  e=int(x[2])
  g=int(x[4])*10+int(x[5])
  if g<d*10+c:
    m+=e
  else:
    m=m+e+1
  return m
print(f(b)-f(a))
  

### FIXED CODE ###

a,b=input().split()
if a!='10000':
  a=str(int(a)-1)
def f(x):
  c=int(x[0])
  d=int(x[1])
  m=(c-1)*100+d*10
  e=int(x[2])
  g=int(x[3])*10+int(x[4])
  if g<d*10+c:
    m+=e
  else:
    m=m+e+1
  return m
print(f(b)-f(a))