Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
	if S[i] == '?':
		c = -1
	else:
		c = int(S[i])

	for j in range(10):
		if c != -1 and c != j:
			continue
		for k in range(13):
			dp[i+1][(k*10+j)%13] = (dp[i+1][(k*10+j)%13] + dp[i][k]) % mod

# print(dp)
print(dp[len(S)][5])


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
	if S[i] == '?':
		c = -1
	else:
		c = int(S[i])

	for j in range(10):
		if c != -1 and c != j:
			continue
		for k in range(13):
			dp[i+1][(k*10+j)%13] = (dp[i+1][(k*10+j)%13] + dp[i][k]) % mod

# print(dp)
print(dp[len(S)][5])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from itertools import product


def read():
    N = int(input().strip())
    XYP = []
    for i in range(N):
        x, y, p = map(int, input().strip().split())
        XYP.append((x, y, p))
    return N, XYP


def solve(N, XYP, INF=10**18):
    ans = [INF for i in range(N+1)]
    vcost = [[0 for j in range(2**N)] for i in range(N)]
    hcost = [[0 for j in range(2**N)] for i in range(N)]

    # check 2**N pairs
    for intptn in range(2**N):
        for i, (xi, yi, pi) in enumerate(XYP):
            v = abs(xi)
            h = abs(yi)
            for j, (xj, yj, pj) in enumerate(XYP):
                if (intptn >> j) & 1 == 1:
                    v = min(v, abs(xj-xi))
                    h = min(h, abs(yj-yi))
            vcost[i][intptn] += v * pi
            hcost[i][intptn] += h * pi

    # check 3**N pairs
    for ptn in product(range(3), repeat=N):
        # split into two 2**N pairs
        intvptn = sum([1<<(N-i-1) for i in range(N) if ptn[i]==1])
        inthptn = sum([1<<(N-i-1) for i in range(N) if ptn[i]==2])
        s = 0
        for i in range(N):
            s += min(vcost[i][intvptn], hcost[i][inthptn])
        u = sum([t>0 for t in ptn])
        ans[u] = min(ans[u], s)

    for u in range(N+1):
        print(ans[u])


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)


### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    XYP = np.empty((N, 3), dtype=np.int32)
    for i in range(N):
        XYP[i] = np.fromstring(input().strip(), sep=" ")
    return N, XYP


@njit
def solve(N, XYP, INF=10**18):
    ans = np.full(N+1, INF, dtype=np.int64)
    vcost = np.zeros((2**N, N), dtype=np.int32)
    hcost = np.zeros((2**N, N), dtype=np.int32)

    # check 2**N pairs
    for intptn in range(2**N):
        for i in range(N):
            xi, yi, pi = XYP[i]
            v = abs(xi)
            h = abs(yi)
            for j in range(N):
                xj, yj, pj = XYP[j]
                if (intptn >> j) & 1 == 1:
                    v = min(v, abs(xj-xi))
                    h = min(h, abs(yj-yi))
            vcost[intptn, i] += v
            hcost[intptn, i] += h

    # check 3**N pairs
    for intptn in range(3**N):
        # split into two 2**N pairs
        p, intvptn, inthptn = intptn, 0, 0
        u = 0
        for i in range(N):
            if p % 3 == 1:
                intvptn += 1 << (N-i-1)
                u += 1
            elif p % 3 == 2:
                inthptn += 1 << (N-i-1)
                u += 1
            p //= 3
        s = 0
        for i in range(N):
            s += min(vcost[intvptn, i], hcost[inthptn, i]) * XYP[i, 2]
        ans[u] = min(ans[u], s)
    
    return ans


if __name__ == '__main__':
    inputs = read()
    ans = solve(*inputs)
    for a in ans:
        print(a)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for  _ in range(M)]#リストの表記が違う
BC.sort(key=lambda x: -x[1])#リバースと-1の違い

for b,c in BC:
    A.extend([c]*b)
    if len(A)>N**2:
        break
A.sort(reverse=True)
print(sum(A[:N]))

### FIXED CODE ###

N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key = lambda x: -x[1])

for B, C in BC:
  A.extend([C]*B)
  if len(A) > N*2:
    break
A.sort(reverse = True)
print(sum(A[:N]))
### BUGGY CODE ###

import itertools

n = int(input())
s = input() 
pin = set()
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      pin.add(s[i]+s[j]+s[k])
  
print(len(pin))

### FIXED CODE ###

n = int(input())
s = input()

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)
### BUGGY CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

nums = [0]*(maxA+2)
A.sort()
sA = list(set(A))
cnt = 0 
ans = defaultdict(int)
for a in sA:
    # print('nums', nums)
    new = False
    if nums[a]==0:
        # print(a)
        cnt += 1
        ans[a] += 1
        new = True
    mlt = a
    nums[a] += 1
    while new and a + mlt < maxA+2:
        a += mlt
        # print(' a:', a)
        nums[a] += 1

for an in ans.keys():
    if A.count(an)>1:
        cnt -= 1
print(cnt)

### FIXED CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
S = set(A)

maxA = A[-1]
chk = [0] * (maxA+1)
for s in S:
    for i in range(s, maxA+1, s):
        chk[i] += 1

res = [s for s in S if chk[s] == 1 and C[s] == 1]
# print(res)
print(len(res))
### BUGGY CODE ###

N = int(input())
X = list(map(int,input().split()))
for i in range(N):
    Xi = X[i]
    X.pop(i)
    Xs = sorted(X)
    print(Xs[(N-1)//2])
    X.insert(i,Xi)

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
XL = sorted(X)
for i in range(N):
    if X[i] <= XL[N//2-1]:
        print(XL[(N+1)//2])
    else:
        print(XL[(N-1)//2])
### BUGGY CODE ###

import math
n = int(input())
a = list(map(int, input().split()))

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

p = 1000000007

k = 1
for i in range(n):
    k = lcm(k,a[i])

ans = 0
for i in range(n):
    ans += (k // a[i]) % p
    ans %= p

print(ans)


### FIXED CODE ###

import math
n = int(input())
a = list(map(int, input().split()))

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

p = 1000000007

k = 1
for i in range(n):
    k = lcm(k,a[i])

k %= p

ans = 0
for i in range(n):
    ans += k * pow(a[i],p-2,p)
    ans %= p

print(ans)
### BUGGY CODE ###

k, s = [int(i) for i in input().split()]

ans = 0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i + j + l == s:
        ans += 1
        
print(ans)

### FIXED CODE ###

k, s = [int(i) for i in input().split()]

ans = 0
for i in range(k+1):
  for j in range(k+1):
    if k >= s-i-j and s-i-j>=0:
      ans += 1
        
print(ans)
### BUGGY CODE ###

N=int(input())
a=list(map(int,input().split()))
tmp=[]
tmp=[abs(sum(a[0:i])-sum(a[i:N])) for i in range(1,N)]
print(min(tmp))

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
tmp=[]
X=sum(a)
x=0
ans=1000000000000000000
for i in range(N):
    x+=a[i]
    if i+1<N:
        ans=min(ans,abs(X-2*x))

print(ans)
### BUGGY CODE ###

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

count = 1
for i in range(1, n):
    if a[i] <= min(a[:i]):
        count += 1
print(count)

### FIXED CODE ###

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

count = 0
m = a[0]
for i in range(n):
    if a[i]  <= m:
        m = a[i]
        count += 1
print(count)
### BUGGY CODE ###

s=input()
n=len(s)

dp=[[0]*13 for i in range(n)]

if s[0]!='?':
    a=int(s[0])*10**(n-1)%13
    dp[0][a]=1
else:
    for k in range(10):
        a=k*10**(n-1)%13
        dp[0][a]=1

for i in range(1,n):
    if s[i]!='?':
        a=int(s[i])*10**(n-i-1)%13
        for j in range(13):
            dp[i][j]=dp[i-1][(j-a)%13]
    else:
        for k in range(10):
            a=k*10**(n-i-1)%13
            for j in range(13):
                dp[i][j]+=dp[i-1][(j-a)%13]
print(dp[n-1][5]%(10**9+7))

### FIXED CODE ###

s=input()
n=len(s)
p=10**9+7
 
dp=[[0]*13 for i in range(n)]
m=[0]*(n-1)+[1]
for i in range(n-1):
    m[-i-2]=m[-i-1]*10%13
 
if s[0]!='?':
    a=int(s[0])*m[0]%13
    dp[0][a]=1
else:
    for k in range(10):
        a=k*m[0]%13
        dp[0][a]=1
 
for i in range(1,n):
    if s[i]!='?':
        for j in range(13):
            dp[i][j]=dp[i-1][(j-int(s[i])*m[i])%13]%p
    else:
        for k in range(10):
            for j in range(13):
                dp[i][j]+=dp[i-1][(j-k*m[i])%13]%p
print(dp[n-1][5]%p)
### BUGGY CODE ###

n,k=map(int,input().split())
S = {}
for i in range(k):
  tmp = list(map(int,input().split()))
  lr = range(tmp[0],tmp[1]+1)
  S = set(lr).union(S)

MOD = 998244353

dp = [0]*(n+1)
dp[1] = 1
for i in range(1,n+1):
  for j in S:
    if i-j > 0:
      dp[i] += dp[i-j]%MOD
print(dp[n]%MOD)

### FIXED CODE ###

n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]

mod = 998244353

dp = [0] * (n+1)
sdp = [0] * (n+1)
dp[1] = 1
sdp[1] = 1

for i in range(n+1):
  for j in range(k):
    left = max(0, i-lr[j][1])
    right = max(0, i-lr[j][0]+1)
    
    dp[i] += sdp[right] - sdp[left]
  if i+1 <= n:
    sdp[i+1] = sdp[i]%mod + dp[i]%mod

print(dp[n]%mod)
### BUGGY CODE ###

import itertools

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

comb = itertools.combinations(range(N), 2)
ans = 0

for c in comb:
  if A[c[0]]+A[c[1]] == abs(c[0]-c[1]):
    ans += 1

print(ans)


### FIXED CODE ###

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

L={}
R={}
for i in range(1,len(A)+1):
  L[str(i+A[i-1])] = L.get(str(i+A[i-1]),0)+1
  R[str(i-A[i-1])] = R.get(str(i-A[i-1]),0)+1

ans = 0
for i in range(1,N+1):
  if str(i) in L and str(i) in R:
    ans += L[str(i)] * R[str(i)]

print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    X=0
    for j in range(1,max(A)+1):
        Y=A.count(j)
        if j!=A[i]:
            X+=Y*(Y-1)//2
        else:
            X+=(Y-1)*(Y-2)//2
    print(X)
        

        







### FIXED CODE ###

import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
s=0
def f(n):
    return n*(n-1)//2
for i in c:
    c[i]=(f(c[i]),(f(c[i]-1)))
    s+=c[i][0]
for j in A:
    print(s-c[j][0]+c[j][1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def solve():

    S = input()
    T = input()

    LS = len(S)
    LT = len(T)

    dp = [[0] * (LT + 1) for _ in range(LS + 1)]
    pre = [[None] * (LT + 1) for _ in range(LS + 1)]
    for i in range(LS):
        for j in range(LT):
            now = 0
            if S[i] == T[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
                pre[i+1][j+1] = 1
            else:
                if dp[i + 1][j] < dp[i][j + 1]:
                    dp[i + 1][j + 1] = dp[i][j + 1]
                    pre[i+1][j+1] = 2
                else:
                    dp[i + 1][j + 1] = dp[i + 1][j]
                    pre[i+1][j+1] = 3

    # print(dp)

    # for p in pre:
        # print(p)

    si = LS
    ti = LT
    ans = []

    while not ((si == 0) and (ti == 0)):
        frm = pre[si][ti]
        if frm == 1:
            si -= 1
            ti -= 1
            ans.append(S[si])
        elif frm == 2:
            si -= 1
        elif frm == 3:
            ti -= 1
        elif frm == None:
            break

    return ans[::-1]


ans = solve()
print("".join(ans))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def solve():

    S = input()
    T = input()

    LS = len(S)
    LT = len(T)

    dp = [[0] * (LT + 1) for _ in range(LS + 1)]
    pre = [[None] * (LT + 1) for _ in range(LS + 1)]
    for i in range(LS):
        for j in range(LT):
            now = 0
            if S[i] == T[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
                pre[i+1][j+1] = 1
            else:
                if dp[i + 1][j] < dp[i][j + 1]:
                    dp[i + 1][j + 1] = dp[i][j + 1]
                    pre[i+1][j+1] = 2
                else:
                    dp[i + 1][j + 1] = dp[i + 1][j]
                    pre[i+1][j+1] = 3

    # print(dp)

    # for p in pre:
        # print(p)

    si = LS
    ti = LT
    ans = []

    while not ((si == 0) and (ti == 0)):
        frm = pre[si][ti]
        if frm == 1:
            si -= 1
            ti -= 1
            ans.append(S[si])
        elif frm == 2:
            si -= 1
        elif frm == 3:
            ti -= 1
        elif frm == None:
            break

    return ans[::-1]


ans = solve()
print("".join(ans))
### BUGGY CODE ###

def mpow(a,b,m):
    ans=1
    while b >0 :
        if b&1:
            ans = (ans*a)%m
        a=(a*a)%m
        b=b>>1

    return ans

def calcmod(X,m,N):
    mod=0
    for i in range(N+1):
        if X&(1<<i) > 0:
            mod += mpow(2,i,m)
            mod%=m
    return mod   
def popcount(m):
    return bin(m).count("1")


def findsteps(mm):
    cnt=0
    while mm !=0:
        cnt+=1
        mm=mm%popcount(mm)
    return cnt
N=int(input())
X=int(input(),2)

##we need to find X%(m-1) and X%(m+1)
m=popcount(X)
m1=m+1
m2=m-1
firstmod=calcmod(X,m1,N)
if m2 !=0:
    secondmod=calcmod(X,m2,N)
fans=[]
for i in range(N-1,-1,-1):
    if X & (1<<i) >0:
        ##the bit was set
        ##we need to find X%(m-1) - (2^i)%(m-1)
        if m2 == 0:
            ans=0
        else:
            mm=secondmod - mpow(2,i,m2)
            if mm < 0:
                mm+=m2
            mm=mm%m2
            ans=1+findsteps(mm)
    else:
        mm = firstmod + mpow(2,i,m1)
        mm=mm%m1
        ans=1+findsteps(mm)
    fans.append(ans)
        ##the bit was not set
for i in fans:
    print(i)

### FIXED CODE ###

def mpow(a,b,m):
    ans=1
    while b >0 :
        if b&1:
            ans = (ans*a)%m
        a=(a*a)%m
        b=b>>1

    return ans

def calcmod(X,m,N):
    mod=0
    X=X[::-1]
    # print(X)
    for i in range(N):
        if X[i] == '1':
        # if X & (1<<i) >0:
            mod += mpow(2,i,m)
            mod%=m
    return mod

def popcount(m):
    return bin(m).count("1")


def findsteps(mm):
    cnt=0
    while mm !=0:
        cnt+=1
        mm=mm%popcount(mm)
    return cnt
N=int(input())
x=input()
X=int(x,2)

##we need to find X%(m-1) and X%(m+1)
m=popcount(X)
m1=m+1
m2=m-1
firstmod=calcmod(x,m1,N)
if m2 !=0:
    secondmod=calcmod(x,m2,N)
fans=[0 for i in range(N)]
k=0
for i in range(N-1,-1,-1):
    if X & (1<<i) >0:
        ##the bit was set
        ##we need to find X%(m-1) - (2^i)%(m-1)
        if m2 == 0:
            ans=0
        else:
            mm=secondmod - mpow(2,i,m2)
            if mm < 0:
                mm+=m2
            mm=mm%m2
            ans=1+findsteps(mm)
    else:
        mm = firstmod + mpow(2,i,m1)
        mm=mm%m1
        ans=1+findsteps(mm)
    fans[k] = ans
    k+=1
        ##the bit was not set
for i in fans:
    print(i)
### BUGGY CODE ###

import itertools
import bisect
n=int(input())
count = 0
a=sorted(list(map(int, input().split(" "))))
for i in range(1,n-1):
  b = a[:i]
  c = a[i+1:]
  #print(a[i], b, c)
  for j, k in itertools.product(b,c):
    if a[i] + j > k:
      count += 1
print(count)

### FIXED CODE ###

n = int(input())
import bisect
a = sorted(list(map(int, input().split(" "))))
ans = 0
for i in range(1, n-1):
  b = a[:i]
  c = a[i + 1:]
  #print(b, c)
  for j in b:
    ans += bisect.bisect(c, a[i]+j-0.1)
    #print(bisect.bisect(c, a[i]+j-0.1))
print(ans)
### BUGGY CODE ###

#At coder 2020/2/9 D

# 入力
N,K= map(int, input().split())
p = list(map(int, input().split())) 
#p2 = sorted(p, reverse=True)
#print(p2)
kk=0.0

if N==K:
    kk=sum(p)
else:
    for ii in range(N-K+1):
        kk=max(kk,sum(p[ii:K+ii]))
K=float(K)
kk=float(kk)
ans=0.5*(kk+K)

print(ans)

### FIXED CODE ###

#At coder 2020/2/9 D
#import numpy as np

# 入力
N,K= map(int, input().split())
p = list(map(int, input().split())) 
#p2 = sorted(p, reverse=True)
#print(p2)
kk=[0] * (N-K+1)
#p=np.array(p)
kk[0]=sum(p[0:K])
for ii in range(1,N-K+1):
    kk[ii]=kk[ii-1]-p[ii-1]+p[K+ii-1]
kk=max(kk)
K=float(K)
kk=float(kk)
ans=0.5*(kk+K)

print(ans)
### BUGGY CODE ###

from collections import deque

def cal():
    h, w = map(int, input().split())
    q = deque()
    counts = [[True for _ in range(w+2)]]+[[True]+[False]*w+[True] for _ in range(h)]+[[True for _ in range(w+2)]]
    loc = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    for i in range(h):
        a = input()
        for j in range(w):
            if a[j] == '#':
                q.append([i+1, j+1, 0])
                counts[i+1][j+1] = True

    while q:
        x, y, z = q.popleft()
        for i, j in loc:
            x0 = x+i
            y0 = y+j
            if not counts[x0][y0]:
                counts[x0][y0] = True
                q.append([x0, y0, z+1])
    print(z)

cal()


### FIXED CODE ###

from collections import deque

def cal():
    h, w = map(int, input().split())
    q = deque()
    counts = [[True for _ in range(w+2)]]+[[True]+[False]*w+[True] for _ in range(h)]+[[True for _ in range(w+2)]]
    for i in range(h):
        a = input()
        for j in range(w):
            if a[j] == '#':
                q.append([i+1, j+1, 0])
                counts[i+1][j+1] = True

    while q:
        x, y, z = q.popleft()    
        if not counts[x+1][y]:
            counts[x+1][y] = True
            q.append([x+1, y, z+1])
        if not counts[x-1][y]:
            counts[x-1][y] = True
            q.append([x-1, y, z+1])
        if not counts[x][y+1]:
            counts[x][y+1] = True
            q.append([x, y+1, z+1])
        if not counts[x][y-1]:
            counts[x][y-1] = True
            q.append([x, y-1, z+1])
    print(z)
    

cal()
### BUGGY CODE ###

#coding:utf-8
import math
from functools import reduce

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

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

def main():
    n = int(input())
    sumv = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                sumv += gcd(i, j, k)
                #print(i,j,k)
    print(sumv)
  
if __name__ == '__main__':
    main()

### FIXED CODE ###

#coding:utf-8
import math
from functools import reduce

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

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

def main():
    n = int(input())
    sumv = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                sumv += gcd(i, j, k)
                #print(i,j,k)
    print(sumv)
  
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from functools import reduce
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    l = list(A)
    l.pop(i)
    answer = 0
    for j in range(len(l)-1):
        answer += abs(l[j]-l[j+1])
    else:
        answer += abs(l[0])+abs(l[-1])
    print(answer)
    


### FIXED CODE ###

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

sum = 0
for j in range(len(A)-1):
    sum += abs(A[j]-A[j+1])
for i in range(N):
    print(sum - abs(A[i] - A[i+1]) - abs(A[i+1] - A[i+2]) + abs(A[i] - A[i+2]))
### BUGGY CODE ###

from collections import deque
INFTY = 1000
N = int(input())
S = [list(map(int,list(input()))) for _ in range(N)]
G = {i:[] for i in range(1,N+1)}
for i in range(N-1):
    for j in range(i+1,N):
        if S[i][j]==1:
            G[i+1].append(j+1)
            G[j+1].append(i+1)
heap = deque([(1,0)])
hist = [0 for _ in range(N+1)]
col = [-1 for _ in range(N+1)]
hist[1] = 1
col[1] = 0
flag = 0
while heap:
    x,c = heap.popleft()
    for y in G[x]:
        if hist[y]==0:
            col[y] = 1-c
            heap.append((y,1-c))
            hist[y]=1
        else:
            if col[y]!=1-c:
                flag = 1
                break
    if flag==1:break
if flag==1:
    print(-1)
else:
    dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
    for i in range(N):
        for j in range(N):
            if i==j:
                dist[i+1][j+1]=0
            if S[i][j]==1:
                dist[i+1][j+1]=1
    for k in range(1,N+1):
        for i in range(1,N+1):
            for j in range(1,N+1):
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
    dmax = 0
    for i in range(1,N+1):
        for j in range(1,N+1):
            dmax = max(dmax,dist[i][j])
    print(dmax+1)

### FIXED CODE ###

from collections import deque
N = int(input())
G = {i:[] for i in range(N)}
for i in range(N):
    S = input().strip()
    for j in range(N):
        if S[j]=="1":
            G[i].append(j)
cmax = 0
for i in range(N):
    hist = [0 for _ in range(N)]
    hist[i]=1
    num = 0
    heap = deque([(i,1)])
    ind = 0
    while ind==0 and num<N:
        cur = heap.popleft()
        num += 1
        y = cur[0]
        g = cur[1]
        cmax = max(cmax,g)
        for x in G[y]:
            if hist[x]==0:
                heap.append((x,g+1))
                hist[x]=g+1
            elif hist[x]==hist[y]:
                ind = 1
                break
    if ind==1:break
if ind==1:
    print(-1)
else:
    print(cmax)