Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02574 (python)

Fixed submission:
import math
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

max_A = max(A)
sqrt_max_A = math.ceil(max_A ** 0.5)
sieve = list(range(2, max_A+1))
prime = list(range(max_A+1))
while len(sieve) > 0 and sieve[0] <= sqrt_max_A:
    p = sieve[0]
    prime[p]= p
    new_sieve = []
    for s in sieve:
        if s % p == 0:
            prime[s] = p
        else:
            new_sieve.append(s)
    sieve = new_sieve

factors = {}
pairwise = True
for a in A:
    while prime[a] != a:
        if prime[a] in factors:
            pairwise = False
            break
        factors[prime[a]] = True
        p = prime[a]
        while a % p == 0:
            a //= p
    if a != 1:
        if a in factors:
            pairwise = False
        else:
            factors[a] = True
    if not pairwise:
        break
if pairwise:
    print('pairwise coprime')
else:
    gcd = reduce(math.gcd, A)
    if gcd == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
max_A = max(A)
sqrt_max_A = max_A ** 0.5
sieve = list(range(2, max_A+1))
prime = list(range(max_A+1))
while True:
    p = sieve[0]
    prime[p]= p
    if p > sqrt_max_A:
        break
    new_sieve = []
    for s in sieve:
        if s % p == 0:
            prime[s] = p
        else:
            new_sieve.append(s)
    sieve = new_sieve
factors = {}
pairwise = True
for a in A:
    while prime[a] != a:
        if prime[a] in factors:
            pairwise = False
            break
        factors[prime[a]] = True
        p = prime[a]
        while a % p == 0:
            a //= p
    if a in factors:
        pairwise = False
    else:
        factors[a] = True
    if not pairwise:
        break
if pairwise:
    print('pairwise coprime')
else:
    gcd = reduce(math.gcd, A)
    if gcd == 1:
        print('setwise coprime')
    else:
        print('not coprime')
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

red = p[:X]
green = q[:Y]

red_no_eat = 0
green_no_eat = 0
for no in r:
    red_worst = red[-red_no_eat - 1] if red_no_eat < X else 10 ** 10
    green_worst = green[-green_no_eat - 1] if green_no_eat < Y else 10 ** 10
    if no > red_worst or no > green_worst:
        if red_worst < green_worst:
            red_no_eat += 1
        else:
            green_no_eat += 1
print(sum(p[:X-red_no_eat]) + sum(q[:Y-green_no_eat]) + sum(r[:red_no_eat+green_no_eat]))

Buggy submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

red = p[:X]
green = q[:Y]

red_no_eat = 0
green_no_eat = 0
for no in r:
    red_worst = red[-red_no_eat - 1] if red_no_eat <= X else 10 ** 10
    green_worst = green[-green_no_eat - 1] if green_no_eat <= Y else 10 ** 10
    if no > red_worst or no > green_worst:
        if red_worst < green_worst:
            red_no_eat += 1
        else:
            green_no_eat += 1
print(sum(p[:X-red_no_eat]) + sum(q[:Y-green_no_eat]) + sum(r[:red_no_eat+green_no_eat]))

Buggy submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

red = p[:X]
green = q[:Y]

red_no_eat = 0
green_no_eat = 0
for no in r:
    if no > red[-red_no_eat - 1] or no > green[-green_no_eat - 1]:
        if red[-red_no_eat - 1] < green[-green_no_eat-1]:
            red_no_eat += 1
        else:
            green_no_eat += 1
print(sum(p[:X-red_no_eat]) + sum(q[:Y-green_no_eat]) + sum(r[:red_no_eat+green_no_eat]))
Problem p02803 (python)

Fixed submission:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())

def bfs(start):
    already = {}
    queue = []
    counter = 0
    queue.append((start[0], start[1], 0))
    already[start] = True
    max_depth = 0
    while counter < len(queue):
        y, x, depth = queue[counter]
        if depth > max_depth:
            max_depth = depth
        for move in ((-1, 0), (0, 1), (1, 0), (0, -1)):
            new_y = y + move[0]
            new_x = x + move[1]
            if new_y >= 0 \
            and new_y < H \
            and new_x >= 0 \
            and new_x < W \
            and S[new_y][new_x] == '.' \
            and (new_y, new_x) not in already:
                already[(new_y, new_x)] = True
                queue.append((new_y, new_x, depth+1))
        counter += 1
    return max_depth

answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        depth = bfs((i, j))
        if answer < depth:
            answer = depth
print(answer)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())

def bfs(start):
    already = {}
    queue = []
    counter = 0
    queue.append((start[0], start[1], 0))
    already(start) = True
    max_depth = 0
    while counter < len(queue):
        y, x, depth = queue[counter]
        if depth > max_depth:
            max_depth = depth
        for move in ((-1, 0), (0, 1), (1, 0), (0, -1)):
            new_y = y + move[0]
            new_x = x + move[1]
            if new_y >= 0 \
            and new_y < H \
            and new_x >= 0 \
            and new_x < W \
            and S[new_y][new_x] == '.' \
            and (new_y, new_x) not in already:
                already[(new_y, new_x)] = True
                queue.append((new_y, new_x, depth+1))
        counter += 1
    return max_depth

answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        depth = bfs((i, j))
        if answer < depth:
            answer = depth
print(answer)
Problem p02838 (python)

Fixed submission:
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
MOD = 10 ** 9 + 7
for a in A:
    i = 0
    waru = 1
    while a > 0:
        if a % (waru * 2) != 0:
            a -= waru
            bit[i] += 1
        waru *= 2
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % MOD)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * (math.ceil(math.log2(max(A))))
MOD = 10 ** 9 + 7
for a in A:
    b = a
    i = 0
    while a > 0:
        if a % (2 ** (i+1)) != 0:
            a -= 2 ** i
            bit[i] += 1
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % MOD)
Problem p02936 (python)

Fixed submission:
N, Q = map(int, input().split())
tree = [[] for i in range(N)]
for i in range(N-1):
    ai, bi = map(int, input().split())
    ai -= 1
    bi -= 1
    tree[ai].append(bi)
point = [0] * N
for j in range(Q):
    pi, xi = map(int, input().split())
    pi -= 1
    point[pi] += xi

answer = [0] * N
queue = []
counter = 0
queue.append((0, 0))
while True:
    if counter == len(queue):
        break
    node, p = queue[counter]
    counter += 1


    answer[node] = p + point[node]
    for t in tree[node]:
        queue.append((t, answer[node]))

print(' '.join(map(str,answer)))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
tree = [[] for i in range(N)]
for i in range(N-1):
    ai, bi = map(int, input().split())
    ai -= 1
    bi -= 1
    tree[ai].append(bi)
point = [0] * N
for j in range(Q):
    pi, xi = map(int, input().split())
    pi -= 1
    point[pi] = point[pi] + xi

# print(tree)
# print(point)

answer = [0] * N
def dfs(node, p):
    answer[node] = p + point[node]
    for t in tree[node]:
        dfs(t, answer[node])
    return None

dfs(0, 0)
print(' '.join(map(str,answer)))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
tree = [[] for i in range(N)]
for i in range(N-1):
    ai, bi = map(int, input().split())
    ai -= 1
    bi -= 1
    tree[ai].append(bi)
point = [0] * N
for j in range(Q):
    pi, xi = map(int, input().split())
    pi -= 1
    point[pi] = point[pi] + xi

print(tree)
print(point)

answer = [0] * N
def dfs(node, p):
    answer[node] = p + point[node]
    for t in tree[node]:
        dfs(t, answer[node])
    return None

dfs(0, 0)
print(' '.join(map(str,answer)))
Problem p03044 (python)

Fixed submission:
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while counter < N - 1:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')

Buggy submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph.get(node, {}):
        if answer[n] == -1:
            search(n,depth + graph[node][n])
if N == 1:
    print('0')
else:
    search(root, 0)
    for a in answer:
        print('0' if a % 2 else '1')

Buggy submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            search(n,depth + graph[node][n])
if N == 1:
    print('0')
else:
    search(root, 0)
    for a in answer:
        print('0' if a % 2 else '1')

Buggy submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            search(n,depth + graph[node][n])

search(root, 0)
for a in answer:
    print('0' if a % 2 else '1')

Buggy submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

print(graph)

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            search(n,depth + graph[node][n])

search(root, 0)
for a in answer:
    print('0' if a % 2 else '1')
Problem p03047 (python)

Fixed submission:
N, K = map(int, input().split())

print(N-K+1)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input())

print(N-K+1)
Problem p03080 (python)

Fixed submission:
N = input()
s = input()

r = 0
b = 0
for s_i in s:
    if s_i == 'R':
        r += 1
    else:
        b += 1

if r > b:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = input()
s = input()

r = 0
b = 0
for s_i in s:
    if s_i == 'R':
	r += 1
    else:
	b += 1

if r > b:
    print('Yes')
else:
    print('No')
Problem p03085 (python)

Fixed submission:
b = input()

if b ==	'A':
    print('T')
elif b == 'T':
    print('A')
elif b =='C':
    print('G')
elif b == 'G':
    print('C')

Buggy submission (verdict: Runtime Error):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    l, r = (int(x) for x in input().split())
    sub_S = S[l-1:r]
    count = 0
    print('hoge')
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

for i in range(Q):
    l, r = map(int, input().split())
    l = l - 1
    r = r - 1
    print(AC_appearance[r] - AC_appearance[l])

Buggy submission (verdict: Runtime Error):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    l, r = (int(x) for x in input().split())
    sub_S = S[l-1:r]
    count = 0
	print('test')
Problem p03244 (python)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))

even_dict = {}
odd_dict = {}
for i, value in enumerate(v):
    if i % 2:
        even_dict[value] = 1 if value not in even_dict else even_dict[value] + 1
    else:
        odd_dict[value] = 1 if value not in odd_dict else odd_dict[value] + 1

counter = 0
even = sorted(even_dict.items(), key=lambda x: x[1], reverse=True)
odd = sorted(odd_dict.items(), key=lambda x: x[1], reverse=True)

if even[0][0] == odd[0][0]:
    even_second = 0 if len(even) < 2 else even[1][1]
    odd_second = 0 if len(odd) < 2 else odd[1][1]
    if even[0][1] - even_second > odd[0][1] - odd_second:
        counter += sum([x[1] for x in even[1:]])
        counter += sum([x[1] for x in odd[2:] + [odd[0]]])
    else:
        counter += sum([x[1] for x in odd[1:]])
        counter += sum([x[1] for x in even[2:] + [even[0]]])
else:
    counter += sum([x[1] for x in even[1:]])
    counter += sum([x[1] for x in odd[1:]])

print(counter)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = list(map(int, input().split()))

even_dict = {}
odd_dict = {}
for i, value in enumerate(v):
    if i % 2:
        even_dict[value] = 1 if value not in even_dict else even_dict[value] + 1
    else:
        odd_dict[value] = 1 if value not in odd_dict else odd_dict[value] + 1

counter = 0
even = sorted(even_dict.items(), key=lambda x: x[1], reverse=True)
odd = sorted(odd_dict.items(), key=lambda x: x[1], reverse=True)

if even[0][0] == odd[0][0]:
    if even[0][1] - even[1][1] > odd[0][1] - odd[1][1]:
        counter += sum([x[1] for x in even[1:]])
        counter += sum([x[1] for x in odd[2:] + [odd[0]]])
    else:
        counter += sum([x[1] for x in odd[1:]])
        counter += sum([x[1] for x in even[2:] + [even[0]]])
else:
    counter += sum([x[1] for x in even[1:]])
    counter += sum([x[1] for x in odd[1:]])

print(counter)
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())

if S[0] == '1':
    counter = 1
    for s in S:
        if s != '1' or counter >= K:
            print(s)
            break
        counter += 1 
else:
    print(S[0])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

if S[0] == '1':
    print(S[1])
else:
    print(S[0])
Problem p03294 (python)

Fixed submission:
import fractions
N = int(input())
a = list(map(int, input().split()))

lcm = a[0]
for item in a[1:]:
    lcm = (lcm * item) // fractions.gcd(lcm, item)
f = 0
for item in a:
    f += (lcm - 1) % item
print(f)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
a = list(map(int, input().split()))

# mはaの(最小公倍数 - 1)
lcm = a[0]
for item in a[1:]:
    lcm = (lcm * item) // math.gcd(lcm, item)
f = 0
for item in a:
    f += (lcm - 1) % item
print(f)
Problem p02677 (python)

Fixed submission:
import math
a, b, h, m = [int(i) for i in input().split()]

rad = math.pi * 2 * (h/12.0 + m/60.0 / 12.0 - m/60.0)
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad))
print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

const double PI = acos(-1);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double th = double(h * 60 + m) / 720 * 2 * PI;
  double tm = double(m) / 60 * 2 * PI;
  double xh = a * cos(th), yh = a * sin(th);
  double xm = b * cos(tm), ym = b * sin(tm);
  // 2乗するので絶対値を取る必要はない
  double dx = xh - xm, dy = yh - ym;
  double ans = sqrt(dx * dx + dy * dy);
  printf("%.10f\n", ans);
  return 0;
}
Problem p02684 (python)

Fixed submission:
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = []
o = [-1] * (n + 1)  # ord 訪れた箇所, v が1スタートなので注意
c, l = 1, 0  # 周期, 例外

v = 1
while o[v] == -1:
    o[v] = len(s)
    s.append(v)
    v = a[v-1]
c = len(s) - o[v]
l = o[v]

if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l + k])

Buggy submission (verdict: Runtime Error):
6 727202214173249351
6 5 2 5 3 2
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = []
o = [-1] * (n + 1)  # ord 訪れた箇所, v が1スタートなので注意
c, l = 1, 0  # 周期, 例外

v = 1
while o[v] == -1:
    o[v] = len(s)
    s.append(v)
    v = a[v-1]
c = len(s) - o[v]
l = o[v]

if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l + k])
Problem p02774 (python)

Fixed submission:
import numpy as np

n, k = [int(i) for i in input().split()]
a = np.array(sorted([int(i) for i in input().split()]))
posi = a[a > 0]
zero = a[a == 0]
nega = a[a < 0]

# 2分探索, mid より小さいものを数える
l = -10 ** 18 - 1
r = 10 ** 18 + 1
while r - l > 1:
    mid = (r + l) // 2
    cnt = 0
    if mid >= 0:
        cnt += len(zero) * n

    cnt += a.searchsorted(mid // posi, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid // nega), side="left")).sum()
    cnt -= np.count_nonzero(a * a <= mid)
    cnt //= 2
    if cnt >= k:
        r = mid
    else:
        l = mid
print(r)

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    for j in range(i + 1, n):
        print(a[i], a[j])
        b.append(a[i] * a[j])
ans = list(sorted(b))
print(ans[k])
Problem p02802 (python)

Fixed submission:
N, M = [int(i) for i in input().split()]

ac, wa = 0, 0
hist_ac, hist_wa = [0] * N, [0] * N
for i in range(M):
    p, s = input().split()
    p = int(p) - 1
    if hist_ac[p] == 0:
        if s == "AC":
            hist_ac[p] = 1
            ac += 1
            wa += hist_wa[p]
        else:
            hist_wa[p] += 1
print(ac, wa)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
l = max(N, M)
WA, AC = [0] * l, [False] * l
wa, ac = 0, 0
for i in range(M):
    inp = input().split()
    P, S = int(inp[0]), inp[1]
    if not AC[P] and S == "AC":
        AC[P] = True
        ac += 1
        wa += WA[P]
    elif S == "WA":
        WA[P] += 1
print(ac, wa)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
WA, AC = [0] * M, [False] * M
wa, ac = 0, 0
for i in range(M):
    inp = input().split()
    P, S = int(inp[0]), inp[1]
    if S == "AC":
        AC[P] = True
        ac += 1
        wa += WA[P]
    elif S == "WA":
        WA[P] += 1
print(ac, wa)
Problem p02814 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

A = [i >> 1 for i in A]


def applied_lcm(x, y):
    g = gcd(x, y)
    x //= g
    y //= g
    if x % 2 == 0 or y % 2 == 0:
        return 0
    n = x * y * g
    if n >> 10 ** 9:
        return 0

    return n


p = reduce(applied_lcm, A)
if p == 0:
    ans = 0
else:
    ans = (M // p) - (M // (p + p))
print(ans)

Buggy submission (verdict: Runtime Error):
import math


def f(x):
    res = 0
    while x % 2 == 0:
        x /= 2
        res += 1
    return res


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


N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]


# a -> a'
for i in range(N):
    A[i] = A[i] // 2

# a' -> a''
t = f(A[0])
for i in range(N):
    if f(A[i]) != t:
        print(0)
        exit()
    A[i] >>= t  # A[i] /= 2^t
M >>= t

L = 1
for i in range(N):
    L = lcm(L, A[i])
    if L > M:
        print(0)
        exit()

M /= L
ans = math.ceil(M / 2)
print(ans)

Buggy submission (verdict: Runtime Error):
def ans(s, set_arr):
    if len(set_arr) == 1:
        return s.intersection(set_arr[0])
    return ans(s, set_arr[1:])


N, M = [int(i) for i in input().split()]
A = list(set([int(i) for i in input().split()]))
set_list = list()
for a in A:
    s = set()
    a_max = M // a
    for i in range(1, a_max):
        x = int(a * (i + 0.5))
        s.add(a * (i + 0.5))
    set_list.append(s)
print(len(ans(set_list[0], set_list[1:])))
Problem p02823 (python)

Fixed submission:
def is_even(num):
    return num % 2 == 0


N, A, B = [int(i) for i in input().split()]
#  N, A, B = [5, 2, 4]
#  N, A, B = [5, 2, 3]
#  N, A, B = [10, 2, 3]
#  N, A, B = [10, 7, 8]
#  N, A, B = [5, 2, 5]
#  N, A, B = [10, 2, 8]
#  N, A, B = [2, 1, 2]
#  N, A, B = [2, 1, 1]
is_even_a = is_even(A)
is_even_b = is_even(B)
if (is_even_a == True and is_even_b == True) or (
    is_even_a == False and is_even_b == False
):
    print((B - A) // 2)
else:
    print(min(A - 1, N - B) + 1 + ((B - A - 1) // 2))

Buggy submission (verdict: Runtime Error):
a = A - 1
b = N - B
if a == b:
    print(a)
else:
    ans = (a if a < b else b) + 1
    print(ans)
Problem p02837 (python)

Fixed submission:
def judge(bit, n, v):
    # i 人目の証言を検証する
    for i in range(n):
        # 1人目が「不親切」だったら証言はすべて無視
        if not (bit & (1 << i)):
            continue

        for x, y in v[i]:
            # y == 1 なのに「不親切」だったらダメ
            if y == 1 and not (bit & (1 << x)):
                return False

            # y == 0 なのに「正直者」だったらダメ
            if y == 0 and (bit & (1 << x)):
                return False
    return True


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

ans = 0
for bit in range(1 << n):
    if not judge(bit, n, v):
        continue

    # bit に含まれる人数を数える
    cnt = 0
    for i in range(n):
        if bit & (1 << i):
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
def judge(bit, n, v):
    # i 人目の証言を検証する
    for i in range(n):
        # 1人目が「不親切」だったら証言はすべて無視
        if not (bit & (1 << i)):
            continue

        x, y = v[i]
        # y == 1 なのに「不親切」だったらダメ
        if y == 1 and not (bit & (1 << x)):
            return False

        # y == 0 なのに「正直者」だったらダメ
        if y == 0 and (bit & (1 << x)):
            return False
    return True


n = int(input())
v = []
for i in range(n):
    for j in range(int(input())):
        x, y = [int(i) for i in input().split()]
        x -= 1
        v.append((x, y))

ans = 0
for bit in range(1 << n):
    if not judge(bit, n, v):
        continue

    # bit に含まれる人数を数える
    cnt = 0
    for i in range(n):
        if bit & (1 << i):
            cnt += 1
    ans = max(ans, cnt)
print(ans)