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

Fixed submission:
t, x = map(int, input().split())
print(t/x)

Buggy submission (verdict: Runtime Error):
a = int(input())
b, c = map(int, input().split())
s = input()
print(a+b+c, end = ' ')
print(s)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = [0] * (m-1)
for i in range(m-1):
    diff[i] = x[i+1] - x[i]
diff.sort(reverse = True)
print(sum(diff[(n-1):]))

Buggy submission (verdict: Runtime Error):
t, x = map(int, input(),split())
print(t/x)
Problem p02659 (python)

Fixed submission:
s=input()
a,b=s.split(' ')
a=int(a)
b=100*int(b[0])+int(b[2:])
s=a*b
print(int(s//100))

Buggy submission (verdict: Runtime Error):
a,b=map(input().split())
a=int(a)
b=int(float(b)*100)
a,b=int(a),int(b)
print(int((a*b)//100))
Problem p02835 (python)

Fixed submission:
print('win' if sum(list(map(int,input().split())))<22 else 'bust')

Buggy submission (verdict: Runtime Error):
n=int(input())
l=sorted(list(map(int,input().split())))
for i,x in enumerate(l):
  l[i]=format(x,'63b')
memo=[0]*63
for i in range(63):
  for j in range(n):
    if l[j][i]=='1':
      memo[-i-1]+=1
now=1
ans=0
mod=10**9+7
for x in memo:
  ans+=(now*x*(n-x))%mod
  now*=2
print(ans%mod)
Problem p03045 (python)

Fixed submission:
class uf():
    def __init__(self,n):
        self.n=n
        self.pa=[-1]*n
    def find(self,x):
        if self.pa[x]<0:
            return x
        else:
            self.pa[x]=self.find(self.pa[x])
            return self.pa[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
        	return True
        else:
            if self.pa[x]>self.pa[y]:
                x,y=y,x
            self.pa[x]+=self.pa[y]
            self.pa[y]=x
            return True
    def same(self,x,y):
        return self.find[x]==find.pa[y]
    def size(self,x):
        return -self.pa[self.find(x)] 
n,m=map(int,input().split())
import sys
input=sys.stdin.readline
uf=uf(n)
for _ in range(m):
    a,b,c=map(int,input().split())
    uf.unite(a-1,b-1)
memo=set([])
for i in range(n):
    memo.add(uf.find(i))
print(len(memo))

Buggy submission (verdict: Runtime Error):
class uf():
    def __init__(self,n):
        self.n=n
        self.pa=[-2]*n
    def find(self,x):
        if self.pa[x]<-1:
            return x
        else:
            self.pa[x]=self.find(self.pa[x])
            return self.pa[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
        	return True
        else:
            if self.pa[x]>self.pa[y]:
                x,y=y,x
            self.pa[x]+=y
            self.pa[y]=x
            return True
    def same(self,x,y):
        return self.find[x]==find.pa[y]
    def size(self,x):
        return -self.pa[self.find(x)] 
n,m=map(int,input().split())
import sys
input=sys.stdin.readline
uf=uf(n)
for _ in range(m):
    a,b,c=map(int,input().split())
    uf.unite(a-1,b-1)
memo=set([])
for i in range(n):
    memo.add(uf.find(i))
print(len(memo))
Problem p02862 (python)

Fixed submission:
def mod_comb(n, r, m):
  nn = n+1
  r = min(r, n-r)
  numer = 1
  denom = 1
  for i in range(1, r+1):
    numer = (numer * (nn - i)) % m
    denom = (denom * i) % m
  output = numer * pow(denom, m-2, m) % m
  return output

x, y = map(int, input().split())
if not (x <= 2*y and y <= 2*x):
  result = 0
else:
  c_up = (2*y-x)/3
  c_do = (2*x-y)/3
  if c_up.is_integer() and c_do.is_integer():
    c_up = int(c_up)
    c_do = int(c_do)
    result = mod_comb((c_up+c_do), c_up, 7+10**9)
  else:
    result = 0
print(result)

Buggy submission (verdict: Runtime Error):
import math
x, y = map(int, input().split())
c_up = (2*y-x)/3
c_do = (2*x-y)/3
if c_up.is_integer() and c_do.is_integer():
  c_up = int(c_up)
  c_do = int(c_do)
  pattern = math.factorial(c_up+c_do) / (math.factorial(c_up)*math.factorial(c_do))
  result = int(pattern % (7 + 10**9))
else:
  result = 0
print(result)
Problem p03775 (python)

Fixed submission:
import math
n = int(input())
sqrt_n = math.ceil(math.sqrt(n))

result = 100
for i in range(1, sqrt_n + 1):
  if n % i == 0:
    digit = max(len(str(i)), len(str(n // i)))
    if digit < result:
      result = digit

print(result)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
sqrt_n = math.ceil(math.sqrt(n))

list_cand = []
for i in range(1, sqrt_n):
  if n % i == 0:
    list_cand.append(max(len(str(i)), len(str(n // i))))

print(min(list_cand))
Problem p02695 (python)

Fixed submission:
N,M,Q=map(int,input().split())
que=[tuple(map(int,input().split())) for _ in range(Q)]
task=[]
sta=[[i] for i in range(1,M+1)]
while sta:
    s=sta.pop()
    if len(s)==N: task.append(s)
    else:
        for d in range(int(s[-1]),M+1):
            sta.append(s+[d])
ans=0
for s in task:
    tmp=0
    for a,b,c,d in que:
        if s[b-1]-s[a-1]==c: tmp+=d
    ans=max(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,Q=map(int,input().split())
que=[tuple(map(int,input().split())) for _ in range(Q)]
task=[]
sta=[str(i) for i in range(1,M+1)]
while sta:
    s=sta.pop()
    if len(s)==N: task.append(s)
    else:
        for d in range(int(s[-1]),M+1):
            sta.append(s+str(d))
ans=0
for s in task:
    A=[int(i) for i in s]
    tmp=0
    for a,b,c,d in que:
        if A[b-1]-A[a-1]==c: tmp+=d
    ans=max(ans,tmp)
print(ans)
Problem p02785 (python)

Fixed submission:
#ABC153-C
N,K=map(int,input().split())
H=[int(i) for i in input().split()]
H.sort(reverse=True)
print(sum(H[K:]))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=[int(i) for i in input().split()]
H.append(0)
H.sort()
for _ in range(K):
  H.pop()
print(sum(H))
Problem p02970 (python)

Fixed submission:
nd = [int(i) for i in input().split()]
n = nd[0]
d = nd[1]
i = 0
while True:
    if n <= (2*d+1)*i:
        flag = i
        break
    else:
        i = i + 1
        
print(flag)

Buggy submission (verdict: Runtime Error):
nd = [int(i) for i in input().split()]
n = nd[0]
d = nd[1]
for i in range(n):
    if n <= (2*d+1)*i:
        D = i
        break
print(D)
Problem p02682 (python)

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

s = 0
s += min(a, d)
if min(a, d) == d:
  print(s)
elif min(a+b, d) == d:
  print(a)
else:
  d -= a + b
  print(a-min(c, d))

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

s = 0
s += min(a, d)
if min(a, d) == d:
  print(s)
elif min(a+b, d) == d
  print(a)
else:
  d -= a + b
  print(a-min(c, d))
Problem p03012 (python)

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


border = N // 2
w1 = sum(w[:border])
w2 = sum(w[border:])

sub = w1 - w2
direction = None
if sub > 0:
  # w1が大きい
  direction = -1
  border -= 1
elif sub < 0:
  # w2が大きい
  direction = 1
else:
  # 両者等しい
  print('0')
  exit()

prev_sub = 0
while(True):
  prev_sub = sub
  w1 += direction * w[border]
  w2 += -direction * w[border]
  border += direction

  sub = w1 - w2
  if abs(sub) >= abs(prev_sub):
    print(abs(prev_sub))
    exit()

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


border = N // 2
w1 = sum(w[:border])
w2 = sum(w[border:])

sub = w1 - w2
direction = None
if sub > 0:
  # w1が大きい
  direction = -1
elif sub < 0:
  # w2が大きい
  direction = 1
else:
  # 両者等しい
  print('0')
  return

prev_sub = 0
while(True):
  prev_sub = sub
  w1 += direction * w[border]
  w2 += -direction * w[border]
  border += direction

  sub = w1 - w2
  if abs(sub) >= abs(prev_sub):
    print(abs(prev_sub))
    exit()

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


border = N // 2
w1 = sum(w[:border])
w2 = sum(w[border:])

sub = w1 - w2
direction = None
if sub < 0:
  # w1が大きい
  direction = -1
elif sub > 0:
  # w2が大きい
  direction = 1
else:
  # 両者等しい
  print('0')
  return

prev_sub = 0
while(True):
  prev_sub = sub
  w1 += direction * w[border]
  w2 += -direction * w[border]
  border += direction

  sub = w1 - w2
  if abs(sub) >= abs(prev_sub):
    print(abs(sub))
    return
Problem p02627 (python)

Fixed submission:
a = input()
if a == a.upper():
  print('A')
else:
  print('a')

Buggy submission (verdict: Runtime Error):
a = input()
if a = a.upper():
  print('A')
else:
  print('a')
Problem p02711 (python)

Fixed submission:
import sys
A = 1
N = str(input())
for i in N:
  if int(i) == 7:
    print("Yes")
    exit()
  else:
    A = 0
    
if A == 0:
  print("No")

Buggy submission (verdict: Runtime Error):
N = str(input())
if N in 7:
  print("Yes")
else:
  print("No")
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumA, sumB = [0], [0]
sa, sb = 0, 0
for a in A:
    sa += a
    sumA.append(sa)
for b in B:
    sb += b
    sumB.append(sb)


n_max = 0
nb_max = M
for na in range(0, N+1):
    for nb in range(nb_max, -1, -1):
        k = sumA[na] + sumB[nb]
        if k <= K:
            n = na + nb
            n_max = max(n_max, n)
            nb_max = nb
            break
print(n_max)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(300000)

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))


def calc(k, n):
    if k > K:
        return n - 1
    else:
        if len(A) and len(B):
            a = A.popleft()
            na = calc(k+a, n+1)
            A.appendleft(a)
            b = B.popleft()
            nb = calc(k+b, n+1)
            B.appendleft(b)
            return max(na, nb)
        elif len(A):
            a = A.popleft()
            na = calc(k + a, n + 1)
            A.appendleft(a)
            return na
        elif len(B):
            b = B.popleft()
            nb = calc(k + b, n + 1)
            B.appendleft(b)
            return nb
        else:
            return n


print(calc(0, 0))
Problem p03252 (python)

Fixed submission:
S = input()
T = input()

# 例abcdefg...のように文字列が1対1の矢印関係の場合は、
# どのような場合でも置き換えできる。問題は同じ文字が複数現れる場合

# S上に同じ文字sのある場所には
# T上にも同じ文字tがなくてはならない
# つまり、同じ値になっているインデックスの集合を取れば
# 全部同じになっているはず

# 文字種ごとにインデックスの集合を求める
ns = len(S)
indexS = {}
for i in range(ns):
    s = S[i]
    if s in indexS:
        indexS[s].append(i)
    else:
        indexS[s] = [i]
indexT = {}
for i in range(ns):
    t = T[i]
    if t in indexT:
        indexT[t].append(i)
    else:
        indexT[t] = [i]
# 先頭の文字から、インデックスの集合が等しいかチェック
for i in range(ns):
    s = S[i]
    t = T[i]
    i_s = len(indexS[s])
    i_t = len(indexT[t])
    if i_s != i_t:
        print("No")
        break
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
S = list(input())
T = list(input())

charmap = {}
for s, t in zip(S, T):
    if t in charmap:
        charmap[t].add(s)
        break
    else:
        charmap[t] = set(s)

# マッピングが1対1なら交換できる
result = True
for k, v in charmap.items():
    if not result:
        break
    if len(v) > 1:
        # 1対1でない場合でも全ての組で2対2,3対3,n対nになっているなら交換できる
        for c in v:
            if charmap[c] != v:
                result = False
                break

if result:
    print("Yes")
else:
    print("No")
Problem p03835 (python)

Fixed submission:
k,s = map(int,input().split())
ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        x = s - (i + j)
        if x <= k and x >= 0 : ans+=1
print (ans)

Buggy submission (verdict: Runtime Error):
k,s = map(int,input().split())
ans = 0
for i in range(k + 1):
    if i > s;break
    for j in range(k + 1):
        if i + j > s;break
        for k in range(k + 1):
            if i + j + k > s;break
            if i + j + k == s:ans+=1
print (ans)
Problem p02659 (python)

Fixed submission:
A, B = input().split()
A = int(A)
B1,B2 = B.split(".")
B = 100*int(B1)+int(B2)
print((A*B)//100)

Buggy submission (verdict: Runtime Error):
A, B = input().split()
print(int(A)*float(B*100)//100)
Problem p02925 (python)

Fixed submission:
from collections import deque
N = int(input())

def trans(x):
    return int(x)-1

A = deque()
for _ in range(N):
    A.append(deque(map(trans,input().split())))

Q = set()

def check(i):
    if len(A[i]) == 0:
        return
    j = A[i][0]
    if len(A[j]) == 0:
        return
    if A[j][0] == i:
        if i > j:
            i, j = j, i
        Q.add((i, j))

for i in range(N):
    check(i)

ans = 0
while len(Q) > 0:
    ans += 1
    Q2 = Q.copy()
    Q = set()
    for q in Q2:
        A[q[0]].popleft()
        A[q[1]].popleft()
    for q in Q2:
        check(q[0])
        check(q[1])

for i in range(N):
    if len(A[i]) > 0:
        print(-1)
        exit()

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
from collections import defaultdict
N = int(input())

def trans(x):
    return int(x)-1

A = deque()
for _ in range(N):
    A.append(deque(map(trans,input().split())))

Q = deque()

def check(i):
    if len(A[i]) == 0:
        return
    j = A[i][0]
    if len(A[j]) == 0:
        return
    if A[j][0] == i:
        if i > j:
            i, j = j, i
        Q.append([i, j])

for i in range(N):
    check(i)

ans = 0
while len(Q) > 0:
    ans += 1
    Q2 = Q.copy()
    qcheck = defaultdict(int)
    Q3 = []
    Q = deque()
    for q in Q2:
        key = str(q[0]) + "-" + str(q[1])
        if qcheck[key] == 0:
            A[q[0]].popleft()
            A[q[1]].popleft()
            qcheck[key] += 1
            Q3.append(q)
    for q in Q3:
        check(q[0])
        check(q[1])

for i in range(N):
    if len(A[i]) > 0:
        print(-1)
        exit()

print(ans)
Problem p02990 (python)

Fixed submission:
N, K = map(int,input().split())
ans = N-K+1
print(ans)
for i in range(2, K+1):
    ans = ans * (N-K+2-i) * (K+1-i) // (i - 1) // i
    print(ans % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
N, K = map(int,input().split())

for i in range(1, K+1):
    ans = comb(N - K + 1, i, exact=True) * comb(K-1, i-1, exact=True)
    ans %= 10 ** 9 + 7
    print(ans)

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

for i in range(1, K+1):
    ans = math.factorial(N - K + 1) // math.factorial(N - K + 1 - i) // math.factorial(i)
    ans *= math.factorial(K - 1) // math.factorial(K - i) // math.factorial(i - 1)
    ans %= 10 ** 9 + 7
    print(ans)
Problem p03053 (python)

Fixed submission:
def main():
    H, W = map(int,input().split())

    A = [[False for _ in range(W)] for _ in range(H)]

    Q = []
    for y in range(H):
        S = input()
        for x, s in enumerate(S):
            if s == "#":
                Q.append((y, x))
                A[y][x] = True

    ans = 0
    while Q:
        ans += 1
        NQ = []
        for y, x in Q:
            if x > 0 and A[y][x-1] == False:
                A[y][x-1] = True
                NQ.append((y,x-1))
            if x < W-1 and A[y][x+1] == False:
                A[y][x+1] = True
                NQ.append((y,x+1))
            if y > 0 and A[y-1][x] == False:
                A[y-1][x] = True
                NQ.append((y-1, x))
            if y < H-1 and A[y+1][x] == False:
                A[y+1][x] = True
                NQ.append((y+1,x))
        if NQ:
            Q = NQ
        else:
            break

    print(ans-1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int,input().split())

A = [[False for _ in range(W)] for _ in range(H)]

Q = deque()
for y in range(H):
    S = input()
    for x, a in enumerate(S):
        if a == "#":
            Q.append((y, x))
            A[y][x] = True

ans = 0
while True:
    ans += 1
    NQ = deque()
    while Q:
        y, x = Q.pop()
        if x > 0 and A[y][x-1] == False:
            A[y][x-1] = True
            NQ.append((y,x-1))
        if x < W-1 and A[y][x+1] == False:
            A[y][x+1] = True
            NQ.append((y,x+1))
        if y > 0 and A[y-1][x] == False:
            A[y-1][x] = True
            NQ.append((y-1, x))
        if y < H-1 and A[y+1][x] == False:
            A[y+1][x] = True
            NQ.append((y+1,x))
    if NQ:
        Q = NQ.copy()
    else:
        break

print(ans-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int,input().split())

A = [[False for _ in range(W)] for _ in range(H)]

Q = deque()
for y in range(H):
    S = input()
    for x, a in enumerate(S):
        if a == "#":
            Q.append((x, y))
            A[y][x] = True

ans = 0
while True:
    ans += 1
    NQ = deque()
    while Q:
        x, y = Q.pop()
        if y != 0 and A[y-1][x] == False:
            A[y-1][x] = True
            NQ.append((x,y-1))
        if y != H-1 and A[y+1][x] == False:
            A[y+1][x] = True
            NQ.append((x,y+1))
        if x != 0 and A[y][x-1] == False:
            A[y][x-1] = True
            NQ.append((x-1,y))
        if x != W-1 and A[y][x+1] == False:
            A[y][x+1] = True
            NQ.append((x+1,y))
    if NQ:
        Q = NQ.copy()
    else:
        break

print(ans-1)
Problem p03617 (python)

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

ans = 0
if N % 2 == 1:
    ans = min(4*Q,2*H,S)
ans += (N//2) * min(8*Q, 4*H, 2*S, D)

print(ans)

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

if N % 2 == 1:
    ans = min(4*Q,2*H,S)
ans += (N//2) * min(8*Q, 4*H, 2*S, D)

print(ans)
Problem p02659 (python)

Fixed submission:
from decimal import Decimal

A,B = map(str,input().split())
A = Decimal(A)
B = Decimal(B)
ans = int(A*B)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

A,B = map(str,input().split())

C = int(B*100)
print(A*C//100)
Problem p02757 (python)

Fixed submission:
import sys


N,P = map(int,input().split())
S = list(input())

A = [0]*(N)
A[-1] = int(S[-1])
A[-1] %= P
base = 10 % P
for i in reversed(range(N-1)):
    A[i] = A[i+1] + base*int(S[i])
    A[i] %= P
    base *= 10
    base %= P


ans = 0
if P==2 or P==5:
    for i in reversed(range(N)):
        if int(S[i])%P==0:
            ans += i+1
else:
    nums = {}
    for a in A:
        if not (a in nums):
            nums[a] = 1
        else:
            nums[a] += 1
    
    for n in nums.keys():
        k = nums[n]
        if n==0:
            ans += k*(k+1)//2
        else:
            ans += k*(k-1)//2
    
print(ans)

Buggy submission (verdict: Runtime Error):
import sys


N,P = map(int,input().split())
S = list(sys.stdin.readline().rstrip())

A = [0]*(N)
A[-1] = int(S[-1])
A[-1] %= P
base = 10
for i in reversed(range(N-1)):
    A[i] = A[i+1] + base*int(S[i])
    A[i] %= P
    base *= 10


ans = 0
if P==2 or P==5:
    for i in reversed(range(N)):
        if int(S[i])%P==0:
            ans += i+1
else:
    a = A[10**9]
    nums = {}
    for a in A:
        nums[a] = 0
    for a in A:
        nums[a] += 1
    
    for n in nums.keys():
        k = nums[n]
        if n==0:
            ans += k*(k+1)//2
        else:
            ans += k*(k-1)//2
    
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,P = map(int,input().split())
S = list(input())

A = [0]*(N)
A[-1] = int(S[-1])
A[-1] %= P
base = 10
for i in reversed(range(N-1)):
    A[i] = A[i+1] + base*int(S[i])
    A[i] %= P
    base *= 10


ans = 0
if P==2 or P==5:
    for i in reversed(range(N)):
        if int(S[i])%P==0:
            ans += i+1
else:
    nums = {}
    for a in A:
        nums[a] = 0
    for a in A:
        nums[a] += 1
    
    for n in nums.keys():
        k = nums[n]
        if n==0:
            ans += k*(k+1)//2
        else:
            ans += k*(k-1)//2
    
print(ans)

Buggy submission (verdict: Runtime Error):

import sys
input = sys.stdin.readline

N,P = map(int,input().split())
S = list(input())

A = [0]*(N)
A[-1] = int(S[-1])
A[-1] %= P
base = 10
for i in reversed(range(N-1)):
    A[i] = A[i+1] + base*int(S[i])
    A[i] %= P
    base *= 10


ans = 0
if P==2 or P==5:
    for i in reversed(range(N)):
        if int(S[i])%P==0:
            ans += i+1
else:
    nums = {}
    for a in A:
        nums[a] = 0
    for a in A:
        nums[a] += 1
    
    for n in nums.keys():
        k = nums[n]
        if n==0:
            ans += k*(k+1)//2
        else:
            ans += k*(k-1)//2
    
print(ans)
Problem p02793 (python)

Fixed submission:

from fractions import gcd


MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
#%%
def modinv(x,mod):
    return pow(x,mod-2,mod)

B = []
for a in A:
    b = modinv(a,MOD)
    B.append(b)

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

ans = 0

cur = 1
for a in A:
    cur =  lcm(cur,a)
for b in B:
    ans += cur*b
ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import math
gcd = math.gcd
# from fractions import gcd


MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
#%%
def modinv(x,mod):
    return pow(x,mod-2,mod)

B = []
for a in A:
    b = modinv(a,MOD)
    B.append(b)

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

ans = 0

cur = 1
for a in A:
    cur =  lcm(cur,a)
for b in B:
    ans += cur*b
ans %= MOD
print(ans)
Problem p02892 (python)

Fixed submission:

N = int(input())
S = [input() for _ in range(N)]

import sys
import copy

ans = 0
adj_list = [[]for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if int(S[i][j]):
            adj_list[i].append(j)
            adj_list[j].append(i)


for kk in range(N):
    q = []
    visited = [False] * N
    cnt = 1
    visited[kk] = True
    q.append(kk)
    VC = 1
    while VC < N:
        nextv = copy.copy(q)
        q = []
        nextv = list(set(nextv))
        #子の要素同士の連結チェック
        L = len(nextv)
        for i in range(L):
            if not(visited[nextv[i]]):
                visited[nextv[i]] = True
                VC += 1
            for j in range(i+1,L):
                if (int(S[nextv[i]][nextv[j]])):
                    print(-1)
                    sys.exit()
        
        for nv in nextv:
            for v in adj_list[nv]:
                if not(visited[v]):
                    q.append(v)
    
        cnt += 1
    
    ans = max(ans,cnt-1)
        
#
print(ans)

Buggy submission (verdict: Runtime Error):

N = int(input())
S = [input() for _ in range(N)]

import sys
import queue
import random

ans = 0
adj_list = [[]for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if int(S[i][j]):
            adj_list[i].append(j)
            adj_list[j].append(i)


for kk in range(N):
    q = []
    visited = [False] * N
    cnt = 1
    visited[kk] = True
    q.append(kk)
    VC = 1
    while VC < N:
        nextv = q.copy()
        q = []
        nextv = list(set(nextv))
        #子の要素同士の連結チェック
        L = len(nextv)
        for i in range(L):
            if not(visited[nextv[i]]):
                visited[nextv[i]] = True
                VC += 1
            for j in range(i+1,L):
                if (int(S[nextv[i]][nextv[j]])):
                    print(-1)
                    sys.exit()
        
        for nv in nextv:
            for v in adj_list[nv]:
                if not(visited[v]):
                    q.append(v)
    
        cnt += 1
    
    ans = max(ans,cnt-1)
        
#
print(ans)