Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n = 4
    S= ['((()))', '((((((', '))))))', '()()()']

  else:
    ##INPUT 
    n = input()
    #a, b = map(int, input().split())
    S = [input() for _ in range(n)]

  ## SUBMITION CODES HERE
  def CNT(A):
    tmp, Min = 0, 0
    for a in A:
        if a == '(': tmp += 1
        else: -1
        Min = min(Min, tmp)
    return (-Min, tmp-Min)
  
  T = [CNT(s) for s in S]

  pls = []
  mis = []
  for l, r in T:
    if l <= r: pls.append((l, r))
    else: mis.append((l, r))

  pls.sort(key=lambda a: a[0])
  mis.sort(key=lambda a: a[1], reverse=True)
  total = pls + mis

  levl = 0
  for l, r in total:
    levl -= l
    if levl < 0:
        print('No')
        exit()
    levl += r

  print('Yes' if levl == 0 else 'No')
    
main()

Fixed submission:
def CNT(A):
    tmp, Min = 0, 0
    for a in A:
        if a == '(': tmp += 1
        else: tmp -= 1
        Min = min(Min, tmp)
    return (-Min, tmp-Min)

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

pls = []
mis = []
for l, r in T:
    if l <= r: pls.append((l, r))
    else: mis.append((l, r))

pls.sort(key=lambda a: a[0])
mis.sort(key=lambda a: a[1], reverse=True)
totl= pls + mis

levl = 0
for l, r in totl:
    levl -= l
    if levl < 0:
        print('No')
        exit()
    levl += r

print('Yes' if levl==0 else 'No')
Buggy python submission (verdict: Runtime Error):
x = int(input())
for a in range(101. -101, -1):
  for b in range(-101, 101, 1):
    if x==a**5-b**5:
      print(a, b)
      exit() 

Fixed submission:
x = int(input())
for a in range(200, -200, -1):
  for b in range(-200, 200, 1):
    if x==a**5-b**5:
      print(a, b)
      exit()

Buggy python submission (verdict: Runtime Error):
import math
x = int(input())
y = int(math.pow(x, 1/5))
x - (y)**5 = z
print(x, y)

Fixed submission:
x = int(input())
for a in range(200, -200, -1):
  for b in range(-200, 200, 1):
    if x==a**5-b**5:
      print(a, b)
      exit()
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

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

dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
dp[0][0] = 0

hq = []
for i in range(n):
    heappush(hq, (-A[i], i))

for i in range(n):
    x, pi = heappop(hq)
    for l in range(i+1):
        r = i-l
        dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi-l)*A[pi])
        dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((n-r-1)-pi)*A[pi])

ans = 0
for i in range(n+1):
    ans = max(ans, dp[n][i])
print(ans)

Fixed submission:
from heapq import heappush, heappop

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

MX = 2005
f_inf = float('inf')
dp = [[0 for _ in range(MX)] for _ in range(MX)]
dp[0][0] = 0

hq = []
for i in range(n):
    heappush(hq, (-A[i], i))

ans = 0
for i in range(n):
    x, pi = heappop(hq)
    for l in range(i+1):
        r = i-l
        dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi-l)*A[pi])
        dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((n-r-1)-pi)*A[pi])

ans = 0
for i in range(n+1):
    ans = max(ans, dp[n][i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

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

MX = 2005
f_inf = float('inf')
dp = [[0 for _ in range(MX)] for _ in range(MX)]
dp[0][0] = 0

hq = []
for i in range(n):
    heappush(hq, (-A[i], i))

ans = 0
for i in range(n):
    x, pi = heappop(hq)
    for l in range(i+1):
        r = i-l
        dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi-l)*A[pi])
        dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((n-r-1)-pi)*A[pi])

ans = 0
for i in range(n+1):
    ans = max(ans, dp[n][i])
print(ans)

Fixed submission:
from heapq import heappush, heappop

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

MX = 2005
f_inf = float('inf')
dp = [[0 for _ in range(MX)] for _ in range(MX)]
dp[0][0] = 0

hq = []
for i in range(n):
    heappush(hq, (-A[i], i))

ans = 0
for i in range(n):
    x, pi = heappop(hq)
    for l in range(i+1):
        r = i-l
        dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi-l)*A[pi])
        dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((n-r-1)-pi)*A[pi])

ans = 0
for i in range(n+1):
    ans = max(ans, dp[n][i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += math.gcd(a, math.gcd(b, c))
print(ans)

Fixed submission:
import math

k = int(input())

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = math.gcd(a, b)
        for c in range(1, k+1):
            ans += math.gcd(tmp, c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

k = int(input())
L = [(a, b, c) for a in range(1, k+1) for b in range(1, k+1) for c in range(1, k+1)]
ans = 0
for l in L: ans += gcd_list(l)
print(ans)

Fixed submission:
import math

k = int(input())

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = math.gcd(a, b)
        for c in range(1, k+1):
            ans += math.gcd(tmp, c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, b, c)

print(ans)

Fixed submission:
import math

k = int(input())

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = math.gcd(a, b)
        for c in range(1, k+1):
            ans += math.gcd(tmp, c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

if n%k == 0:
    print(0)
    exit()
    
if abs(n-k) > n:
    print(n)
    exit()

tmp = n
for i in range(1,int(n**0.5)+1):
    if abs(n-i*k) > tmp:
      break
    tmp = min(abs(n-i*k), tmp)
print(tmp)

Fixed submission:
n, k = map(int, input().split())
a = n%k
print(min(a, k-a))

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

if n%k == 0:
    print(0)
    exit()
    
if abs(n-k) > n:
    print(n)
    exit()

tmp = n
for i in range(1,int(n**0.5)+1):
    if abs(n-i*k) > tmp:
      break
    tmp = min(abs(n-i*k), tmp)
print(tmp)

Fixed submission:
n, k = map(int, input().split())
a = n%k
print(min(a, k-a))

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

if n%k == 0:
    print(0)
    exit()
    
if abs(n-k) > n:
    print(n)
    exit()

tmp = n
for i in range(1, int(n**0.5)+1):
    tmp = min(abs(n-i*k), tmp)
print(tmp)

Fixed submission:
n, k = map(int, input().split())
a = n%k
print(min(a, k-a))
Buggy python submission (verdict: Runtime Error):
import sys

def solve():
    input = lambda: sys.stdin.readline().rstrip()
    sys.setrecursionlimit(10 ** 7)
    mod = 10 ** 9 + 7
    
    def comb(n, r):
        if r > n: return 0
        return fac[n] * inv[r] * inv[n - r] % mod

    def dfs(v, Pa=-1):
        for u in to[v]:
            if u == Pa: continue
            dfs(u, v)
            size[v] += size[u]
            dp[v] *= dp[u] % mod
            dp[v] *= comb(size[v], size[u]) % mod
        size[v] += 1

    def bfs(v, Pa=-1, P_val=1, P_sz=0):
        ans[v] = P_val * dp[v] * comb(n - 1, P_sz) % mod
        for u in to[v]:
            if u == Pa: continue
            val = ans[v] * INV(dp[u] * comb(n - 1, size[u])) % mod
            bfs(u, v, val, n - size[u])

    n = int(input())
    to = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        to[a].append(b)
        to[b].append(a)

    fac = [1] * (n + 2)
    inv = [1] * (n + 2)

    for i in range(2, n + 1):
        fac[i] = fac[i - 1] * i % mod
    INV = lambda x: pow(x, mod - 2, mod)
    inv[n] = INV(fac[n])
    for i in range(n - 1, 1, -1):
        inv[i] = inv[i + 1] * (i + 1) % mod

    dp = [1] * n
    size = [0] * n
    ans = [0] * n

    dfs(0)
    bfs(0)
    print(*ans, sep='\n')

if __name__ == '__main__':
    solve()

Fixed submission:
s = input()
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

def choose2(n):
    return n*(n-1)//2

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

Cnt = [(a-1) for a in A]

tot = 0
for i in range(n):
    tot += choose2(Cnt[i])

for i in range(n):
    ans = tot
    ans -= choose2(Cnt[A[i]])
    ans += choose2(Cnt[A[i]]-1)
    print(ans)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

def choose2(n):
    return n*(n-1)//2

n = int(input())
A = list(map(int, input().split()))
A = [a-1 for a in A]
  
Cnt = [0]*n
for i in range(n):
  Cnt[A[i]] += 1
    
tot = 0
for i in range(n):
    tot += choose2(Cnt[i])

for i in range(n):
    ans = tot
    ans -= choose2(Cnt[A[i]])
    ans += choose2(Cnt[A[i]]-1)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]

flg = True
for q in Q:
    if q[0] == "1":
        flg = not flg
    else:
        F = int(q[1])
        if not flg:
            F = 3 - F
        if F == 1:
            S = q[2] + S
        if F == 2:
            S = S + q[2]

if not flg:
    S = S[::-1]
print(S)

Fixed submission:
s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

t = ''
for qi in Q:
  if int(qi[0]) == 1:
    s, t = t, s
  else:
    if int(qi[1])  == 1:
      t += qi[2]
    else:
      s += qi[2]
      
t = t[::-1]
t += s
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = int(input())
Q =[list(map(str, input().split())) for _ in range(n)]

flg = True
for q in Q:
    if q[0] == "1":
        flg = not flg
    else:
        if (q[1] == "1" and flg) or (q[1] == "2" and not flg):
            S = q[2] + S
        else:
            S = S + q[2]
if not flg:
    S = S[::-1]
print(S)

Fixed submission:
s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

t = ''
for qi in Q:
  if int(qi[0]) == 1:
    s, t = t, s
  else:
    if int(qi[1])  == 1:
      t += qi[2]
    else:
      s += qi[2]
      
t = t[::-1]
t += s
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = int(input())
Q =[list(map(str, input().split())) for _ in range(n)]

flg = True
for q in Q:
    if q[0] == "1":
        flg = not flg
    else:
        if q[1] == "1" and flg:
            S = q[2] + S
        elif q[1] == "1" and not flg:
            S = S + q[2]
        elif q[1] == "2" and flg:
            S = S + q[2]
        else:
            S = q[2] + S

if not flg:
    S = S[::-1]
print(S)

Fixed submission:
s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

t = ''
for qi in Q:
  if int(qi[0]) == 1:
    s, t = t, s
  else:
    if int(qi[1])  == 1:
      t += qi[2]
    else:
      s += qi[2]
      
t = t[::-1]
t += s
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = int(input())
Q =[list(map(str, input().split())) for _ in range(n)]

for q in Q:
    if q[0] == "1":
        S = S[::-1]
    else:
        if q[1] == "1":
            S = q[2] + S
        else:
            S = S + q[2]
print(S)

Fixed submission:
s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

t = ''
for qi in Q:
  if int(qi[0]) == 1:
    s, t = t, s
  else:
    if int(qi[1])  == 1:
      t += qi[2]
    else:
      s += qi[2]
      
t = t[::-1]
t += s
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n, p = map(int, input().split())
s = input()

if 10%p==0:
    ans = 0
    for r in range(n):
        if int(s[r])%p == 0:
            ans += r+1
    print(ans)
    exit()

d = [0]*(n+1)
ten = 1

for i in range(n-1, -1, -1):
    a = int(s[i])*ten%p
    d[i] = (d[i+1]+a)%p
    ten *= 10
    #ten %= p

cnt = [0]*p
ans = 0
for i in range(n, -1, -1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1
print(ans)

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

if 10%p==0:
    ans = 0
    for r in range(n):
        if int(s[r])%p == 0:
            ans += r+1
    print(ans)
    exit()

d = [0]*(n+1)
ten = 1

for i in range(n-1, -1, -1):
    a = int(s[i])*ten%p
    d[i] = (d[i+1]+a)%p
    ten *= 10
    ten %= p

cnt = [0]*p
ans = 0
for i in range(n, -1, -1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
math.ceil(n/2)

Fixed submission:
n = int(input())
if n % 2 == 0:
  print(n//2)
else:
  print((n//2) + 1)
Buggy python submission (verdict: Runtime Error):
211 5
31 41 59 26 53

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

if sum(A) >= h:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = [list(map(str, input().split())) for _ in range(m)]

ans = 0
pen = 0

def get_dup(seq):
    seen = []
    return [x for x in seq
            if not seen.append(x) and seen.count(x) == 0
            or not seen.append(x) and seen.count(x) == 2]

A=get_dup(A)

for a in A:
    if a[1]=='AC':
        ans += 1
    if a[1] == 'WA':
        pen += 1

print(ans, pen)

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

ac = [0]*n
wa = [0]*n

for _ in range(m):
    p, s = map(str, input().split())
    p = int(p)

    if ac[p-1]:
        continue
    else:
        if s == 'AC':
            ac[p-1] = 1
        else:
            wa[p-1] += 1

AC = 0
WA = 0
for i in range(n):
    AC += ac[i]
    if ac[i]:
        WA += wa[i]

print(AC, WA)
Buggy python submission (verdict: Time Limit Exceeded):
# エラトステネスの篩
# https://qiita.com/takayg1/items/3769ab4cc62a231f4259

def eratosthenes_sieve(n):
    is_prime = [True]*(n + 1)
    is_prime[0] = is_prime[1] = False
    for p in range(2, n + 1):
        if is_prime[p]:
            for q in range(2*p, n + 1, p):
                is_prime[q] = False
    return is_prime

MAX_N=(10**6)
Primes = eratosthenes_sieve(MAX_N)

x = int(input())
while True:
    if Primes[x]:
        print(x)
        exit()

Fixed submission:
x = int(input())

def is_prim(n):
    if n == 1: return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0: return False
    return True

for i in range(x, 20**5+1):
    if is_prim(i):
        print(i)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())


def factorial_cor(n):
    fact = 1
    for integer in range(1, n + 1, 2):
        fact *= integer
    return fact

def factorization(n):
    arr = []
    temp = n
    count = 0
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            if i == 5:
                count += 1
    return count

print(factorization(factorial_cor(n)))

Fixed submission:
n = int(input())

def g1(n, p):
    if n == 0:
        return 0
    return n//p + g1(n//p, p)

def g2(n, p):
    if n%2 == 1:
        return g1(n,p) - g2(n-1, p)
    res = g1(n//2, p)
    if p == 2:
        res += n//2
    return res
        
ans = min(g2(n,2), g2(n,5))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007

ans = 0
for i in range(60):
    cont = 0
    for j in range(n):
        if (a[j] >> i & 1):
            cont += 1
    now = cont * (n-cont) % mod
    for j in range(i):
        now  = now * 2 % mod
    ans += now
    ans %= mod
print(ans)

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

ans = 0
for i in range(60):
    cont = 0
    for j in range(n):
        if (a[j] >> i & 1):
            cont += 1
    now = cont * (n-cont) % mod
    for j in range(i):
        now  = now * 2 % mod
    ans += now
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

for A in range(1, 10):
    for B in range(1, 10):
        if N == A*B:
            print('Yes')
            True
            break
if False:
  print('No')

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):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors

N = int(input())
if make_divisors(N)[0] < 10 and make_divisors(N)[1] < 10:
    print('Yes')
else:
    print('No')

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):
import copy
def warshall_floyd(dist):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],
                              dist[i][k] + dist[k][j])
    return dist

n, m, l = map(int, input().split()) #N:頂点数　M:辺の数 L:容量
dist = [[float("inf") for i in range(n)] for j in range(n)]
dist2 = copy.deepcopy(dist) 
for i in range(n):
    dist[i][i] = 0

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

warshall_floyd(dist)


for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            dist2[i][j] = 1

warshall_floyd(dist2)
q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    ans = dist2[s-1][t-1]-1
    if dist2[s-1][t-1] == float("inf"):
        ans = -1
    print(ans)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B)

if (B*2) >= A:
    print(0)
else:
    print(A-(B*2))

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

sum_num = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum_num += d_list[i] * d_list[j]

print(sum_num)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B)

if (B*2) >= A:
    print(0)
else:
    print(A-(B*2))

Buggy python submission (verdict: Runtime Error):
N = int(input())
d_list = list(map(int, input().split()))
sum_num = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum_num += d_list[i] * d_list[j]

print(sum_num)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B)

if (B*2) >= A:
    print(0)
else:
    print(A-(B*2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input().split()
count = 1
for i in range(N-1):
    j = i+1
    if S[i] != S[j]:
        count += 1
print(count)

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

checklist = []

for i in range(N-1):
    j = i+1
    if S[i] != S[j]:
        checklist.append(S[i])
print(len(checklist)+1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input().split()

count = 0
for i in range(N-1):
    j = i+1
    if S[i] != S[j]:
        count += 1
print(count+1)

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

checklist = []

for i in range(N-1):
    j = i+1
    if S[i] != S[j]:
        checklist.append(S[i])
print(len(checklist)+1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input().split()
count = 0
for i in range(N-1):
    j = i+1
    if S[i] != S[j]:
        count += 1
print(count+1)

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

checklist = []

for i in range(N-1):
    j = i+1
    if S[i] != S[j]:
        checklist.append(S[i])
print(len(checklist)+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def dfs(v, color):
    colors[v] = color
    for to in g[v]:
        if colors[to] == color: return
        if colors[to] == 0 and not dfs(to, -color):
            return False
    return True

def Washall_Floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d

n = int(input())
g = [[] for _ in range(n)]
f_inf =float('inf')
dist = [[f_inf]*n for _ in range(n)]
for i in range(n): dist[i][i]=0

for i in range(n):
    S = input()
    for j in range(n):
        if S[j] == '1':
            g[i].append(j)
            dist[i][j] = 1
            dist[j][i] = 1

colors = [0] * n
ans = -1
if not dfs(0, 1):
    print(ans)
else:
    Washall_Floyd(dist)
    for d in dist:
      tmp = max(d)
      ans = max(tmp, ans)
    print(ans+1)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def dfs(v, color):
    colors[v] = color
    for to in g[v]:
        if colors[to] == color: return
        if colors[to] == 0 and not dfs(to, -color):
            return False
    return True

def Washall_Floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d

n = int(input())
g = [[] for _ in range(n)]
f_inf =float('inf')
dist = [[f_inf]*n for _ in range(n)]
for i in range(n): dist[i][i]=0

for i in range(n):
    S = input()
    for j in range(n):
        if S[j] == '1':
            g[i].append(j)
            dist[i][j] = 1
            dist[j][i] = 1

colors = [0] * n
ans = -1
if not dfs(0, 1):
    print(ans)
else:
    Washall_Floyd(dist)
    for d in dist:
      tmp = max(d)
      ans = max(tmp, ans)
    print(ans+1)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000) 
N, K = input().strip().split()
h = list(map(int, input().split()))
count = 0
for i in range(N):
    if h[i] >= K:
        count += 1
print(count)


Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

Buggy python submission (verdict: Runtime Error):
N, K = input().strip().split()
h = list(map(int, input().split()))
count = 0
for i in range(N):
    if h[i] >= K:
        count += 1
print(count)

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

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

count = 0
for i in h:
    if i >= K:
        count += 1
print(count)

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

Buggy python submission (verdict: Runtime Error):
N, K = input().split()
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

Buggy python submission (verdict: Runtime Error):
N, K = input().strip().split()
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

Buggy python submission (verdict: Runtime Error):
N, K = input().strip().split()
h = list(map(int, input().split()))
count = 0

for i in h:
    if i >= K:
        count += 1
print(count)

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))