Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
sH, sW = map(int, input().split())
sH, sW = sH - 1, sW - 1
gH, gW = map(int, input().split())
gH, gW = gH - 1, gW - 1
stage = []
scores = []
for _ in range(H):
    stage.append(list(input()))
    scores.append([float('inf')] * W)
scores[sH][sW] = 0
move_q = deque()
move_q.append([sW, sH])
dx_list = [0, 1, 0, -1]
dy_list = [1, 0, -1, 0]
while move_q:
    while move_q:
        # 移動AでBFS
        x, y = move_q.pop()
        for dx, dy in zip(dx_list, dy_list):
            nx, ny = x + dx, y + dy
            if nx < 0 or W <= nx or ny < 0 or H <= ny or stage[ny][nx] == '#':
                continue
            # if scores[ny][nx] == float('inf'):
            if scores[ny][nx] > scores[y][x]:
                scores[ny][nx] = scores[y][x]
                move_q.appendleft([nx, ny])

        # 移動bで動けるマスをmodeA_qに格納
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                nx, ny = x + dx, y + dy
                if nx < 0 or W <= nx or ny < 0 or H <= ny or stage[ny][nx] == '#':
                    continue
                # if scores[ny][nx] == float('inf'):
                if scores[ny][nx] > scores[y][x]:
                    scores[ny][nx] = scores[y][x] + 1
                    move_q.append([nx, ny])


# print(*scores,sep='\n')
if scores[gH][gW] == float('inf'):
    print(-1)
else:
    print(scores[gH][gW])


Fixed submission:
from collections import deque
H, W = map(int, input().split())
sH, sW = map(int, input().split())
sH, sW = sH - 1, sW - 1
gH, gW = map(int, input().split())
gH, gW = gH - 1, gW - 1
stage = []
scores = []
for _ in range(H):
    stage.append(list(input()))
    scores.append([float('inf')] * W)
scores[sH][sW] = 0
moveA_q = deque()
moveB_q = deque()
moveA_q.append([sW, sH])
moveB_q.append([sW, sH])
dx_list = [0, 1, 0, -1]
dy_list = [1, 0, -1, 0]
while moveA_q:
    if scores[gH][gW] != float('inf'):
        break
    # 移動AでBFS
    x, y = moveA_q.pop()
    moveB_q.append([x, y])
    for dx, dy in zip(dx_list, dy_list):
        nx, ny = x + dx, y + dy
        if nx < 0 or W <= nx or ny < 0 or H <= ny or stage[ny][nx] == '#':
            continue
        if scores[ny][nx] == float('inf'):
        # if scores[ny][nx] > scores[y][x]:
            scores[ny][nx] = scores[y][x]
            moveA_q.append([nx, ny])

    if not moveA_q:
        # 移動bで動けるマスをmodeA_qに格納
        while moveB_q:
            x, y = moveB_q.pop()
            for dx in range(-2, 3):
                for dy in range(-2, 3):
                    nx, ny = x + dx, y + dy
                    if nx < 0 or W <= nx or ny < 0 or H <= ny or stage[ny][nx] == '#':
                        continue
                    if scores[ny][nx] == float('inf'):
                    # if scores[ny][nx] > scores[y][x]:
                        moveA_q.append([nx, ny])
                        scores[ny][nx] = scores[y][x] + 1

# print(*scores,sep='\n')
if scores[gH][gW] == float('inf'):
    print(-1)
else:
    print(scores[gH][gW])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
now_sum_val = 1
for i in range(K):
    now_sum_val *= A[i]
for i in range(K, N):
    next_sum_val = now_sum_val // A[i - K] * A[i]
    if next_sum_val > now_sum_val:
        print('Yes')
    else:
        print('No')
    now_sum_val = next_sum_val

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(K, N):
    # next_sum_val = now_sum_val // A[i - K] * A[i]
    if A[i] > A[i - K]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
'''
with open('./b20.txt') as f:
    N, M, K = map(int, f.readline().split())
    A = list(map(int, f.readline().split()))
    B = list(map(int, f.readline().split()))
'''

A_cnt = 0
B_cnt = 0
ans = 0
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
    A_cnt += 1
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
    B_cnt += 1
tmp_ans = ans
finish = False
for i in range(A_cnt, 0, -1):
    nowK += A[i]
    tmp_ans -= 1
    for j in range(B_cnt, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        if j == M - 1:
            finish = True
    B_idx = j
    ans = max(tmp_ans, ans)
print(ans)




Fixed submission:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
A_cumulative_sum = [0]
B_cumulative_sum = [B[0]]
for i in range(N):
    A_cumulative_sum.append(A[i] + A_cumulative_sum[i])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B_cumulative_sum[i - 1])

for i in range(N + 1):
    if K < A_cumulative_sum[i]:
        remaining_time = K
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, idx)
        break
    else:
        remaining_time = K - A_cumulative_sum[i]
        idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
        ans = max(ans, i + idx)
print(ans)

# 113897
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
l = [0] * 10 ** 7
for i in range(1, N + 1):
    for j in range(0, N + 1, i):
        l[j] += 1

for i in range(1, N + 1):
    ans += i * l[i]
print(ans)


Fixed submission:
N = int(input())
ans = 0
l = [0] * (10 ** 7 + 1)
for i in range(1, N + 1):
    for j in range(i, N + 1, i):
        l[j] += 1

for i in range(1, N + 1):
    ans += i * l[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
l = [0] * 10 ** 7
for i in range(1, N + 1):
    for j in range(0, N + 1, i):
        l[j] += 1

for i in range(1, N + 1):
    ans += i * l[i]
print(ans)


Fixed submission:
N = int(input())
ans = 0
l = [0] * (10 ** 7 + 1)
for i in range(1, N + 1):
    for j in range(i, N + 1, i):
        l[j] += 1

for i in range(1, N + 1):
    ans += i * l[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
N -= 1
alphabets = []
for i in range(26):
    alphabets.append(chr(ord('a') + i))

idx = 1
now = 26
while now <= N:
    now += 26 ** (idx + 1)
    idx += 1
idx -= 1
ans = []
while idx > 0:
    ans.append(alphabets[N // (26 ** idx) - 1])
    N %= 26 ** idx
    idx -= 1
ans.append(alphabets[N])
print(*ans, sep='')

Fixed submission:
# [基本方針]
# コンプロでもやった進数変換の応用問題。今回は26進数変換を基本に考える。
# 1:aではなく、0:aを対応していると考える。そのため、26で割ったあまりを考える時、0:a、1:b,..., z:25と考えることができる。
# 計算量はO(logN)

N = int(input())
ans = ''
while N:
    # 1をaではなく、0をaに割り当てると考えるため、N-=1を行う。
    N -= 1

    # ここから下は基本的な進数変換と同じ
    alphabet = chr(ord('a') + N % 26)
    ans += alphabet
    N //= 26
    
# 文字列を反転させる
print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
x = int(input())
for i in range(100000):
	if x * i % 360 == 0:
        print(i)
	    exit()


Fixed submission:
x = int(input())
for i in range(1, 100000):
  if x * i % 360 == 0:
    print(i)
    exit()

Buggy python submission (verdict: Runtime Error):
x = int(input())
for i in range(100000):
	if x * i % 360 == 0:
	  print(i)
	    exit()


Fixed submission:
x = int(input())
for i in range(1, 100000):
  if x * i % 360 == 0:
    print(i)
    exit()

Buggy python submission (verdict: Runtime Error):
x = int(input())
for i in range(100000):
	if x * i % 360 == 0:
	print(i)
	    exit()


Fixed submission:
x = int(input())
for i in range(1, 100000):
  if x * i % 360 == 0:
    print(i)
    exit()

Buggy python submission (verdict: Runtime Error):
x = int(input())
for i in range(100000):
	if x * i % 360 == 0:
		print(i)
	    exit()


Fixed submission:
x = int(input())
for i in range(1, 100000):
  if x * i % 360 == 0:
    print(i)
    exit()

Buggy python submission (verdict: Runtime Error):
x = int(input())
for i in range(100000):
	if x * i % 360 == 0:
		print(i)
        exit()


Fixed submission:
x = int(input())
for i in range(1, 100000):
  if x * i % 360 == 0:
    print(i)
    exit()

Buggy python submission (verdict: Runtime Error):
x = int(input())
for i in range(100000):
	if x * i % 360 == 0:
		print(i)
	    exit()


Fixed submission:
x = int(input())
for i in range(1, 100000):
  if x * i % 360 == 0:
    print(i)
    exit()

Buggy python submission (verdict: Runtime Error):
x = int(input())
for i in range(100000):
  if x * i % 360 == 0:
	print(i)
    exit()

Fixed submission:
x = int(input())
for i in range(1, 100000):
  if x * i % 360 == 0:
    print(i)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
    if len(set(A)) == 1 and A[0] == N:
        break
    work = [0] * (N + 1)
    for i in range(N):
        a = A[i]
        idx0 = max(0, i - a)
        idx1 = min(N, i + a + 1)
        work[idx0] += 1
        work[idx1] -= 1
    now = 0
    for i in range(N):
        now += work[i]
        A[i] = now
print(*A)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(K):
    if len(set(A)) == 1 and A[0] == N:
        break
    work = [0] * (N + 1)
    for i in range(N):
        a = A[i]
        idx0 = max(0, i - a)
        idx1 = min(N, i + a + 1)
        work[idx0] += 1
        work[idx1] -= 1
    now = 0
    for i in range(N):
        now += work[i]
        A[i] = now
print(*A)
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split())
pirnt(a * b)

Fixed submission:
a, b = map(int,input().split())
print(a * b)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
print(int(A * B))

Fixed submission:
A, B = map(float, input().split())
B = B * 100 + 0.1
B = int(B)
print(int(A) * B // 100)
Buggy python submission (verdict: Runtime Error):
x = input()
pon = ['0', '1', '6', '8']
if x[-1] if pon:
  print('pon')
elif x[-1] == '3':
  print('bon')
else:
  print('hon')

Fixed submission:
x = input()
pon = ['0', '1', '6', '8']
if x[-1] in pon:
  print('pon')
elif x[-1] == '3':
  print('bon')
else:
  print('hon')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
r = g =  b = 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1

double = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = (j - i) * 2 + i
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            double += 1
print(r * g * b - double)

Fixed submission:
N = int(input())
S = input()
r = g =  b = 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1

double = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = (j - i) * 2 + i
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            double += 1
print(r * g * b - double)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
Graph = [[] for _ in range(N)]
for i in range(N):
    if i < N - 1:
        Graph[i].append(i + 1)
        Graph[i + 1].append(i)
    if X == i:
        Graph[X - 1].append(Y - 1)
        Graph[Y - 1].append(X - 1)
# print(Graph)
ans = [0] * (N - 1)
from collections import deque, Counter

for i in range(N):
    dist = [-1] * N
    que = deque([i])
    dist[i] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in Graph[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    # print(dist)
    dist_Counter = Counter(dist)
    for key, val in dist_Counter.items():
        if key != 0:
            ans[key - 1] += val

for a in ans:
    print(a // 2)


Fixed submission:
N, X, Y = map(int, input().split())
Graph = [[] for _ in range(N)]
for i in range(N):
    if i < N - 1:
        Graph[i].append(i + 1)
        Graph[i + 1].append(i)
    if X == i:
        Graph[X - 1].append(Y - 1)
        Graph[Y - 1].append(X - 1)
# print(Graph)
ans = [0] * (N - 1)
from collections import deque, Counter

for i in range(N):
    dist = [-1] * N
    que = deque([i])
    dist[i] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in Graph[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    # print(dist)
    dist_Counter = Counter(dist)
    for key, val in dist_Counter.items():
        if key != 0:
            ans[key - 1] += val

for a in ans:
    print(a // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
Graph = [[] for _ in range(N)]
for i in range(N):
    if i < N - 1:
        Graph[i].append(i + 1)
        Graph[i + 1].append(i)
    if X == i:
        Graph[X - 1].append(Y - 1)
        Graph[Y - 1].append(X - 1)
# print(Graph)
ans = [0] * (N - 1)
from collections import deque
for i in range(N):
    dist = [-1]*N
    que = deque([i])
    dist[i] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in Graph[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    # print(dist)
    for d in dist:
        if d > 0:
            ans[d - 1] += 1
for a in ans:
    print(a // 2)


Fixed submission:
N, X, Y = map(int, input().split())
Graph = [[] for _ in range(N)]
for i in range(N):
    if i < N - 1:
        Graph[i].append(i + 1)
        Graph[i + 1].append(i)
    if X == i:
        Graph[X - 1].append(Y - 1)
        Graph[Y - 1].append(X - 1)
# print(Graph)
ans = [0] * (N - 1)
from collections import deque, Counter

for i in range(N):
    dist = [-1] * N
    que = deque([i])
    dist[i] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in Graph[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    # print(dist)
    dist_Counter = Counter(dist)
    for key, val in dist_Counter.items():
        if key != 0:
            ans[key - 1] += val

for a in ans:
    print(a // 2)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
inversion_flag = False
for _ in range(Q):
    query_list = list(input().split())
    if query_list[0] == "1":
        inversion_flag = not inversion_flag
        continue
    C = query_list[2]
    if query_list[1] == "2":
        if inversion_flag:
            S.insert(0, C)
        else:
            S.append(C)
    else:
        if inversion_flag:
            S.append(C)
        else:
            S.insert(0, C)

if inversion_flag:
    print(*S[::-1], sep="")
else:
    print(*S, sep="")


Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
inversion_flag = False
for _ in range(Q):
    query_list = list(input().split())
    if query_list[0] == "1":
        inversion_flag = not inversion_flag
        continue
    C = query_list[2]
    if query_list[1] == "2":
        if inversion_flag:
            S.appendleft(C)
        else:
            S.append(C)
    else:
        if inversion_flag:
            S.append(C)
        else:
            S.appendleft(C)

S = list(S)
if inversion_flag:
    print(*S[::-1], sep="")
else:
    print(*S, sep="")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))
sc.sort()
for i in range(M - 1):
    if sc[i][0] == sc[i + 1][0] and sc[i][1] != sc[i + 1][1]:
        print('-1')
        exit()


max_len = sc[-1][0]
min_idx = sc[0][0]
is_ans = False
for i in range(10 ** (3 - min_idx),1000):
    str_num = str(i)
    num_len = len(str_num)
    for s, c in sc:
        # if num_len max_len:
        #     break
        if int(str_num[s - 1]) != c:
            break
    else:
        is_ans = True
        ans = i
        break
if is_ans:
    print(ans)
else:
    print("-1")


Fixed submission:
N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))

for i in range(1000):
    str_num = str(i)
    num_len = len(str_num)
    if num_len != N:
        continue
    for s, c in sc:
        if num_len < s:
            break
        if int(str_num[s - 1]) != c:
            break
    else:
        print(i)
        exit()

print("-1")
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
X_max = max(X)
ans = float('inf')
for i in range(X_max + 1):
    tmp_ans = 0
    for x in X:
        tmp_ans += (x - i) ** 2
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)


Fixed submission:
N , R = map(int,input().split())
if N < 10:
    print(100 * (10 - N) + R)
else:
    print(R)
Buggy python submission (verdict: Runtime Error):
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

def nCk(N, k, mod):
    ret_val = 1
    for i in range(k):
        ret_val *= (N - i)
        ret_val %= mod
        ret_val *= modinv(i + 1, mod)
        ret_val %= mod
    return ret_val


n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
all_cnt = pow(2, n, MOD) - 1
a_cnt = nCk(n, a, MOD)
b_cnt = nCk(n, b, MOD)
ans = all_cnt - a_cnt - b_cnt
print(ans　% MOD)


Fixed submission:
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

def nCk(N, k, mod):
    ret_val = 1
    for i in range(k):
        ret_val *= (N - i)
        ret_val %= mod
        ret_val *= modinv(i + 1, mod)
        ret_val %= mod
    return ret_val


n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
all_cnt = pow(2, n, MOD) - 1
a_cnt = nCk(n, a, MOD)
b_cnt = nCk(n, b, MOD)
ans = all_cnt - a_cnt - b_cnt
while ans < 0:
    ans += MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
H, N = map(int, input().split())
dp = [[0 for _ in range(H + 1)] for _ in range(N)]
A, B = map(int, input().split())
for i in range(H + 1):
    cnt = math.ceil(i / A)
    dp[0][i] = B * cnt

for i in range(1, N):
    A, B = map(int, input().split())
    for j in range(H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)
# print(*dp, sep='\n')
print(dp[-1][-1])

Fixed submission:
import math
H, N = map(int, input().split())
dp = [[0 for _ in range(H + 1)] for _ in range(N)]
A, B = map(int, input().split())
for i in range(H + 1):
    cnt = math.ceil(i / A)
    dp[0][i] = B * cnt

for i in range(1, N):
    A, B = map(int, input().split())
    for j in range(H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)
# print(*dp, sep='\n')
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 6)
Hitpoint, N = map(int, input().split())
magic_damage = []
magic_point = []
for _ in range(N):
    A, B = map(int, input().split())
    magic_damage.append(A)
    magic_point.append(B)

@lru_cache(maxsize=None)
def solve(i, now_HP):
    if now_HP <= 0:
        retval = 0
    elif i == N:
        retval = float('inf')
    else:
        retval = min(solve(i + 1, now_HP), solve(i, now_HP - magic_damage[i]) + magic_point[i])
    return retval


print(solve(0, Hitpoint))

Fixed submission:
import math
H, N = map(int, input().split())
dp = [[0 for _ in range(H + 1)] for _ in range(N)]
A, B = map(int, input().split())
for i in range(H + 1):
    cnt = math.ceil(i / A)
    dp[0][i] = B * cnt

for i in range(1, N):
    A, B = map(int, input().split())
    for j in range(H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)
# print(*dp, sep='\n')
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 6)
Hitpoint, N = map(int, input().split())
magic_damage = []
magic_point = []
dp = [[0] * (N + 1) for _ in range(N)]
for _ in range(N):
    A, B = map(int ,input().split())
    magic_damage.append(A)
    magic_point.append(B)

@lru_cache(maxsize=None)
def solve(i , now_HP):
    if now_HP <= 0:
        retval = 0
    elif i == N:
        retval = float('inf')
    else:
        retval = min(solve(i + 1 , now_HP) , solve(i, now_HP - magic_damage[i]) + magic_point[i])

    return retval
ans = solve(0, Hitpoint)
print(ans)


Fixed submission:
import math
H, N = map(int, input().split())
dp = [[0 for _ in range(H + 1)] for _ in range(N)]
A, B = map(int, input().split())
for i in range(H + 1):
    cnt = math.ceil(i / A)
    dp[0][i] = B * cnt

for i in range(1, N):
    A, B = map(int, input().split())
    for j in range(H + 1):
        dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)
# print(*dp, sep='\n')
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a , b = map(int,input().split())
print(lcm(a, b))

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

def lcm(x, y):
    return (x * y) // gcd(x, y)
a , b = map(int,input().split())
print(lcm(a, b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
info = [[] for _ in range(N)]
people = [-1] * N
for i in range(N):
    A = int(input())
    for j in range(A):
        x , y = map(int,input().split())
        info[i].append([A , x - 1 , y])
#print(info[0][0][0])
ans = 0
for i in range(2 ** N):
    cnt = 0
    Flag = True
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            people[j] = 1
        else:
            people[j] = 0
    for j in range(N):
        if i >> j & 1:
            info_num = info[j][0][0]
            for k in range(info_num):
                judge = info[j][k][2]
                origin = people[info[j][k][1]]
                if judge != origin:
                    Flag = False
                    break
        if not Flag:
            break
    if Flag:
        if ans < cnt:
            ans = cnt
print(ans)


Fixed submission:
N = int(input())
info = [[] for _ in range(N)]
people = [-1] * N
for i in range(N):
    A = int(input())
    if A == 0:
        info[i].append([0])
    for j in range(A):
        x , y = map(int,input().split())
        info[i].append([A , x - 1 , y])
#print(info[0][0][0])
ans = 0
# ビット全探索を行う
for i in range(2 ** N):
    cnt = 0
    Flag = True
    # ビットが１の時、正直者としてpeopleに格納
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            people[j] = 1
        else:
            people[j] = 0
    for j in range(N):
        # 正直者の発言と実際に正直者であるかを判定
        if i >> j & 1:
            info_num = info[j][0][0]
            for k in range(info_num):
                judge = info[j][k][2]
                origin = people[info[j][k][1]]
                if judge != origin:
                    Flag = False
                    break
        if not Flag:
            break
    if Flag:
        if ans < cnt:
            ans = cnt
print(ans)