Harryxun/stf_run huggingface dataset:
import copy

h, w = map(int, input().split())

grid = [[False] * (w + 2)]
for _ in range(w):
    grid.append([False] + [x == '#' for x in input()] + [False])
grid.append([False] * (w + 2))

cnt = 0
while True:
    flag = True
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            # print('#' if grid[i][j] else '.', end='')
            if grid[i][j] is False:
                flag = False
        # print()
    if flag:
        break

    new_grid = copy.deepcopy(grid)
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] is True:
                new_grid[i][j + 1] = True
                new_grid[i][j - 1] = True
                new_grid[i + 1][j] = True
                new_grid[i - 1][j] = True
    grid = new_grid
    cnt += 1

print(cnt)


### FIXED CODE ###

h, w = map(int, input().split())

grid = [[True] * (w + 2)]
for _ in range(h):
    grid.append([True] + [x == '#' for x in input()] + [True])
grid.append([True] * (w + 2))

q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if grid[i][j] is True:
            q.append((i, j))

cnt = 0
while q:
    qq = []
    for i, j in q:
        if not grid[i + 1][j]:
            grid[i + 1][j] = True
            qq.append((i + 1, j))
        if not grid[i - 1][j]:
            grid[i - 1][j] = True
            qq.append((i - 1, j))
        if not grid[i][j + 1]:
            grid[i][j + 1] = True
            qq.append((i, j + 1))
        if not grid[i][j - 1]:
            grid[i][j - 1] = True
            qq.append((i, j - 1))

    cnt += 1
    q = qq

print(cnt - 1)
x = int(input())
depo = 100
count = 0
while True:
  depo += int(depo / 100)
  count += 1
  if x == depo:
    break;
    
print(count)

### FIXED CODE ###

x = int(input())
depo = 100
count = 0
while depo < x:
  depo += int(depo / 100)
  count += 1
  
print(count)
N = int(input())
Lists = map(int,input().split())
sum = 0
for x in Lists:
  sum+=i/x
 
print(1/sum)


### FIXED CODE ###

N = int(input())
Lists = map(int,input().split())
sum = 0
for x in Lists:
  sum+=1/x
 
print(1/sum)
while True:
    n = input()
    if n == 0: break
    p = map(int, raw_input().strip().split(" "))
    j = map(int, raw_input().strip().split(" "))
    j.sort(); j.reverse();
    sum = 0; num = n;
    for m in p:
        sum += m
    for i in range(n):
        if (num-1)*(sum+j[i]) < num*sum: break
        num-=1; sum+=j[i]
    print num * sum

### FIXED CODE ###

while True:
    n = input()
    if n == 0: break
    p = map(int, raw_input().strip().split(" "))
    j = map(int, raw_input().strip().split(" "))
    j.sort(); j.reverse();
    sum = 0; num = n;
    for m in p:
        sum += m
    for i in range(n-1):
        if (num-1)*(sum+j[i]) < num*sum: break
        num-=1; sum+=j[i]
    print num * sum
a,b=map(it,input().split())
p=0
if a>=13:
  p=b
elif a<=5:
  p=0
else:
  p=b//2
print(p)

### FIXED CODE ###

a,b=map(int,input().split())
p=0
if a>=13:
  p=b
elif a<=5:
  p=0
else:
  p=b//2
print(p)
print(3 * N)

### FIXED CODE ###

print((int(input())-2) * 180)
a, b = map(int,input().split())

if 1<=a=<9,1<=b<=9:
  print(a*b)
else:
  pritn("-1")

### FIXED CODE ###

a, b = map(int,input().split())
if 1 <= a <= 9 and 1 <= b <= 9:
    print(a*b)
else:
    print(-1)
n = int(input())
str = input()
s = -(-n//2)
if str[:s] == str[s:]
    print('Yes')
else
    print('No')

### FIXED CODE ###

n = int(input())
str = input()
if n%2 == 1:
    print('No')
else:
    if str[:n//2] == str[n//2:]:
	    print('Yes')
    else:
	    print('No')
def is_reachable(edges,start,end):
  g = {}
  for f,t,w in edges:
    if f in g: g[f].append(t)
    else: g[f] = [t]
  visiting = [start]
  visited = {}
  while visiting:
    v = visiting.pop()
    if v in visited: continue
    if v == end: return True
    visited[v] = True
    for v2 in g.get(v, ()):
      if v2 in visited or v2 in visiting: continue
      visiting.append(v2)
  return False

N,M,P = map(int, input().split())

edges = []
for _ in range(M):
    a,b,c = map(int, input().split())
    edges.append((a,b,c))

neg_inf = float("-Inf")
no_answer = False

start = 1
end = N

distance = {}
for i in range(1,N+1):
  distance[i] = neg_inf
distance[start] = 0

for i in range(N-1):
    for f,t,w in edges:
        if distance[f] + w - P > distance[t]:
            distance[t] = distance[f] + w - P

for f,t,w in edges:
    if distance.get[f] + w - P > distance[t] and is_reachable(edges,t,end):
        no_answer = True
        break

if no_answer:
    print(-1)
else:
    print(max(0,distance[end]))


### FIXED CODE ###

def is_reachable(edges,start,end):
  g = {}
  for f,t,w in edges:
    if f in g: g[f].append(t)
    else: g[f] = [t]
  visiting = [start]
  visited = {}
  while visiting:
    v = visiting.pop()
    if v in visited: continue
    if v == end: return True
    visited[v] = True
    for v2 in g.get(v, ()):
      if v2 in visited or v2 in visiting: continue
      visiting.append(v2)
  return False

N,M,P = map(int, input().split())

edges = []
for _ in range(M):
    a,b,c = map(int, input().split())
    edges.append((a,b,c))

neg_inf = float("-Inf")
no_answer = False

start = 1
end = N

distance = {}
for i in range(1,N+1):
  distance[i] = neg_inf
distance[start] = 0

for i in range(N-1):
    for f,t,w in edges:
        if distance[f] + w - P > distance[t]:
            distance[t] = distance[f] + w - P

for f,t,w in edges:
    if distance[f] + w - P > distance[t] and is_reachable(edges,t,end):
        no_answer = True
        break

if no_answer:
    print(-1)
else:
    print(max(0,distance[end]))
s=input()
s.sort()
if s[0]==s[1]and s[2]==s[3]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = ''.join(sorted(input()))
if(s[0]==s[1] and s[2] == s[3] and s[1] != s[3]):
  print("Yes")
else:
  print("No")
value = input()
answer = value * value * value
print("answer")

### FIXED CODE ###

value = int(input())
print(value ** 3)
S = int(input())
l = [int(x) for x in list(str(S))]
K = int(input())
length = len(l)
flag=0
i=0
ans = 0
while flag ==0:
    if l[i] == 1:
        i = i + 1
    else:
        flag=1
        ans = l[i]
if len(S)>=K:
    ans = S[K-1]
print(ans)
        

### FIXED CODE ###

S = int(input())
K = int(input())
l = [int(x) for x in list(str(S))]
flag=0
flag2=0
i=0
j=0
ans = 0
if K<=len(l):
    while j<K and flag2 == 0:
        if l[j] == 1 or l[j]==0:
            ans = l[j]
            j = j + 1
        else:
            flag2 =1
            ans = l[j]
else:
    while flag ==0:
        if l[i] == 1 or l[i]==0:
            i = i + 1
        else:
            flag=1
            ans = l[i]
print(ans)
import itertools

N = int(input())
x = list(map(int,input().split()))
y = []
CONST = 10**9 + 7
def kaijo(n):
    if n==1:
        return n
    return n * kaijo(n-1)
N_1 = kaijo(N-1)
ans = 0
for i in range(1,N):
    y.append(i)
Y = list(itertools.permutations(y,len(y)))
del_num = []
ok_num = []
#操作のやつ
#iは何回目の操作かを指す
for i in range(1,N):
    prob = 1/(N-i)
    #順列Yの操作フェーズ
    for j in range(len(Y)):
        #存在しうる順列を探す
        for k in range(N-i):
            #N-i番目の値がN-i以下ならばok、存在しうる
            #print(k)
            #print(Y[j])
            if Y[j][k] <= (N-i):
                flag = 1
                if k == (N-i-1):
                    ok_num.append(j)
            else:
                flag = 0
                break
        if flag != 1:
            if j not in ok_num:
                del_num.append(j)
    #存在しない順列を削除していく
    for num in range(len(del_num)):
        del Y[del_num[num]]
ans_list = []
print("Y")
print(Y)
#ansを求めていく
for i in range(len(Y)):
    Y_list = []
    prob = 1
    ans = 0
    x_list = []
    for m in range(len(x)):
        x_list.append(x[m])
    for m in range(len(y)):
        Y_list.append(Y[i][m])
    #ここから
    for j in range(len(y)):
        prob *= 1/(N-(1+j))
        tmp = Y_list[j] - 1

        ans += x_list[tmp+1] - x_list[tmp]
        print("ans")
        print(ans)
        for k in range(len(y)):
            if tmp < (Y_list[k]):
                Y_list[k] = Y_list[k] - 1
        del x_list[tmp]
    ans = ans * prob
    ans_list.append(ans)

ans = 0
for i in range(len(ans_list)):
    ans += ans_list[i]
ans = ans * N_1
ans = int(ans)
ans = ans % CONST
print("fina._ans")
print(ans)

### FIXED CODE ###

MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))
x.sort()

kaijo = [1]
for i in range(1,N):
    kaijo.append(kaijo[-1]*i % MOD)

ans = 0
for i in range(N - 1):
    ans = (ans * (i+1) + (x[-1] - x[i]) * kaijo[i]) % MOD

print(ans)
n=int(input())
ans=1
for i in range 3:
  ans*=n
print(ans)

### FIXED CODE ###

n=int(input())
ans=1
for i in range(3):
  ans*=n
print(ans)
A=int(input())
B=int(input())
C=int(input())
x=int(input())
s=0
for i in range(A+1):
  if x=0: break
  else:
    for t in range(B+1):
    if x=0: break
    else 50*C>=x:
      s+=1
      x-=100
  x-=500
print(s) 

### FIXED CODE ###

A=int(input())
B=int(input())
C=int(input())
X=int(input())
s=0
for i in range(A+1):
  x=X-500*i
  if x<0: break
  for t in range(B+1):
    if x<0: break
    elif 50*C>=x:
      s+=1
      x-=100
    else: x-=100
print(s)
li = [2,3,4,5,6,7,8,9,10,11,12,1]
a,b = map(int,input().split())
if li.index(a) == li.index(b):
    print("Draw")
if li.index(a) > li.index(b):
    print("Alice")
else:
    print("Bob")

### FIXED CODE ###

li = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = map(int,input().split())
if li.index(a) == li.index(b):
    print("Draw")
elif li.index(a) > li.index(b):
    print("Alice")
else:
    print("Bob")
def ceil(a,b) :
    return (a + b - 1) // b

N , K = map(int,input().split())

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

A.sort()

maxDigit = ceil(max(K,A[-1]), 2)

ans = 0

# 前計算
maxVal = [0] * maxDigit
for i in range(maxDigit) :
    count = 0
    mask = 2**i
    for a in A :
        count += (a & mask) // mask
    count = max(N - count, count)
    if i == 0 :
        maxVal[0] = count
    else :
        maxVal[i] = count * mask + maxVal[i-1]

valK = [0] * (maxDigit + 1)
for i in range(maxDigit-1, -1, -1) :
    mask = 2**i
    maskK = K & mask
    sumK = 0
    for a in A :
        val = a & mask
        if maskK != val :
            sumK += mask
    valK[i] = sumK + valK[i+1]

for i in range(maxDigit-1, -1, -1) :  # 上からi+1桁まではKと同じ
    if not K & (2**i) > 0  :  # i桁目が0の場合
        continue

    sumXor = valK[i+1]

    # i桁目 0にする
    mask = 2**i
    for n in range(N) :
        if A[n] & mask > 0 :
            sumXor += mask

    if i > 0 :
        sumXor += maxVal[i-1]

    ans = max(ans, sumXor)

print(ans)



### FIXED CODE ###

N , K = map(int,input().split())
 
A = list(map(int,input().split()))
 
A.sort()
 
maxDigit = max(K,A[-1]).bit_length()
 
# 前計算
maxVal = [0] * maxDigit
for i in range(maxDigit) :
    count = 0
    mask = 2**i
    for a in A :
        count += (a & mask) // mask
    count = max(N - count, count)
    if i == 0 :
        maxVal[0] = count
    else :
        maxVal[i] = count * mask + maxVal[i-1]
 
valK = [0] * (maxDigit + 1)
for i in range(maxDigit-1, -1, -1) :
    mask = 2**i
    maskK = K & mask
    sumK = 0
    for a in A :
        val = a & mask
        if maskK != val :
            sumK += mask
    valK[i] = sumK + valK[i+1]
 
ans = valK[0]  # X = K
for i in range(maxDigit-1, -1, -1) :  # 上からi+1桁まではKと同じ
    if not K & (2**i) > 0  :  # i桁目が0の場合
        continue
 
    sumXor = valK[i+1]
 
    # i桁目 0にする
    mask = 2**i
    for n in range(N) :
        if A[n] & mask > 0 :
            sumXor += mask
 
    if i > 0 :
        sumXor += maxVal[i-1]
 
    ans = max(ans, sumXor)
 
print(ans)
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
cnt = 0
for i in range(s):
  p = input()
  if p[0] == "M":
    m += 1
  if p[0] == "A":
    a += 1
  if p[0] == "R":
    r += 1
  if p[0] == "C":
    c += 1
  if p[0] == "H":
    h += 1
if m > 0:
  cnt += 1
if a > 0:
  cnt += 1
if r > 0:
  cnt += 1
if c > 0:
  cnt += 1
if h > 0:
  cnt += 1
  
if cnt < 3:
  print(0)
else:
  print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*h + a*c*h + r*c*h)


### FIXED CODE ###

n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
cnt = 0
for i in range(n):
  p = input()
  if p[0] == "M":
    m += 1
  if p[0] == "A":
    a += 1
  if p[0] == "R":
    r += 1
  if p[0] == "C":
    c += 1
  if p[0] == "H":
    h += 1
if m > 0:
  cnt += 1
if a > 0:
  cnt += 1
if r > 0:
  cnt += 1
if c > 0:
  cnt += 1
if h > 0:
  cnt += 1
  
if cnt < 3:
  print(0)
else:
  print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    return gcd(b, a%b)
N = int(input())
A = map(int,input().split())
g1=[0 for i in range(N)]
g2=[0 for i in range(N)]
g1[0]=a[0]
g2[N-1]=a[N-1]
for i in range(1,N):
  g1[i]=gcd(g1[i-1],a[i])
for i in range(N-2,-1,-1):
  g2[i]=gcd(g2[i+1],a[i])
ans=1
for i in range(N-2):
  a=gcd(g1[i],g2[i+2])
  ans=max(ans,a)
ans=max(ans,g1[N-2],g2[1])
print(ans)

### FIXED CODE ###

def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    return gcd(b, a%b)
N = int(input())
a = list(map(int,input().split()))
g1=[0 for i in range(N)]
g2=[0 for i in range(N)]
g1[0]=a[0]
g2[N-1]=a[N-1]
for i in range(1,N):
  g1[i]=gcd(g1[i-1],a[i])
for i in range(N-2,-1,-1):
  g2[i]=gcd(g2[i+1],a[i])
ans=1
for i in range(N-2):
  a=gcd(g1[i],g2[i+2])
  ans=max(ans,a)
ans=max(ans,g1[N-2],g2[1])
print(ans)
print(sum([int(list(input().split())[i]) for i in range(3)]))

### FIXED CODE ###

A1, A2, A3 = map(int, input().split())
if A1+A2+A3 >= 22:
  print('bust')
else:
  print('win')
import fractions
N=int(input())
a = list(map(int, input().split()))

#------------最小公倍数---------------------
lcm = 1
for i in range(1, N):
    lmc = lcm * a[i] // fractions.lcm(lcm, a[i])
#------------------------------------------
b= []
for i in range(N):
    b.append(lcm //a[i])
ans=0

for j in b:
    ans +=lcm// b
    ans%=1000000007


print(ans)

### FIXED CODE ###

import fractions
N=int(input())
a = list(map(int, input().split()))

#------------最小公倍数---------------------
lcm = a[0]
for i in range(1, N):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
#------------------------------------------
ans=0
for j in a:
    ans += lcm // j
print(ans % 1000000007)
n = int(input())
w = {}
for _ in range(n):
    w[i] = w.get(input(), 0) + 1
ans = sorted(i for i, j in w.items() if j == max(w.values()))
for i in ans:
    print(i)


### FIXED CODE ###

n = int(input())
s = list(input() for _ in range(n))
s.sort()
now = s[0]
ans = [s[0],]
cnt = 0
m_cnt = 0

for i in range(n):
    word = s[i]
    if word == now:
        cnt +=1
        if cnt > m_cnt:
            ans = [word,]
            m_cnt = cnt
        elif cnt == m_cnt:
            ans.append(word)
    else:
        cnt = 1
        now = word
        if cnt > m_cnt:
            ans = [word,]
            m_cnt = cnt
        elif cnt == m_cnt:
            ans.append(word)

for k in sorted(ans):
    print(k)
import sys
sys.setrecursionlimit(10**7)

road_par = []
road_rank = []
rail_par = []
rail_rank = []
c1 = []
c2 = []

def init(par, rank, c, n):
    for i in range(n):
        par.append(i)
        rank.append(0)
        c.append(0)


def find(par,x):
    if par[x] == x:
        return x
    par[x] = find(par, par[x])
    return par[x]


def unite(par, rank, x, y):
    x = find(x); y = find(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    elif rank[y] < rank[x]:
        par[y] = x
    else:
        par[y] = x
        rank[x] += 1


N, K, L = map(int, input().split())
init(road_par, road_rank, c1, N)
init(rail_par, rail_rank, c2, N)

for i in range(K):
    f, t = map(int, input().split())
    unite(road_par, road_rank, f-1, t-1)

for i in range(L):
    f,t = map(int, input().split())
    unite(rail_par, rail_rank, f-1, t-1)

for i in range(N):
    c1[find(road_par, i)] += 1
    c2[find(rail_par, i)] += 1

for i in range(N):
    if c1[i] == 1:
        road_par[i] = -1
    if c2[i] == 1:
        rail_par[i] = -1

ans = [0 for i in range(N)]
for i in range(N):
    if road_par[i] != -1:
        ans[i] +=1
    if rail_par[i] != -1:
        ans[i] += 1

for i in range(N):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

road_par = []
road_rank = []
rail_par = []
rail_rank = []
c1 = []
c2 = []

def init(par, rank, c, n):
    for i in range(n):
        par.append(i)
        rank.append(0)
        c.append(0)


def find(par,x):
    if par[x] == x:
        return x
    par[x] = find(par, par[x])
    return par[x]


def unite(par, rank, x, y):
    x = find(par, x); y = find(par, y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    elif rank[y] < rank[x]:
        par[y] = x
    else:
        par[y] = x
        rank[x] += 1


N, K, L = map(int, input().split())
init(road_par, road_rank, c1, N)
init(rail_par, rail_rank, c2, N)


for i in range(K):
    f, t = map(int, input().split())
    unite(road_par, road_rank, f-1, t-1)

for i in range(L):
    f,t = map(int, input().split())
    unite(rail_par, rail_rank, f-1, t-1)

for i in range(N):
    c1[find(road_par, i)] += 1
    c2[find(rail_par, i)] += 1

ans = [0 for i in range(N)]

"""
for i in range(N):
    for j in range(N):
        if find(road_par, i) == find(road_par, j) and find(rail_par, i) == find(rail_par, j):
            ans[i] += 1
"""
from collections import defaultdict
ans = defaultdict(int)
for i in range(N):
    ans[(find(road_par, i), find(rail_par, i))] += 1

for i in range(N):
    print(ans[(find(road_par, i), find(rail_par, i))], end=' ')
print('')
N = int(input())
v = map(int,input().split())

for i in N:

    titi = max(v)
    haha = min(v)

    v.remove(titi)
    v.remove(haha)

    son = (titi + haha)/2 

    v.add(son)

res = v[0] 
print(str(res))

### FIXED CODE ###

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

v.sort()

son = v[0]

for i in range(1,len(v)):
	son = (v[i] + son)/2

print(son)
X,Y,Z,K = list(map(int,input().split()))
A = [(sorted(list(map(int,input().split())))[::-1]) for i in range(3)]

import heapq

heap = []
item = (0,(0,0,0))
heapq.heappush(heap, item)

considered_dict = set()

ret = []
max_ = A[0][0]+A[1][0]+A[2][0]
while len(considered_dict) < K:
    task  = heapq.heappop(heap)
    score,(x,y,z) =task
    ret.append(score)
    considered_dict |= {(x,y,z)}
    # assign next task
    if x+1 != X-1 and (x+1,y,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x+1]-A[1][y]-A[2][z],(x+1,y,z) ))
                       
    if y+1 != Y-1 and (x,y+1,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y+1]-A[2][z],(x,y+1,z) ))
                       
    if z+1 != Z-1 and (x,y,z+1) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y]-A[2][z+1],(x,y,z+1) ))


for i in ret:
    print(max_-i)

### FIXED CODE ###

X,Y,Z,K = list(map(int,input().split()))
A = [(sorted(list(map(int,input().split())))[::-1]) for i in range(3)]
b = sorted([i+j for i in A[0] for j in A[1]])[-K:]
for i in sorted([i+j for i in b for j in A[2]])[-K:][::-1] :
  print(i)
a, b = map(int, input().split())
if (a*b)%2 == 0:
  print 'Even'
else:
  print 'Odd'

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b)%2 == 0:
  print ('Even')
else:
  print ('Odd')
import itertools

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

Pattern=[]
for i in range(1,N+1):
    Pattern.append(i)

c1=Pattern.index(P) + 1
c2=Pattern.index(Q) + 1

print(abs(c1-c2))

### FIXED CODE ###

K, X=map(int, input().split())

if 500*K >= X:
    print("Yes")
else:
    print("No")
from collections import deque
import sys
sys.setrecursionlimit(10**7)

N=int(input())
M=N*(N-1)//2
D=[[]for i in range(M)]
F=[[]for i in range(M)]
for i in range(N):
  x=list(map(int,input().split()))
  for j in range(N-2):
    a,b,c=i+1,x[j],x[j+1]
    x1,x2=min(i+1,x[j]),max(i+1,x[j])
    y1,y2=min(i+1,x[j+1]),max(i+1,x[j+1])
    e=M-(N-x1)*(N-x1+1)//2
    f=e+(x2-x1-1)
    g=M-(N-y1)*(N-y1+1)//2
    h=g+(y2-y1-1)
    D[f].append(h)
    F[h].append(f)
P=[-1]*M
def bfs(u):
  P[u]=0
  B.append(u)
  queue=deque([u])
  while queue:
    v=queue.popleft()    
    for i in D[v]:
      if i in B:
        ans=-1
        break
      if P[v]+1>P[i]:
        P[v]+1>P[i]
        P[i]=P[v]+1
        queue.append(i)
ans=-1
for i in range(M):
  B=[]
  if len(F[i])==0:
    ans=0
    bfs(i)
  if ans==-1:
    print(-1)
    exit()

if min(P)==-1:
  print(-1)
else:
  print(max(P)+1

### FIXED CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**7)

N=int(input())
M=N*(N-1)//2
D=[[]for i in range(M)]
F=[[]for i in range(M)]
for i in range(N):
  x=list(map(int,input().split()))
  for j in range(N-2):
    a,b,c=i+1,x[j],x[j+1]
    x1,x2=min(i+1,x[j]),max(i+1,x[j])
    y1,y2=min(i+1,x[j+1]),max(i+1,x[j+1])
    e=M-(N-x1)*(N-x1+1)//2
    f=e+(x2-x1-1)
    g=M-(N-y1)*(N-y1+1)//2
    h=g+(y2-y1-1)
    D[f].append(h)
    F[h].append(f)
    
q=deque()
P=[0]*M
for i in range(M):
  if len(F[i])==0:
    q.append((i,0))

r=[]
while q:
  v1,cnt=q.popleft()
  r.append((v1,cnt))
  for v2 in D[v1]:
    P[v2]+=1
    if P[v2]==len(F[v2]):
      q.append((v2,cnt+1))

if len(r)!=M:
  print(-1)
else:
  print(r[-1][-1]+1)
S = input()
if S = 'SUN':
  print(7)
elif S = 'MON':
  print(6)
elif S = 'TUE':
  print(5)
elif S = 'WED':
  print(4)
elif S = 'THU':
  print(3)
elif S = 'FRI':
  print(2)
elif S = 'SAT':
  print(1)

### FIXED CODE ###

S = input()
if S == 'SUN':
  print(7)
elif S == 'MON':
  print(6)
elif S == 'TUE':
  print(5)
elif S == 'WED':
  print(4)
elif S == 'THU':
  print(3)
elif S == 'FRI':
  print(2)
elif S == 'SAT':
  print(1)
a = input()
num=0
b=[]
for i in a:
  if a in 'ATGC':
    num+=1
  else:
    b.append(num)
    num=0
print(max(b))
    

### FIXED CODE ###

a = input()+"a"
num=0
b=[]
for i in a:
  if i in 'ATGC':
    num+=1
  else:
    b.append(num)
    num=0
print(max(b))
n = int(input())
s = input()
count = 0
for i in range(1, n):
    if s[i - 1] == "A" and s[i] == "B" and s[i+1] == "C":
        count += 1
    else:
        pass
print(count)

### FIXED CODE ###

n = int(input())
s = input()
count = 0

for i in range(1, n-1):
    if s[i - 1] == "A" and s[i] == "B" and s[i+1] == "C":
        count += 1
    else:
        pass
print(count)
l = map(int, raw_input().split())

print(l[0] + l[1]//2)

### FIXED CODE ###

x, y = map(int, input().split())
print(x + y//2)
n,k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
#print(p)
s= sum(p[:k])
print(s)

### FIXED CODE ###

α = input()
if α in['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']:
    print('A')
else:
    print('a')
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

if n >= m:
    print(0)

li = []
for i in range(len(x)-1):
    li.append(x[i+1] - x[i])

for i in range(n-1):
    m = max(li)
    li.remove(m)

print(sum(li))


### FIXED CODE ###

import numpy as np
import heapq

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

if n >= m:
    print(0)
else:
    npx = np.array(x)
    li = list(np.diff(npx, n = 1))

    print(sum(heapq.nsmallest(len(li)-n+1, li)))
N = int(input())
S = [input() for _ in range(N)]

cnt = 0
b = 0
a = 0
ab = 0
for x in S:
    cnt += x.count('AB')
    if x[0] == 'B':
        b += 1
    if x[-1] == 'A':
        a += 1
    if x[0] == 'B' and x[-1] == 'A':
        ab += 1

if a+b >= 2:
    if a == ab and b == ab:
        a = 1
        b = 1
        ab -= 2
    if a > b:
        cnt += a//b + ab
    else:
        cnt += b//a + ab

print(cnt)

### FIXED CODE ###

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

cnt = 0
b = 0
a = 0
ab = 0
for x in S:
    cnt += x.count('AB')
    if x[0] == 'B' and x[-1] == 'A':
        ab += 1
        continue
    if x[0] == 'B':
        b += 1
    if x[-1] == 'A':
        a += 1
    

if (a>0 and b>0) or ab>=2:
    if a==0:
        a = 1
        ab -= 1
    if b==0:
        b = 1
        ab -= 1
    cnt += min(a,b) + ab

print(cnt)