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

n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a=l[i]
            b=l[j]
            c=l[k]
            if a<b+c and b<a+c and c<a+b:
              ans+=1
print(ans)

### FIXED CODE ###

from bisect import bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):#jはi未満
        m = L[i]-L[j]#上記c-bを計算
        k = bisect_right(L, m)#二分探索
        #aに相当するkは、上記の通り、mよりも大きい(つまり、右側)
        #同じものがあったら右側
        n = max(0, j-k)#j-kの区間の数は大丈夫
        ans+=n
print(ans)
### BUGGY CODE ###

n=int(input())
ans=[]
for i in range(n):
  a=int(input())
  if a in ans:
    ans.remove(a)
  else:
    ans.append(a)
print(len(ans))

### FIXED CODE ###

n=int(input())
a=[0 for _ in range(n)]
for i in range(n):
  a[i]=int(input())
a.sort()
ans,cnt=0,0
p=-1
for x in a:
  if p==x:
    cnt+=1
  else:
    p=x
    if cnt%2==1:
      ans+=1
    cnt=1
if cnt%2==1:
  ans+=1
print(ans)
### BUGGY CODE ###

A,B,Q = (int(i) for i in input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
x = [int(input()) for i in range(Q)]

def len_L(s,x):
    L= 99999999999
    for i in s:
        if i <= x:
            L = x - i
    return L

def len_R(s,x):
    for i in s:
        if i >= x:
            return i - x
    return 99999999999

for i in x:
    mini = min([2*len_L(s,i)+len_R(t,i) , len_L(s,i)+2*len_R(t,i) ,2*len_R(s,i)+len_L(t,i) , len_R(s,i)+2*len_L(t,i) , max([len_L(t,i),len_L(s,i)]) , max([len_R(t,i),len_R(s,i)])])
    print(mini)


### FIXED CODE ###

import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)
### BUGGY CODE ###

import itertools
N,M=map(int,input().split())
A,B,C,D=[0]*M,[0]*M,[],[]
for i in range(M):
    A[i],B[i]=map(int,input().split())
    if A[i]==1:
        C.append(i)
    else:
        D.append(i)

res=0
for j in C:
    for p in itertools.permutations(D,N-2):
        path=[1,B[j]]
        for i in p:
            if A[i]==path[-1]:
                if not B[i] in path:
                    path.append(B[i])
                else:
                    break
            elif B[i]==path[-1]:
                if not A[i] in path:
                    path.append(A[i])
                else:
                    break
            else:
                break
        else:
            path.sort()
            if path==list(range(1,N+1)):
                res+=1
print(res)

### FIXED CODE ###

import itertools
N,M=map(int,input().split())
edges=[]
for i in range(M):
    edges.append(list(map(int,input().split())))

res=0
for i in itertools.permutations(range(2,N+1),N-1):
    path=[1]+list(i)
    check=[sorted(path[i:i+2]) in edges for i in range(len(path)-1)]
    if not False in check:
        res+=1
print(res)
### BUGGY CODE ###

n = int(input())
l = []
count = 0
for _ in range(n):
    l.append(sorted(input()))
while len(l) > 0:
    count += l.count(l[0]) - 1
    l = l[1:]
print(count)

### FIXED CODE ###

N = int(input())
dic = {}
 
for i in range(N):
    s = list(input())
    s.sort()
    key = str(s)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1
 
ans = 0
for value in dic.values():
    ans += value*(value-1) / 2
print(int(ans))
### BUGGY CODE ###

import numpy as np

N,M = [int(i) for i in input().split(' ')]
itemList = np.array([int(i) for i in input().split(' ')])

for _ in range(M):
    itemList[np.argmax(itemList)] //= 2        

print(sum(itemList))

### FIXED CODE ###

from heapq import heappush, heappop
import math

N,M = [int(i) for i in input().split(' ')]
itemList = [int(i) for i in input().split(' ')]
heap = []

for i in itemList:
    heappush(heap, -i)

for _ in range(M):
    heappush(heap, math.ceil(heappop(heap)/2))
print(-sum(heap))
### BUGGY CODE ###

X=int(input())

for i in range(10000):
    for j in range(10000):
        j *= -1
        if X == (i**5-j**5):
            print(i, j)
            exit()


### FIXED CODE ###

X=int(input())

for i in range(-200,200):
    for j in range(-200,200):
        j *= -1
        if X == (i**5-j**5):
            print(i, j)
            exit()
### BUGGY CODE ###

a,b,c,d = map(int,input().split())
cnt = 0
for i in range(a,b+1):
    if i % c != 0 and i % d != 0:
        cnt += 1
           
print(cnt)           

### FIXED CODE ###

from fractions import gcd
A, B, C, D = map(int, input().split())
def solve(N):
    ans = N
    ans -= N//C
    ans -= N//D
    ans += N//(C*D//gcd(C, D))
    return ans
print(solve(B) - solve(A-1))
### BUGGY CODE ###

#93B
a,b,k = map(int,input().split())

for i in range(a,b+1):
	if i < k+a:
		print(i)
		continue
	if i > b-k:
		print(i)

### FIXED CODE ###

#93B
a,b,k = map(int,input().split())

if a+k <= b-k:
	for i in range(a, a+k):
		print(i)
	for i in range(b-k+1, b+1):
		print(i)
else:
	for i in range(a,b+1):
		print(i)
### BUGGY CODE ###

from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	print(sum([(lcm//x)%MOD for x in a])%MOD)

### FIXED CODE ###

from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= MOD
	ans = 0
	for x in a:
		ans += lcm * pow(x, MOD-2, MOD)
		ans %= MOD
	print(ans)
### BUGGY CODE ###

from fractions import gcd
 
def primeNum(n):
  ans = 1
  if n % 2 == 0:
    ans += 1
    while n % 2 == 0:
      n = n // 2
  for k in range(3, n+1, 2):
    if n % k == 0:
      ans += 1
      while n % k == 0:
        n = n // k
    if n == 1:
      return ans
  return ans
 
a,b = list(map(int, input().split()))
n=gcd(a,b)
print(primeNum(n))

### FIXED CODE ###

from fractions import gcd
 
def primeNum(n):
  ans = 1
  if n == 1:
    return ans
  if n % 2 == 0:
    ans += 1
    while n % 2 == 0:
      n = n // 2
  for k in range(3, int(n**0.5)+1, 2):
    if n % k == 0:
      ans += 1
      while n % k == 0:
        n = n // k
    if n == 1:
      return ans
  if n != 1:
    ans += 1
  return ans
  
a,b = list(map(int, input().split()))
n=gcd(a,b)
print(primeNum(n))
### BUGGY CODE ###

import re
s=input()
ans=0

re_abc=re.compile(r'ABC')
while(True):

    abc_num=len(re.findall(re_abc,s))
    if(abc_num==0):
        break
    else:
        ans+=abc_num
        s=re.sub(re_abc,'BCA',s)
#    print(s)

print(ans)

### FIXED CODE ###

import re
s=input()
ans=0

s=re.sub('BC', 'D', s)

re_ad=re.compile(r'[AD]+')
ad=re.findall(re_ad,s)
#print(s)
#print(ad)
for adi in ad:
    adi_a=0
    for adij in adi:
        if(adij=='A'):
            adi_a+=1
        else:
            ans+=adi_a

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

k=int(input())
if k % 2 ==0:
    print(-1)
else:
    n=7
    ans = 0
    while(True):
        ans += 1
        n %= k
        if n  == 0:
            print(ans)
            exit()
        n = 10 * n + 7


### FIXED CODE ###

k=int(input())
if k % 2 ==0:
    print(-1)
else:
    n=7
    ans = 0
    while(True):
        ans += 1
        if ans >= 10**6:
            print(-1)
            exit()
        n %= k
        if n  == 0:
            print(ans)
            exit()
        n = 10 * n + 7
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import itertools

input = sys.stdin.readline


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


h, w = MI()
Ch, Cw = MI()
Dh, Dw = MI()

S = [["#"] * (w + 4), ["#"] * (w + 4)]
for _ in range(h):
    S.append(["#", "#"] + list(ST()) + ["#", "#"])
S.append(["#"] * (w + 4))
S.append(["#"] * (w + 4))

dxy = ((0, 1), (0, -1), (1, 0), (-1, 0), (0, 0))
wxy = tuple(
    (x, y)
    for x, y in itertools.product([-2, -1, 0, 1, 2], repeat=2)
    if (x, y) not in dxy
)
dxy = ((0, 1), (0, -1), (1, 0), (-1, 0))

wq = [(Ch + 1, Cw + 1)]
cost = 0
while wq:
    q = list(set(wq))
    wq = []
    passed = []
    while q:
        qq = []
        for y, x in q:
            if y == Dh + 1 and x == Dw + 1:
                print(cost)
                exit()
            passed.append((y, x))
            S[y][x] = "#"
            for dy, dx in dxy:
                ny, nx = y + dy, x + dx
                if S[ny][nx] == "#":
                    continue
                # if ny == Dh + 1 and nx == Dw + 1:
                #     print(cost)
                #     exit()
                qq.append((ny, nx))
                # S[ny][nx] = "#"
        q = qq

    # print(cost, set(passed))
    for y, x in passed:
        for dy, dx in wxy:
            ny, nx = y + dy, x + dx
            if S[ny][nx] == "#":
                continue
            wq.append((ny, nx))

    cost += 1

print(-1)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import itertools

input = sys.stdin.readline


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


h, w = MI()
Ch, Cw = MI()
Dh, Dw = MI()

S = [["#"] * (w + 4), ["#"] * (w + 4)]
for _ in range(h):
    S.append(["#", "#"] + list(ST()) + ["#", "#"])
S.append(["#"] * (w + 4))
S.append(["#"] * (w + 4))

dxy = ((0, 1), (0, -1), (1, 0), (-1, 0), (0, 0))
wxy = tuple(
    (x, y)
    for x, y in itertools.product([-2, -1, 0, 1, 2], repeat=2)
    if (x, y) not in dxy
)
dxy = ((0, 1), (0, -1), (1, 0), (-1, 0))

wq = {(Ch + 1, Cw + 1)}
cost = 0
while wq:
    q = wq
    passed = set()
    while q:
        qq = set()
        for y, x in q:
            if y == Dh + 1 and x == Dw + 1:
                print(cost)
                exit()
            passed.add((y, x))
            S[y][x] = "#"
            for dy, dx in dxy:
                ny, nx = y + dy, x + dx
                if S[ny][nx] == "#":
                    continue
                # if ny == Dh + 1 and nx == Dw + 1:
                #     print(cost)
                #     exit()
                qq.add((ny, nx))
                # S[ny][nx] = "#"
        q = qq

    # print(cost, set(passed))
    wq = set()
    for y, x in passed:
        for dy, dx in wxy:
            ny, nx = y + dy, x + dx
            if S[ny][nx] == "#":
                continue
            wq.add((ny, nx))

    cost += 1

print(-1)
### BUGGY CODE ###

n = int(input())

ans = 1

while ans<=n:
    if ans*2>n:
        print(ans)
    else:
        ans *= 2

### FIXED CODE ###

n = int(input())

ans = 1

while ans<=n:
    if ans*2>n:
        print(ans)
        break
    else:
        ans *= 2
### BUGGY CODE ###

n=int(input())
x=list(map(int,input().split()))
for i in range(n):
    z=x.pop(i)
    y=sorted(x)
    print(y[n//2-1])
    x.insert(i,z)
    


### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
l=y[n//2-1]
r=y[n//2]
for a in x:
  print(l if a >= r else r)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from math import ceil
N,D,A = map(int,input().split())
XH = [list(map(int,input().split())) for _ in range(N)]
XH.sort(key = lambda x:x[0])
X,H = map(list, zip(*XH))

ans = 0
for i,xh in enumerate(XH):
    X = xh[0]
    H = xh[1]
    if H > 0:
        num = ceil(H/A)
        for j in range(i,N):
            if XH[j][0] <= X+2*D:
                XH[j][1] -= A*num
            else:
                break
        ans += num
print(ans)


### FIXED CODE ###

#https://atcoder.jp/contests/abc153/submissions/9750027

import sys
input = sys.stdin.readline
from math import ceil
from collections import deque
N,D,A = map(int, input().split())
XH = [list(map(int,input().split())) for _ in range(N)]
XH.sort(key = lambda x:x[0])
#X,H = map(list, zip(*XH))
q = deque()
d = 0
ans = 0

for x,h in XH:
    while q and q[0][0] < x:    #今見ている座標が既にそれまでの爆弾範囲から外れていたら
        d -= q.popleft()[1]
    h -= d
    if h > 0:
        num = ceil(h/A)
        ans += num
        q.append((x+2*D, num*A))    #(末端, そこまででの爆弾の威力)
        d += num*A
print(ans)
### BUGGY CODE ###

from numba import njit

@njit(cache=True)
def calc(N, M, A, X, Y):
    ans = 0
    for a in A:
        aa = (a // N + 1) * M + a % N + 1
        ans += X[aa]
        h = X[aa]
        if h < 0: continue
        Q = [(aa, h)]
        q = 0
        X[aa] -= 1
        Y[aa] = 0
        dd = (-1, 1, M, -M)
        while q < len(Q):
            i, h = Q[q]
            q += 1
            for d in dd:
                j = i + d
                y = Y[j]
                if X[j] >= h + y:
                    X[j] -= 1
                    Q.append((j, h + y))
    return ans

N = 1
A = [0]
M = 3
X = [-1, -1, -1, -1, 0, -1, -1, -1, -1]
Y = [0, 0, 0, 0, 1, 0, 0, 0, 0]
calc(N, M, A, X, Y)

N = int(input())
A = [int(a)-1 for a in input().split()]
M = N + 2
X = [max(min(i-1, j-1, M-2-i, M-2-j), -1) for j in range(M) for i in range(M)]
Y = [min(x, 0) + 1 for x in X]
print(calc(N, M, A, X, Y))

### FIXED CODE ###

from collections import deque
N = int(input())
A = [int(a)-1 for a in input().split()]
M = N + 2
X = [max(min(i-1, j-1, M-2-i, M-2-j), -1) for j in range(M) for i in range(M)]
Y = [min(x, 0) + 1 for x in X]

def calc(i0):
    h = X[i0]
    if h < 0: return
    Q = deque([(i0, h)])
    X[i0] -= 1
    Y[i0] = 0
    dd = (-1, 1, M, -M)
    while Q:
        i, h = deque.popleft(Q)
        for d in dd:
            j = i + d
            y = Y[j]
            if X[j] >= h + y:
                X[j] -= 1
                deque.append(Q, (j, h + y))
ans = 0
for a in A:
    aa = (a // N + 1) * M + a % N + 1
    ans += X[aa]
    calc(aa)
print(ans)
### BUGGY CODE ###

H, W = map(int,input().split())
dp = [[[0]]]
inf = [[0]*W for i in range(H)]
for i in range(H):
  x = [int(c) for c in input().split()]
  for j in range(W):
    inf[i][j] = x[j]
m = 0
for i in range(H):
  x = [int(c) for c in input().split()]
  for j in range(W):
    inf[i][j] = abs(inf[i][j]-x[j])
    m = max(inf[i][j],m)
M = m*(H+W)+10
dp = [[[0]*M for i in range(W)] for i in range(H)]
x = inf[0][0]
dp[0][0][x] = 1
for i in range(1,H):
  x = inf[i][0]
  for h in range(M):
    if dp[i-1][0][h]==1:
      dp[i][0][h+x] = 1
      dp[i][0][abs(h-x)] = 1

for j in range(1,W):
  x = inf[0][j]
  for h in range(M):
    if dp[0][j-1][h]==1:
      dp[0][j][h+x] = 1
      dp[0][j][abs(h-x)] = 1

for i in range(1,H):
  for j in range(1,W):
    x = inf[i][j]
    for h in range(M):
      if dp[i][j-1][h]==1:
        dp[i][j][h+x] = 1
        dp[i][j][abs(h-x)] = 1
      if dp[i-1][j][h]==1:
        dp[i][j][h+x] = 1
        dp[i][j][abs(h-x)] = 1
for h in range(M):
  if dp[-1][-1][h]==1:
    print(h)
    break

### FIXED CODE ###

import numpy as np
H,W = map(int,input().split())
A = [[0]*W for i in range(H)]
B = [[0]*W for i in range(H)]
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    A[i][j] = inf[j]
    
for i in range(H):
  inf = [int(c) for c in input().split()]
  for j in range(W):
    B[i][j] = inf[j]

X = (H + W) * 80
L = X + X + 1
# X点持った状態から始める
dp = [[0] * W for _ in range(H)]
d = abs(A[0][0] - B[0][0])
dp[0][0] = np.zeros(L,np.bool)
dp[0][0][X+d] = 1
for h in range(H):
    for w,(a,b) in enumerate(zip(A[h],B[h])):
        if h == w == 0:
            continue
        d = abs(a - b)
        x = np.zeros(L,np.bool)
        if h != 0:
            x[d:] |= dp[h-1][w][:L-d]
            x[:L-d] |= dp[h-1][w][d:]
        if w != 0:
            x[d:] |= dp[h][w-1][:L-d]
            x[:L-d] |= dp[h][w-1][d:]
        dp[h][w] = x

dp2 = dp[-1][-1]
can_make = np.where(dp2)[0] - X

answer = np.abs(can_make).min()
print(answer)
### BUGGY CODE ###

N, M = map(int, input().split())
A = []
for i in range(M):
    A.append(list(map(int,input().split())))
A = A[::-1]


P = [[x+1] for x in range(N)]
n = [x+1 for x in range(N)]
an = [N*(N-1)/2]


for i in range(M-1):
    Aind = A[i][0]-1
    Bind = A[i][1]-1
    if n[Aind] != n[Bind]:
        an.append(an[i]-len(P[n[Aind]-1]) * len(P[n[Bind]-1]))
        P[n[Aind]-1].extend(P[n[Bind]-1])
        for j in P[n[Bind]-1]:
            n[j-1] = n[Aind]
    else:
        an.append(an[i])
        
        
an = an[::-1]
for k in range(M):
    print(int(an[k]))

### FIXED CODE ###

N, M = map(int, input().split())
A = []
for i in range(M):
    A.append(list(map(int,input().split())))
A = A[::-1]


P = [[x+1] for x in range(N)]
n = [x+1 for x in range(N)]
an = [N*(N-1)/2]


for i in range(M-1):
    if an[i] == 0:
        an.append(0)
    else:        
        Aind = A[i][0]-1
        Bind = A[i][1]-1
        PAind = P[n[Aind]-1]
        PBind = P[n[Bind]-1]
        if n[Aind] != n[Bind]:
            if len(PAind) >= len(PBind):
                an.append(an[i]-len(PAind) * len(PBind))
                P[n[Aind]-1].extend(PBind)
                for j in PBind:
                    n[j-1] = n[Aind]
            else:
                an.append(an[i]-len(PAind) * len(PBind))
                P[n[Bind]-1].extend(PAind)
                for j in PAind:
                    n[j-1] = n[Bind]
        else:
            an.append(an[i])
            
        
an = an[::-1]
for k in range(M):
    print(int(an[k]))
### BUGGY CODE ###

s = input()
q = int(input())
rev = 0
for i in range(q):
  tmp = input().split()
  if len(tmp) == 1:
    rev += 1
  else:
    if tmp[1] == '1':
      if rev % 2 == 0:
        s = tmp[2] + s
      else:
        s = s + tmp[2]
    else:
      if rev % 2 == 0:
        s = s + tmp[2]
      else:
        s = tmp[2] + s
if rev % 2:
  print(s[::-1])
else:
  print(s)

### FIXED CODE ###

import collections

s = collections.deque(input())
q = int(input())
rev = 0
for i in range(q):
  tmp = input().split()
  if len(tmp) == 1:
    rev += 1
  else:
    if tmp[1] == '1':
      if rev % 2 == 0:
        s.appendleft(tmp[2])
      else:
        s.append(tmp[2])
    else:
      if rev % 2 == 0:
        s.append(tmp[2])
      else:
        s.appendleft(tmp[2])
if rev % 2:
  while True:
    try:
      print(s.pop(), end='')
    except IndexError:
      break
else:
  while True:
    try:
      print(s.popleft(), end='')
    except IndexError:
      break
### BUGGY CODE ###

def sieve(n):
    is_prime =[True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
        if is_prime[i]:
            for j in range(i+i,n,i):
                is_prime[j] = False
    c = [0 for i in range(n+1)]
    for i in range(3,n+1,2):
        if is_prime[i] and is_prime[(i+1)//2]:
            c[i] = 1
    for i in range(n):
        c[i+1] += c[i]
    return c

def solve(l,r,c):
    return c[r]-c[l-1]



if __name__ == '__main__':
    q = int(input())
    for i in range(q):
        l,r = map(int,input().split())
        c = sieve(100000)
        print(solve(l,r,c))

### FIXED CODE ###

def sieve(n):
    is_prime =[True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i+i,n,i):
                is_prime[j] = False
    c = [0 for i in range(n+1)]
    for i in range(3,n+1,2):
        if is_prime[i] and is_prime[(i+1)//2]:
            c[i] = 1
    for i in range(n):
        c[i+1] += c[i]
    return c

def solve(l,r,c):
    return c[r]-c[l-1]



if __name__ == '__main__':
    q = int(input())
    c = sieve(100000)
    for i in range(q):
        l,r = map(int,input().split())
        print(solve(l,r,c))
### BUGGY CODE ###

from collections import Counter
from collections import defaultdict

def solver():
    H, W, M = map(int, input().split())

    retu = Counter()
    gyo = Counter()

    ipt = defaultdict(list)

    for _ in range(M):
        a, b = map(int, input().split())
        retu[a-1] += 1
        gyo[b-1] += 1
        ipt[a-1].append(b-1)

    rm = retu.most_common()
    rmm = rm[0][1]
    gm = gyo.most_common()
    gmm = gm[0][1]

    for r in rm:
        if r[1] < rmm:
            break
        for g in gm:
            if g[1] < gmm:
                break

            if g[0] not in ipt[r[0]]:
                return rmm+gmm
    
    return rmm+gmm-1

print(solver())

### FIXED CODE ###

from collections import Counter

def solver():
    H, W, M = map(int, input().split())

    retu = Counter()
    gyo = Counter()

    ipt = [set() for _ in range(H)]

    for _ in range(M):
        a, b = map(int, input().split())
        retu[a-1] += 1
        gyo[b-1] += 1
        ipt[a-1].add(b-1)

    rm = retu.most_common()
    rmm = rm[0][1]
    gm = gyo.most_common()
    gmm = gm[0][1]

    for r in rm:
        if r[1] < rmm:
            break
        for g in gm:
            if g[1] < gmm:
                break

            if g[0] not in ipt[r[0]]:
                return rmm+gmm
    
    return rmm+gmm-1

print(solver())
### BUGGY CODE ###

import sys
from heapq import heappop, heappush, heapify
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float("inf")

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(lambda x: int(x)-1, input().split())
    g[u].append(v)
s, t = map(lambda x: int(x)-1, input().split())

g2 = [set() for _ in range(n)]
visited = [False] * n

def dfs(v):
    if visited[v]: return
    visited[v] = True
    for nv1 in g[v]:
        for nv2 in g[nv1]:
            for nv3 in g[nv2]:
                if nv3 not in g2[v]:
                    g2[v].add(nv3)
                    dfs(nv3)

for i in range(n): dfs(i)
for i in range(n):
    g2[i] = list(map(lambda x: (x, 1), list(g2[i])))

def dijkstra(graph, n, s):
    d = [INF] * n
    d[s], q = 0, []
    heappush(q, (0, s))
    while q:
        dist, v = heappop(q)
        if d[v] < dist: continue
        for nv, cost in graph[v]:
            if d[nv] > d[v] + cost:
                d[nv] = d[v] + cost
                heappush(q, (d[nv], nv))
    return d

ans = dijkstra(g2, n, s)[t]
print(-1 if ans == INF else ans)


### FIXED CODE ###

from heapq import heappop, heappush, heapify

INF = float("inf")
n, m = map(int, input().split())
idx = [[i*3 + j for j in range(3)] for i in range(n)]
g = [[] for _ in range(n*3)]
for _ in range(m):
    u, v = map(lambda x: int(x)-1, input().split())
    for i in range(3):
        g[idx[u][i]].append((idx[v][(i+1) % 3], 1))
s, t = map(lambda x: int(x)-1, input().split())

def dijkstra(graph, n, s):
    d = [INF] * n
    d[s], q = 0, []
    heappush(q, (0, s))
    while q:
        dist, v = heappop(q)
        if d[v] < dist: continue
        for nv, cost in graph[v]:
            if d[nv] > d[v] + cost:
                d[nv] = d[v] + cost
                heappush(q, (d[nv], nv))
    return d

res = dijkstra(g, n*3, idx[s][0])[idx[t][0]]
print(-1 if res == INF else res // 3)
### BUGGY CODE ###

n=int(input())
table=[[float("inf")]*n for i in range(n)]
for i in range(n):
  s=input()
  for j in range(n):
    if s[j]=="1":
      table[i][j]=1
    
def warshall_floyd(d):
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if d[i][k]+d[k][j]<d[i][j]:
          d[i][j]=d[i][k]+d[k][j]
        if d[i][j]<float("inf") and d[i][k]+d[k][j]<float("inf") and d[i][j]%2!=(d[i][k]+d[k][j])%2:
          return False
  return d

d=warshall_floyd(table)

if not d:
  print(-1)
else:
  ans=0
  for i in range(n):
    for j in range(i+1,n):
      ans=max(ans,d[i][j]+1)
  
  print(ans)

### FIXED CODE ###

n=int(input())
inf=float("inf")
table=[[inf]*n for i in range(n)]
for i in range(n):
  s=input()
  for j in range(n):
    if s[j]=="1":
      table[i][j]=1
    
def warshall_floyd(d):
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if d[i][k]!=inf and d[k][j]!=inf:
          d[i][j]=min(d[i][j],d[i][k]+d[k][j])
          if d[i][j]<float("inf") and d[i][j]%2!=(d[i][k]+d[k][j])%2:
            return False
  return d

d=warshall_floyd(table)

if not d:
  print(-1)
else:
  ans=0
  for i in range(n):
    for j in range(i+1,n):
      ans=max(ans,d[i][j]+1)
  
  print(ans)