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

Fixed submission:
import collections
import math

def combination(n, m):
    return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))

N = int(input())
S = []
for n in range(N):
    S.append(str(input()))

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

c = collections.Counter(Y)
C = c.most_common()
len_C = len(C)

for n in range(len_C):
    if C[n][1] > 1:
        ans += combination(C[n][1], 2)
    else:
        pass

print(round(ans))

Buggy submission (verdict: Runtime Error):
import collections
import math

def combination(n, m):
    return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))

N = int(input())
S = []
for n in range(N):
    S.append(str(input()))

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

c = collections.Counter(Y)
C = c.most_common()

len_C = len(C)

for n in range(len_C):
    if C[n][1] == 1:
        del C[n]
    else:
        pass

len_C = len(C)

for m in range(len_C):
    ans += combination(C[m][1], 2)

print(round(ans))

Buggy submission (verdict: Runtime Error):
import collections
import math

def combination(n, m):
    return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))

N = int(input())
S = []
for n in range(N):
    S.append(str(input()))

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

print(Y)

c = collections.Counter(Y)
C = c.most_common()

len_C = len(C)
print(C)
print(len_C)

for n in range(len_C):
    if C[n][1] == 1:
        del C[n]
    else:
        pass
print(C)

len_C = len(C)

for m in range(len_C):
    ans += combination(C[m][1], 2)

print(round(ans))
Problem p02953 (python)

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

ans = 'Yes'

for i in reversed(range(0, N-1)):
    if H[i] > H[i+1] + 1:
        ans = 'No'
    elif H[i] == H[i+1] + 1:
        H[i] -= 1

print(ans)

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

ans = 'Yes'

for i in reversed(range(0, N-1)):
    if H[i] > H[i+1] + 1:
        ans += 1
    elif H[i] == H[i+1] + 1:
        H[i] -= 1

if ans == 0:
    print('Yes')
else:
    print('No')

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

ans = 0

for i in reversed(range(0, N-1)):
    if H[i] > h[i+1] + 1:
        ans += 1
    elif H[i] == h[i+1] + 1:
        h[i] -= 1

if ans == 0:
    print('Yes')
else:
    print('No')
Problem p02969 (python)

Fixed submission:
r = int(input())
print(3 * r **2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)
Problem p02995 (python)

Fixed submission:
import fractions

A, B, C, D = map(int, input().split())

# B以下でC, Dで割り切れるものの個数
b_c = B // C
b_d = B // D

# B以下でCでもDでも割り切れるものの個数
b_c_d = B // ((C*D)//fractions.gcd(C,D))

# A未満でC, Dで割り切れるものの個数
a_c = (A-1) // C
a_d = (A-1) // D

# A未満でCでもDでも割り切れるものの個数
a_c_d = (A-1) // ((C*D)//fractions.gcd(C,D))


count = b_c + b_d - b_c_d - (a_c + a_d - a_c_d)

ans = B-A+1 - count
print(int(ans))

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

X = list(range(A, B+1))

c = A % C
d = A % D

if c == 0:
    I = list(range(A, B+1, C))
else:
    I = list(range(A+C-c, B+1, C))
if d == 0:
    J = list(range(A, B+1, D))
else:
    J = list(range(A+D-d, B+1, D))

ans_list = list(set(X) - set(I) - set(J))
print(len(ans_list))

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())

X = list(range(A, B+1))

c = A % C
d = A % D

if c == 0:
    I = list(range(A, B+1, C))
else:
    I = list(range(A+C-c, B+1, C))
if d == 0:
    J = list(range(A, B+1, D))
else:
    J = list(range(A+D-d, B+1, D))

ans_list = list(set(X) - set(I) - set(J))
print(ans_list)
Problem p03086 (python)

Fixed submission:
S = str(input())

count = 0
X =[]
for n in range(len(S)):
    if n != len(S) -1:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
        else:
            X.append(count)
            count = 0
    else:
        if S[n] == 'A' or S[n] == 'T' or S[n] == 'C' or S[n] == 'G':
            count += 1
            X.append(count)
        else:
            X.append(count)
print(int(max(X)))

Buggy submission (verdict: Runtime Error):
S = str(input())
count = 0
X =[]
for s in S:
    if s == 'A' or s == 'T' or s == 'C' or s == 'G':
        count += 1
    else:
        X.append(count)
        count = 0
print(int(max(X)))

Buggy submission (verdict: Runtime Error):
S = str(input())
count = 0
X =[]
for s in S:
    if s == 'A' or s == 'T' or s == 'C' or s == 'G':
        count += 1
    else:
        X.append(count)
print(int(max(X)))
Problem p03109 (python)

Fixed submission:
S = str(input())
S = S.replace('/','')

if int(S) <= 20190430:
    print('Heisei')
else:
    print('TBD')

Buggy submission (verdict: Runtime Error):
N = int(input())
X = []
U = []
count = 0

for _ in range(N):
    x, u = map(str, input().split())
    X.append(float(x))
    if u == 'JPY':
        U.append(1)
    else:
        U.append(380000)

for n in range(N):
    count += X[n] * U[n]

print(count)
Problem p03282 (python)

Fixed submission:
S = str(input())
K = int(input())
L = []

count = 0
for s in S:
    count += 1
    if s != '1':
        t = s
        break
    t = s

if K < count:
    print(1)
else:
    print(int(t))

Buggy submission (verdict: Runtime Error):
S = str(input())
K = int(input())
L = []

count = 0
for s in S:
    count += 1
    if s != '1':
        t = s
        break

if K < count:
    print(1)
else:
    print(int(t))
Problem p03284 (python)

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

if N % K == 0:
    ans = 0
else:
    ans = 1

print(ans)

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

def get_ans(x):
    if x == 0:
        return ['0']
    d = []
    i = 0
    div = 1
    while x != 0:
        if x % (div*2) == 0:
            d.append('0')
        else:
            d.append('1')
            x -= div
        i += 1
        div = div * (-2)
    return d

a = get_ans(N)
b = list(reversed(a))
ans = ''.join(b)
print(ans)
Problem p03309 (python)

Fixed submission:
import bisect

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

for n in range(N):
    A_n.append(A[n]-(n+1))

A_n = sorted(A_n, reverse=True)

can_f = A_n[N//2]
ans_f = 0
for n in range(N):
    ans_f += abs(A_n[n]-can_f)


if N > 1:
    ans_s = 0
    can_s = A_n[N//2+1]
    for n in range(N):
        ans_s += abs(A_n[n]-can_s)
else:
    ans_s = 10**10

ans = min(ans_f, ans_s)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect

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

for n in range(N):
    A_n.append(A[n]-n)

A_n = sorted(A_n, reverse=True)

can_f = A_n[N//2]
can_s = A_n[N//2 + 1]

ans_f = 0
ans_s = 0

for n in range(N):
    ans_f += abs(A_n[n]-can_f)

for n in range(N):
    ans_s += abs(A_n[n]-can_s)

ans = min(ans_f, ans_s)
print(ans)
Problem p03448 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            if 500*i + 100*j + 50*k == x:
                count += 1

print(count)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
 
ans = 0
 
for x in range(n+1):
    y = str(x)
    z = list(map(int, y))
    sum_x = sum(z)
    
    if a <= sum_x and sum_x <= b:
        ans += x

print(ans)
Problem p03469 (python)

Fixed submission:
s = str(input())
ans = '2018' + s[4:]
print(ans)

Buggy submission (verdict: Runtime Error):
n, h = map(int, input().split())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


throw_a = max(A)
B = sorted(B, reverse=True)
count = 0

while h > 0:
    count += 1
    if throw_a > max(B):
        h -= a
    else:
        h -= max(B)
        B.remove(max(B))

print(count)
Problem p03471 (python)

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

ans = '-1 -1 -1'

for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        if i*10000 + j*5000 + k*1000 == y:
            ans = str(i) + ' ' + str(j) + ' ' + str(k)

print(ans)

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

ans = '-1 -1 -1'

for i in range(n+1):
    for j in range(n-i+1):
        k = n - i + j:
        if i*10000 + j*5000 + k*1000 == y:
            ans = str(i) + ' ' + str(j) + ' ' + str(k)

print(ans)
Problem p03472 (python)

Fixed submission:
n, h = map(int, input().split())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

B = sorted(B, reverse=True)
a_max = max(A)

bigger = [x for x in B if x >= a_max]
throw_b = len(bigger)

throw = 0
check = 0

while check == 0:
    if throw >= throw_b:
        break
    h = h - B[throw]
    throw += 1
    if h <= 0:
        break

if h <= 0:
    ans = throw
else:
    ans = throw + -(-h//max(A))

print(ans)

Buggy submission (verdict: Runtime Error):
n, h = map(int, input().split())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


throw_a = max(A)
B = sorted(B, reverse=True)
count = 0

while h > 0:
    count += 1
    if throw_a > max(B):
        h -= a
    else:
        h -= max(B)
        B.remove(max(B))

print(count)
Problem p03473 (python)

Fixed submission:
m = int(input())

ans = 48- m
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
C, S, F = [], [], []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(n-1):
    #i=0, 1つめの駅発を対象とする
    time = S[i] + C[i]
    for j in range(i+1, n-1):
        if time <= S[j]:
            time = S[j] + C[j]
        else:
            #timeに到着して次の出発までにかかる時間は、
            time += (time - S[j])% F[j] + C[j]
    print(time)
print(0)
Problem p03486 (python)

Fixed submission:
s = str(input())
t = str(input())
S = []
T = []

for i in s:
    S.append(i)
for j in t:
    T.append(j)

S = sorted(S)
T = sorted(T, reverse=True)

S = ''.join(S)
T = ''.join(T)

if S < T:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Buggy submission (verdict: Runtime Error):
s = str(input())
t = str(input())
S = []
T = []

for i in s:
    S.append(ord(i))
for j in t:
    T.append(ord(j))

S = sorted(S)
T = sorted(T, reverse=True)

ans = 'Yes'

for n in range(len(S)):
    if S[n] < T[n]:
        break
    elif S[n] == T[n]:
        continue
    else:
        ans = 'No'

if S == T:
    ans = 'No'

print(ans)
Problem p03544 (python)

Fixed submission:
n = int(input())
Num = [2,1]

for i in range(2,87):
    new = Num[i-1] + Num[i-2]
    Num.append(new)

ans = Num[n]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
Num = [2,1]

for i in range(2,86):
    new = Num[i-1] + Num[i-2]
    Num.append(new)

ans = Num[n]
print(ans)
Problem p03547 (python)

Fixed submission:
x, y = map(str, input().split())
if ord(x) < ord(y):
    ans = '<'
elif ord(x) > ord(y):
    ans = '>'
else:
    ans = '='

print(ans)

Buggy submission (verdict: Runtime Error):
x, y = map(str, input())
if ord(x) < ord(y):
    ans = '<'
elif ord(x) > ord(y):
    ans = '>'
else:
    ans = '='

print(ans)
Problem p03573 (python)

Fixed submission:
a, b, c = map(int, input().split())

if a == b:
    ans = c
elif a == c:
    ans = b
else:
    ans = a

print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a == b:
    ans = c
elif a == c:
    ans = b:
else:
    ans = a

print(ans)
Problem p03626 (python)

Fixed submission:
n = int(input())
S = []
for _ in range(2):
    s = str(input())
    S.append(s)

count = 0
mod = (10**9) +7

if S[0][0] == S[1][0]:
    ans = 3
else:
    ans = 6

while count < n-1:
    if (S[0][count] == S[1][count]) and (S[0][count+1] == S[1][count+1]):
        ans = ans * 2
        ans = ans % mod
        count += 1
    elif S[0][count] == S[1][count]:
        ans = ans * 2
        ans = ans % mod
        count += 1
    elif count >= n-2:
        break
    elif S[0][count+2] == S[1][count+2]:
        ans = ans
        count += 2
    else:
        ans = ans * 3
        ans = ans % mod
        count += 2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
S = []
for _ in range(2):
    s = str(input())
    S.append(s)

count = 0
mod = (10**9) +7

if S[0][0] == S[1][0]:
    ans = 3
else:
    ans = 6

while count < n-1:
    if (S[0][count] == S[1][count]) and (S[0][count+1] == S[1][count+1]):
        ans = ans * 2
        ans = ans % mod
        count += 1
    elif S[0][count] == S[1][count]:
        ans = ans * 2
        ans = ans % mod
        count += 1
    elif S[0][count+2] == S[1][count+2]:
        ans = ans
        count += 2
    else:
        ans = ans * 3
        ans = ans % mod
        count += 2
print(ans)
Problem p03695 (python)

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

Colors = [0 for _ in range(8)]
any_color = 0

for a in A:
    if a <= 399:
        Colors[0] = 1
    elif a <= 799:
        Colors[1] = 1
    elif a <= 1199:
        Colors[2] = 1
    elif a <= 1599:
        Colors[3] = 1
    elif a <= 1999:
        Colors[4] = 1
    elif a <= 2399:
        Colors[5] = 1
    elif a <= 2799:
        Colors[6] = 1
    elif a <= 3199:
        Colors[7] = 1
    else:
        any_color += 1

ans_min = max(sum(Colors), 1)
ans_max = sum(Colors) + any_color

print(str(ans_min) + ' ' + str(ans_max))

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

Colors = [0 for _ in range(7)]
any_color = 0

for a in A:
    if a <= 399:
        Colors[0] = 1
    elif a <= 799:
        Colors[1] = 1
    elif a <= 1199:
        Colors[2] = 1
    elif a <= 1599:
        Colors[3] = 1
    elif a <= 1999:
        Colors[4] = 1
    elif a <= 2399:
        Colors[5] = 1
    elif a <= 2799:
        Colors[6] = 1
    elif a <= 3199:
        Colors[7] = 1
    else:
        any_color += 1

ans_min = sum(Colors)
ans_max = sum(Colors) + any_color

print(str(ans_min) + ' ' + str(ans_max))
Problem p03853 (python)

Fixed submission:
h, w = map(int, input().split())

C = [str(input()) for _ in range(h)]

for i in range(h):
    print(C[i])
    print(C[i])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())

C = [str(input()) for _ in range(w)]

for i in range(h):
    print(C[i])
    print(C[i])
Problem p02921 (python)

Fixed submission:
S = input()
T = input()
c = 0
for i in range(3):
    if S[i] == T[i]:
        c += 1
print(c)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = [int(x) for x in input().split()]
x = 1
ans = 1

for i in range(1,len(H)):
    if H[i] <= H[i-1]:
        x += 1
        if x > ans:
            ans = x
    else:
        x = 1
print(ans)
Problem p02947 (python)

Fixed submission:
def nCr(n, r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
    return numerator // denominator

N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]

dic={}
for i in s:
	if i in dic:
		dic[i] +=1
	else:
		dic[i] = 1

result = 0
for j in dic.values():
	if j > 1:
		result += nCr(j,2)

print(result)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))

Buggy submission (verdict: Runtime Error):
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))
Problem p03006 (python)

Fixed submission:
from collections import Counter
N = int(input())
if N == 1:
	print(1)
else:
	l = [[int(arr) for arr in input().split()] for i in range(N)]
	l.sort()
	tmp = [[b - a for a, b in zip(l[j],l[k])] for j in range(N-1) for k in range(j+1,N)]
	c = Counter(map(tuple, tmp))
	m = c.most_common(1)[0][1]
	print(N-m)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
l = [[int(arr) for arr in input().split()] for i in range(N)]
l.sort()
tmp = [[b - a for a, b in zip(l[j],l[k])] for j in range(N-1) for k in range(j+1,N)]
c = Counter(map(tuple, tmp))
m = c.most_common(1)[0][1]
print(N-m)
Problem p02717 (python)

Fixed submission:
a,b,c = map(int,input().split())
a,b = b,a
a,c = c,a
print(a,b,c)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
vote_result_list = sorted(list(map(int,input().split())))[::-1]
border = sum(vote_result_list)/(4*M)
print("Yes" if vote_result_list[M-1] >= border else "No")
Problem p02718 (python)

Fixed submission:
N, M = map(int, input().split())
vote_result_list = sorted(list(map(int,input().split())))[::-1]
border = sum(vote_result_list)/(4*M)
print("Yes" if vote_result_list[M-1] >= border else "No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
vote_result_list = sorted(list(map(int,input().split())))[::-1]
border = sum(vote_result_list)//(4*M)
print("Yes" if vote_result_list[M] >= border else "No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
vote_result_list = sorted(list(map(int,input().split())))[::-1]
border = sum(vote_result_list)//(4*M)
print("Yes" if vote_result_list[M] >= border else "No")
Problem p02718 (python)

Fixed submission:
n, m = map(int, input().split())
rank = list(map(int, input().split()))
rank.sort(reverse=True)
cnt = 0

for r in rank:
  if r >= (sum(rank)/(4*m)):
    cnt += 1
    if cnt >= m:
      break

if cnt >= m :
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
rank = list(map(int, input().split()))
rank.sort(reverse=True)
cnt = 0

for r in rank:
  if r >= (sum(rank)//(4*m)):
    cnt += 1
    if cnt = m:
      break

if cnt >= m :
  print('Yes')
else:
  print('No')
Problem p02780 (python)

Fixed submission:
n, k = map(int, input().split())
p_lis = list(map(int, input().split()))
def calc_ex(num):
    return (num - 1) * 0.5 + 1
cur_num = 0
for i in range(k):
    cur_num += p_lis[i]
max_nums = cur_num
max_nums_i = 0
for i in range(len(p_lis) - k):
    cur_num -= p_lis[i]
    cur_num += p_lis[i + k]
    if max_nums < cur_num:
        max_nums = cur_num
        max_nums_i = i + 1
res = 0
for i in range(max_nums_i, max_nums_i + k):
    res += calc_ex(p_lis[i])
print(res)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000)
n, k = map(int, input().split())
p_lis = list(map(int, input().split()))
def calc_ex(num):
    return (num - 1) * 0.5 + 1
cur_num = 0
for i in range(k):
    cur_num += p_lis[i]
max_nums = cur_num
max_nums_i = i
for i in range(len(p_lis) - k):
    cur_num -= p_lis[i]
    cur_num += p_lis[i + k]
    if max_nums < cur_num:
        max_nums = cur_num
        max_nums_i = i + 1
res = 0
for i in range(max_nums_i, max_nums_i + k):
    res += calc_ex(p_lis[i])
print(res)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p_lis = list(map(int, input().split()))
def calc_ex(num):
    return (num - 1) * 0.5 + 1
cur_num = 0
for i in range(k):
    cur_num += p_lis[i]
max_nums = cur_num
max_nums_i = i
for i in range(len(p_lis) - k):
    cur_num -= p_lis[i]
    cur_num += p_lis[i + k]
    if max_nums < cur_num:
        max_nums = cur_num
        max_nums_i = i + 1
res = 0
for i in range(max_nums_i, max_nums_i + k):
    res += calc_ex(p_lis[i])
print(res)
Problem p02803 (python)

Fixed submission:
h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(list(input()))
res = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] != '.':
            continue
        visited = [[False for _ in range(w)] for _ in range(h)]
        visited[i][j] = True
        queue = [(i, j, 0)]
        while queue:
            c_i, c_j, level = queue.pop(0)
#             visited.append((c_i, c_j))
            for n_i, n_j in ((c_i - 1, c_j), (c_i + 1, c_j), (c_i, c_j - 1), (c_i, c_j + 1)):
                if 0 <= n_i < h and 0 <= n_j < w and grid[n_i][n_j] == '.' and visited[n_i][n_j] == False:
                    queue.append((n_i, n_j, level + 1))
                    visited[n_i][n_j] = True
        res = max(res, level)
print(res)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(list(input()))
res = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] != '.':
            continue
        visited = [[False for _ in range(w)] for _ in range(h)]
        visited[h][w] = True
        queue = [(i, j, 0)]
        while queue:
            c_i, c_j, level = queue.pop(0)
#             visited.append((c_i, c_j))
            for n_i, n_j in ((c_i - 1, c_j), (c_i + 1, c_j), (c_i, c_j - 1), (c_i, c_j + 1)):
                if 0 <= n_i < h and 0 <= n_j < w and grid[n_i][n_j] == '.' and visited[n_i][n_j] == False:
                    queue.append((n_i, n_j, level + 1))
                    visited[n_i][n_j] = True
        res = max(res, level)
print(res)
Problem p02837 (python)

Fixed submission:
g = [[-1] * 15 for _ in range(15)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(m):
        a, x = map(int, input().split())
        a -= 1
        g[i][a] = x
def count_ones_by_minus(num):
    count = 0
    while num:
        num &= num -1
        count += 1
    return count
ans = 0
for i in range(1 << n):
    d = [0] * n
    for j in range(n):
        if i >> j & 1:
            d[j] = 1
    ok = True
    for j in range(n):
        if d[j]:
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
    if ok:
        ans = max(ans, count_ones_by_minus(i))
print(ans)

Buggy submission (verdict: Runtime Error):
g = [[-1] * 15 for _ in range(15)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(m):
        a, x = map(int, input().split())
        a -= 1
        g[i][a] = x
def count_ones_by_minus(num):
    count = 0
    while num:
        num &= num -1
        count += 1
    return count
for i in range(1 << n):
    for j in range(n):
        if i >> j & 1:
            d[j] = 1
    ok = True
    for j in range(n):
        if d[j]:
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
        if ok:
            ans = max(ans, count_ones_by_minus(i))
    print(ans)