Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
print("Yes" if len(set(map(int, input().split())) == 2 else "No")

Fixed submission:
print("Yes" if len(set(map(int, input().split()))) == 2 else "No")
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

index = 0
while s[index] == "1":
    index += 1
if k <= index:
    print('1')
else:
    print(s[index])


Fixed submission:
s = input()
k = int(input())

index = 0
while s[index] == "1" and index < len(s) - 1:
    index += 1
if k <= index:
    print('1')
else:
    print(s[index])

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

index = 0
while s[index] == "1":
    index += 1
if k <= index + 1:
    print('1')
else:
    print(s[index])


Fixed submission:
s = input()
k = int(input())

index = 0
while s[index] == "1" and index < len(s) - 1:
    index += 1
if k <= index:
    print('1')
else:
    print(s[index])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
total = 0
for i in range(A_len - K):
    total += A_count[i]
print(total)


Fixed submission:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_dict = dict()
for elem in A_list:
    if not elem in A_dict:
        A_dict[elem] = 1
    else:
        A_dict[elem] += 1
total = 0
A_dict = sorted(A_dict.items(), key=lambda x: x[1])
for i in range(len(A_dict) - K):
    total += A_dict[i][1]
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = [ A_list.count(A) for A in A_index]
A_count.sort()
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))


Fixed submission:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_dict = dict()
for elem in A_list:
    if not elem in A_dict:
        A_dict[elem] = 1
    else:
        A_dict[elem] += 1
total = 0
A_dict = sorted(A_dict.items(), key=lambda x: x[1])
for i in range(len(A_dict) - K):
    total += A_dict[i][1]
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))


Fixed submission:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_dict = dict()
for elem in A_list:
    if not elem in A_dict:
        A_dict[elem] = 1
    else:
        A_dict[elem] += 1
total = 0
A_dict = sorted(A_dict.items(), key=lambda x: x[1])
for i in range(len(A_dict) - K):
    total += A_dict[i][1]
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
array = input().split()
b_list = list()
i = 0

while i < n:
    if i % 2 == 0:
        b_list.append(array[i])
    else:
        b_list.insert(0, array[i])
    i += 1

if len(b_list) % 2 != 0:
    i = len(b_list)-1
    while i >= 0:
        print(b_list[i], end = ' ')
        i -= 1
else:
    i = 0
    while i < len(b_list):
        print(b_list[i], end = ' ')
        i += 1

Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
b = collections.deque()

for i in range(N):
    if i % 2 == 0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
    
if N % 2 == 0:
    i = N-1
    while i >= 0:
        print(b[i], end = ' ')
        i -= 1
else:
    for i in range(N):
        print(b[i], end = ' ')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
array = input().split()
b_list = list()
i = 0

while i < n:
    if i % 2 == 0:
        b_list.append(array[i])
    else:
        b_list.insert(0, array[i])
    i += 1

if len(b_list) % 2 != 0:
    i = len(b_list)-1
    while i >= 0:
        print(b_list[i], end = ' ')
        i -= 1
else:
    i = 0
    while i < len(b_list):
        print(b_list[i], end = ' ')
        i += 1

Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
b = collections.deque()

for i in range(N):
    if i % 2 == 0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
    
if N % 2 == 0:
    i = N-1
    while i >= 0:
        print(b[i], end = ' ')
        i -= 1
else:
    for i in range(N):
        print(b[i], end = ' ')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
array = input().split()
b_list = list()
i = 0

while i < n:
    b_list.append(int(array[i]))
    new_list = []
    while len(b_list) != 0:
        new_list.append(b_list.pop())
    b_list = list(new_list)
    i += 1

i = 0
while i < n:
    print(b_list[i], end = ' ')
    i += 1

Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
b = collections.deque()

for i in range(N):
    if i % 2 == 0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
    
if N % 2 == 0:
    i = N-1
    while i >= 0:
        print(b[i], end = ' ')
        i -= 1
else:
    for i in range(N):
        print(b[i], end = ' ')
Buggy python submission (verdict: Time Limit Exceeded):
nums = input().split()

N = int(nums[0])
M = int(nums[1])

sum = 0

while N > 0:
    if M >= 2:
        sum += 1
        M -= 2
        N -= 1

while M >= 4:
    sum += 1
    M -= 4

print(sum)

Fixed submission:
nums = input().split()

N = int(nums[0])
M = int(nums[1])

sum = 0

if 2*N <= M:
    sum += N
    M -= 2*N
    if M >= 4:
        sum += M // 4
else:
    sum += M // 2    

print(sum)
Buggy python submission (verdict: Runtime Error):
a,b = int(input())


if a<10 and b<10:
    print(a*b)
else:
    print(-1)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
a,b = int(input())

c = a*b

if a<10 or b<10:
    print(c = -1)
else:
    print(a*b)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
a,b = int(input())


if a<10 or b<10:
    print(-1)
else:
    print(a*b)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
a,b = int(input())


if a<=9 or b<=9:
    print(a*b)
else:
    print(-1)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
a,b = int(input())


if a<9 or b<9:
    print(a*b)
else:
    print(-1)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
a,b = int(input())


if a>9 or b>9:
    print(a*b)
else:
    print(-1)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
A,B = int(input())


c = A * B


if c > 10:
    print(-1)
else:
    print(c)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
A,B = int(input())

A = 10
B = 9

if A * B :
    print(-1)
else:
    print(A,B)

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a,b = map(int. input().split())

if a>b:
    print(a-b)
elif a<b:
    print(0)

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

if b*2 >= a:
    print(0)
else:
    print(a - b*2)

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

if a>b:
    print(a-b)
elif a<b:
    print(0)
else:
    print(0)

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

if b*2 >= a:
    print(0)
else:
    print(a - b*2)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n > 1:
  p = list(map(int, input().split()))
else:
  print(x)
  exit(0)
   
for i in range(n+1):
  if (x-i) not in p:
    print(x-i)
    break
  if (x+i) not in p:
    print(x+i)
    break

Fixed submission:
x = input().split()
print(x.index('0') + 1)
Buggy python submission (verdict: Runtime Error):
sum = int(input()) + int(input()) + int(input())

if sum >= 22:
	print("bust")
else:
	print("win")

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

if int(a+b+c) >= 22:
	print("bust")
else:
	print("win")
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

count = 0
for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z == s:
      	count +=1
          
print(count)

Fixed submission:
k,s = map(int,input().split())

count = 0
for x in range(k+1):
  for y in range(k+1):
    z = s-(x+y)
    if z >=0 and z <= k:
      #print(x,y,z)
      count += 1
          
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    o = 1
    s = input()
    q = int(input())
    for i in range(q):
        qu = input().split()
        if qu[0] == '1':
            o = int(not o)
        else:
            addo = 1 if qu[1] == '1' else 0
            if o == addo:
                s = qu[2] + s
            else:
                s += qu[2]
        # print(s, o)
    
    if o:
        print(s)
    else:
        print(''.join(reversed(s)))




if __name__ == '__main__':
    main()


Fixed submission:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
from collections import deque
inf = 10**9


def main():
    o = 1
    s = deque(input())
    q = int(input())
    for i in range(q):
        qu = input().split()
        if qu[0] == '1':
            o = int(not o)
        else:
            addo = 1 if qu[1] == '1' else 0
            if o == addo:
                s.appendleft(qu[2])
            else:
                s.append(qu[2])
        # print(s, o)
    
    if o:
        print(''.join(s))
    else:
        s.reverse()
        print(''.join(s))




if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
l=list(map(int, input().split()))
for i in range(n):
    l[i]-=(i+1)
avg=sum(l)/n
fb=math.floor(avg)
cb=math.ceil(avg)
sadf=sadc=0
for i in l:
    sadf+=abs(i-fb)
    sadc+=abs(i-cb)

sad=min(sadf, sadc)
print(sad)

Fixed submission:
n=int(input())

if n%2==0:
    print(n)
else:
    print(n*2)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy
n=int(input())
l=numpy.array(list(map(int, input().split())))
a=l.prod()
c=0
while a%2==0:
    a//=2
    c+=1
print(c)

Fixed submission:
import numpy
n=int(input())
l=list(map(int, input().split()))
c=0
for i in range(n):
    a=l[i]
    while a%2==0:
        a//=2
        c+=1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int, input().split()))
c=0
def a(n, l):
    result=False
    num=0
    for i in range(n):
        if l[i]%2==0:
            result=True
            num=i
            break
    return result, num
while True:
    b=a(n, l)
    if b[0]:
        c+=1
        l=list(map(lambda x: x*3, l))
        l[b[1]]//=6
    else:
        break
print(c)

Fixed submission:
import numpy
n=int(input())
l=list(map(int, input().split()))
c=0
for i in range(n):
    a=l[i]
    while a%2==0:
        a//=2
        c+=1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    k, s = map(int, input().split())

    c = 0
    for i in range(k+1):
        if i > s:
            break
        for j in range(k+1):
            if i + j > s:
                break
            for l in range(k + 1):
                if i + j + l > s:
                    break
                if i + j + l == s:
                    c += 1
                    # print(i, j, l)

    print(c)


if __name__ == '__main__':
    main()


Fixed submission:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    k, s = map(int, input().split())

    c = 0
    for i in range(k+1):
        if i > s:
            break
        for j in range(k+1):
            if i + j > s:
                break
            if s-i-j <= k:
                c += 1

    print(c)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque


n, m = map(int, input().split())

g = [[] for i in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

dist = [-1] * n
prev = [-1] * n
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in g[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)
        prev[w] = v

print("Yes")
for i in prev[1:]:
    print(i + 1)

Fixed submission:
from collections import deque


n, m = map(int, input().split())

g = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

dist = [-1] * n
prev = [-1] * n
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in g[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)
        prev[w] = v

print("Yes")
for i in prev[1:]:
    print(i + 1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

for i in range(len(route)):
    if route[i] == route[-1]:
        roop = route[i:-1]
        break

print(roop[(k - i) % len(roop)])

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

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:
            roop = route[i:-1]
            break

    print(roop[(k - i) % len(roop)])
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())

ans = 0
for x in range(n + 1):
    ans = max(ans, int(a / b * x) - a * int(x / b))

print(ans)

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

x = min(n, b - 1)

print(int(a * x / b) - a * int(x / b))

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())

ans = 0
for x in range(n + 1):
    ans = max(ans, int(a * x / b) - a * int(x / b))

print(ans)

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

x = min(n, b - 1)

print(int(a * x / b) - a * int(x / b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b

c = {"R", "G", "B"}

for i in range(n):
    for j in range(i + 1, n):
        if j - i + j < n:
            if {s[i], s[j], s[j - i + j]} == c:
                ans -= 1

print(ans)

Fixed submission:
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b

c = {"R", "G", "B"}

for i in range(n):
    for j in range(i + 1, n):
        if j - i + j < n:
            if {s[i], s[j], s[j - i + j]} == c:
                ans -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xl = sorted([list(map(int, input().split())) for i in range(n)])

prev_right = -float("inf")
ans = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

xl = reversed(xl)

prev_right = -float("inf")
ans_ = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans_ += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

print(n - min(ans, ans_))

Fixed submission:
from operator import itemgetter

n = int(input())
xl = []

for i in range(n):
    x, l = map(int, input().split())
    xl.append([x - l, x + l])

xl = sorted(xl, key=itemgetter(1))

ans = 0
m = -float("inf")
for left, right in xl:
    if left < m:
        ans += 1
    else:
        m = max(m, right)

print(n - ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        key = "0" * (3 - len(str(i))) + str(i)
        j = 0
        flag = True
        while True:
            if j == n:
                flag = False
                break
            if s[j] == key[0]:
                j += 1
                break
            j += 1
        if not flag:
            continue
        while True:
            if j == n:
                flag = False
                break
            if s[j] == key[1]:
                j += 1
                break
            j += 1
        if not flag:
            continue
        while True:
            if j == n:
                flag = False
                break
            if s[j] == key[2]:
                j += 1
                break
            j += 1
        if flag:
            ans += 1
    print(ans)

main()

Fixed submission:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = "0" * (3 - len(str(i))) + str(i)
    j = 0
    flag = True
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[0]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[1]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[2]:
            j += 1
            break
        j += 1
    if flag:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = "0" * (3 - len(str(i))) + str(i)
    j = 0
    flag = True
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[0]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[1]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[2]:
            j += 1
            break
        j += 1
    if flag:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = "0" * (3 - len(str(i))) + str(i)
    j = 0
    flag = True
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[0]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[1]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[2]:
            j += 1
            break
        j += 1
    if flag:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 逆元
# a^n mod を計算する
def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res

# a^{-1} mod を計算する
def modinv(a, mod):
    return modpow(a, mod - 2, mod)


x, y = map(int, input().split())

mod = 10 ** 9 + 7

if (x + y) % 3 == 0 and min(x, y) * 2 >= max(x, y):
    a = (2 * y - x) // 3
    b = (2 * x - y) // 3
    x = 1
    for i in range(2, a + b + 1):
        x = x * i % mod
    for i in range(2, a + 1):
        x = x * modinv(i, mod) % mod
    for i in range(2, b + 1):
        x = x * modinv(i, mod) % mod
    print(x)
else:
    print(0)

Fixed submission:
# 互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a, b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2] != 1:
        q = r[2] // w[2]
        r2 = w
        w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
        r = r2
        w = w2
    # [x,y]
    return [w[0], w[1]]


# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a, m):
    x = extgcd(a, m)[0]
    return (m + x % m) % m


x, y = map(int, input().split())

mod = 10 ** 9 + 7

if (x + y) % 3 == 0 and min(x, y) * 2 >= max(x, y):
    a = (2 * y - x) // 3
    b = (2 * x - y) // 3
    x = 1
    for i in range(2, a + b + 1):
        x = x * i % mod
    for i in range(2, a + 1):
        x = x * mod_inv(i, mod) % mod
    for i in range(2, b + 1):
        x = x * mod_inv(i, mod) % mod
    print(x)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

l = sorted(l)
ans = 0
for i in range(n):
    a = l[i]
    for j in range(i + 1, n):
        b = l[j]
        shita = max(a - b, b - a)
        ue = a + b
        ans += bisect.bisect_left(l, ue) - bisect.bisect_right(l, shita)
        if shita < a < ue:
            ans -= 1
        if shita < b < ue:
            ans -= 1

print(ans // 3)

Fixed submission:
import bisect

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

l = sorted(l)
ans = 0
for i in range(n):
    a = l[i]
    for j in range(i + 1, n):
        b = l[j]
        shita = max(a - b, b - a)
        ue = a + b
        ans += bisect.bisect_left(l, ue) - bisect.bisect_right(l, shita)
        if shita < a < ue:
            ans -= 1
        if shita < b < ue:
            ans -= 1

print(ans // 3)
Buggy python submission (verdict: Time Limit Exceeded):
def dfs(v, c):
    color[v] = c
    for i in range(n):
        if g[v][i] == 1:
            if color[i] == c:
                return False
            if color[i] == 0 and not dfs(i, -c):
                return False
    return True


n = int(input())
g = []
for i in range(n):
    s = list(map(int, list(input())))
    for j in range(n):
        if s[j] == 0:
            s[j] = 1000000
        if i == j:
            s[j] = 0
    g.append(s)

# 二部グラフ判定
color = [0] * n
nibu = True
for i in range(n):
    if color[i] == 0:
        if not dfs(i, 1):
            nibu = False

if nibu:
    for k in range(n):
        for i in range(n):
            for j in range(n):
                g[i][j] = min(g[i][j], g[i][k] + g[k][j])
    ans = 0
    for i in range(n):
        ans = max(ans, max(g[i]))
    print(ans + 1)
else:
    print(-1)

Fixed submission:
def dfs(v, c):
    color[v] = c
    for i in range(n):
        if g[v][i] == 1:
            if color[i] == c:
                return False
            if color[i] == 0 and not dfs(i, -c):
                return False
    return True


n = int(input())
g = []
for i in range(n):
    s = list(map(int, list(input())))
    for j in range(n):
        if s[j] == 0:
            s[j] = 1000000
        if i == j:
            s[j] = 0
    g.append(s)

# 二部グラフ判定
color = [0] * n
nibu = True
for i in range(n):
    if color[i] == 0:
        if not dfs(i, 1):
            nibu = False

if nibu:
    for k in range(n):
        for i in range(n):
            for j in range(n):
                g[i][j] = min(g[i][j], g[i][k] + g[k][j])
    ans = 0
    for i in range(n):
        ans = max(ans, max(g[i]))
    print(ans + 1)
else:
    print(-1)