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

def main():
    h,w = map(int,input().split())
    S = [[] for i in range(h)]
    q = []
    cnt = 0
    for i in range(h):
        s = input()
        for j in range(w):
            S[i].append(s[j])
            if s[j]=='#':
                q.append([i,j])
                cnt += 1
    ans = 0
    while True:
        ans += 1
        q_ = []
        while len(q)>0:
            b = q.pop(0)
            if b[0]>0:
                if S[b[0]-1][b[1]]=='.':
                    cnt += 1
                    S[b[0]-1][b[1]]='#'
                    q_.append([b[0]-1,b[1]])
                    if cnt==h*w:
                        print(ans)
                        return
            if b[0]<h-1:
                if S[b[0]+1][b[1]]=='.':
                    cnt += 1
                    S[b[0]+1][b[1]]='#'
                    q_.append([b[0]+1,b[1]])
                    if cnt==h*w:
                        print(ans)
                        return
            if b[1]>0:
                if S[b[0]][b[1]-1]=='.':
                    cnt+=1
                    S[b[0]][b[1]-1]='#'
                    q_.append([b[0],b[1]-1])
                    if cnt==h*w:
                        print(ans)
                        return
            if b[1]<w-1:
                if S[b[0]][b[1]+1]=='.':
                    cnt += 1
                    S[b[0]][b[1]+1]='#'
                    q_.append([b[0],b[1]+1])
                    if cnt==h*w:
                        print(ans)
                        return
        q = q_

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import deque
def main():
    h,w = map(int,input().split())
    S = [list(input()) for i in range(h)]
    q = [(i,j) for i,a in enumerate(S) for j,b in enumerate(a) if b=='#']
    q = deque(q)
    ans = 0
    s = h*w
    cnt = len(q)
    nxt = [(0,1),(1,0),(-1,0),(0,-1)]
    while cnt < s:
        ans += 1
        q_ = deque([])
        while q:
            a,b = q.pop()
            for x,y in nxt:
                X,Y = a+x,b+y
                if 0>X or X>h-1 or 0>Y or Y>w-1:
                    continue
                if S[X][Y]=='.':
                    S[X][Y]='#'
                    q_.append((X,Y))
        q = q_
        cnt += len(q_)
    print(ans)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
INF = 10**18
arr = []
for a in A:
    l, r = -1, len(arr)
    while (r-l) > 1:
        mid = (r+l)//2
        if arr[mid] < a:
            l = mid
        else:
            r = mid
    if l == -1:
        arr = [a]+arr
    else:
        arr[l] = a
print(len(arr))


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
A = [int(input()) for _ in range(N)]
INF = 10**18
arr = deque([])
for a in A:
    l, r = -1, len(arr)
    while (r-l) > 1:
        mid = (r+l)//2
        if arr[mid] < a:
            l = mid
        else:
            r = mid
    if l == -1:
        arr.appendleft(a)
    else:
        arr[l] = a
print(len(arr))
### BUGGY CODE ###

import numpy as np
from functools import reduce
import fractions
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
 
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
n = int(input())

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

lcm = lcm_list(inp_list)

ans = 0

for i in inp_list:
    ans += lcm // i


print(ans % (10**9+7))



### FIXED CODE ###

from functools import reduce
import fractions
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
n = int(input())

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

lcm = lcm_list(inp_list)

ans = 0
mod = 10**9+7

for i in inp_list:
    ans += lcm // i



print(ans % mod)
### BUGGY CODE ###

N = int(input())
A = list([int(x) for x in input().split()])

for i in range(0, A[0] * 2 + 1, 2):
    result = [0] * N
    result[0] = i
    for x in range(N-1, -1, -1):
        if x == N-1:
            r = (A[x] - result[0] // 2) * 2
        else:
            r = (A[x] - result[x+1] // 2) * 2

        if r % 2 != 0 or r < 0:
            break

        if x == 0:
            if r == i:
                print(' '.join([str(x) for x in result]))
                exit()

        result[x] = r


### FIXED CODE ###

N = int(input())
A = list([int(x) for x in input().split()])

result = [0] * N
x = 0
for key, i in enumerate(A):
    if key % 2 == 0:
        x += i
    else:
        x -= i

result[0] = x

for i in range(1, N):
    result[i] = 2 * A[i-1] - result[i-1]

print(' '.join([str(x) for x in result]))
### BUGGY CODE ###

import heapq

N,M = list(map(int,input().split()))
A = [[] for _ in range(M)]

for i in range(N):
    a,b = list(map(int,input().split()))
    if a <= M:
        A[a-1].append(-b)
    
ans = 0
cand = []

for i in range(M):
    
    for j in A[i]:
        cand.append(j)
        
    if cand:
        heapq.heapify(cand)
        ans -= heapq.heappop(cand)
    
print(ans)

### FIXED CODE ###

import heapq

N, M = list(map(int,input().split()))
A = [[] for _ in range(M)]

for i in range(N):
    a, b = list(map(int,input().split()))
    if a <= M:
        A[a-1].append(-b)
    
ans = 0
cand = []

for i in range(M):
    
    for j in A[i]:
        heapq.heappush(cand, j)
        
    if cand:
        ans -= heapq.heappop(cand)
    
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
li_a = list(map(int, input().split()))
if k == 1:
    for i in range(1, n):
        if li_a[i] > li_a[i-1]:
            print('Yes')
        else:
            print('No')
else:
    li = []
    tmp = 1
    for i in range(k):
        tmp *= li_a[i]
    li.append(tmp)
    for i in range(k, n):
        tmp = tmp // li_a[i-k]
        tmp  *= li_a[i]
        li.append(tmp)
    for i in range(1, n-k+1):
        if li[i] > li[i-1]:
            print('Yes')
        else:
            print('No')

### FIXED CODE ###

n, k = map(int, input().split())
li_a = list(map(int, input().split()))
if k == 1:
    for i in range(1, n):
        if li_a[i] > li_a[i-1]:
            print('Yes')
        else:
            print('No')
else:
    for i in range(k, n):
        if li_a[i-k] < li_a[i]:
            print('Yes')
        else:
            print('No')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

def main():
    n, q = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(lambda x: int(x)-1, input().split())
        g[a].append(b); g[b].append(a)
    node = [0]*n
    for i in range(q):
        p, x = map(int, input().split())
        p -= 1
        node[p] += x

    def dfs(v, p=-1):
        for u in g[v]:
            if u==p:
                continue
            node[u] += node[v]
            dfs(u, v)
    dfs(0)
    print(*node)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

n, q = map(int, input().split())
g = [list() for i in range(n)]
node = [0] * n

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

for i in range(q):
    p, x = map(int, input().split())
    node[p-1] += x

def dfs(v, p=-1):
    for u in g[v]:
        if u == p: continue
        node[u] += node[v]
        dfs(u, v)

dfs(0)
print(*node)
### BUGGY CODE ###

n=int(input())
s=str(input())
import itertools
l=[]
for v in itertools.combinations(s, 3):
  l.append(v)
print(len(set(l)))

### FIXED CODE ###

n=int(input())
s=str(input())
ans=0
for _ in range(1000):
  t=str(_).zfill(3)
  #print(t)
  if s.find(t[0])==-1:
    continue
  check=s[s.find(t[0])+1:]
  if check.find(t[1])==-1:
    continue
  fin=check[check.find(t[1])+1:]
  if fin.find(t[2])==-1:
    continue
  ans+=1
print(ans)
### BUGGY CODE ###

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b, n = map(int, input().split())

    ans = 0

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

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


### FIXED CODE ###

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b, n = map(int, input().split())

    ans = 0

    x = min(b - 1, n)
    ans = max(int(a * x / b) - a * int(x / b), ans)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

_input = sys.stdin.readlines()
array_length = int(_input[0])
array = list(map(int, _input[1].split()))
# print(array_length, array)
assert array_length == len(array)


def merge(A, left, mid, right):
    global count
    
    n1 = mid - left
    n2 = right - mid
    L = [0 for _ in range(n1 + 1)]
    R = [0 for _ in range(n2 + 1)]

    for i in range(n1):
        L[i] = A[left + i]

    for j in range(n2):
        R[j] = A[mid + j]

    L[n1], R[n2] = [1e9] * 2
    i, j = 0, 0

    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    return None


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A


if __name__ == '__main__':
    count = 0
    print(*merge_sort(A=array, left=0, right=array_length))
    print(count)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def merge(A, left, mid, right):
    global count

    L = A[left:mid] + [1e9]
    R = A[mid:right] + [1e9]

    i, j = 0, 0

    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return None


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    assert array_length == len(array)
    count = 0
    print(*merge_sort(A=array, left=0, right=array_length))
    print(count)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
result_1 = []
result_1.append(abs(a[0]))
for i in range(n-1):
    result_1.append(abs(a[i+1]-a[i]))
result_1.append(abs(a[n-1]))
a.insert(0,0)
a.insert(n+1,0)
for i in range(n):
    if a[i+2] >= a[i+1] >= a[i]:
        print(sum(result_1))
    elif a[i+2] <= a[i+1] <= a[i]:
        print(sum(result_1))
    else:
        b = abs(a[i+2]-a[i+1])
        c = abs(a[i+1]-a[i])
        d = abs(a[i+2]-a[i])
        result = sum(result_1) - (b + c - d)
        print(result)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
total = abs(a[0]) + abs(a[n-1])
for i in range(n-1):
    total += abs(a[i+1] - a[i])
a.insert(0,0)
a.insert(n+1,0)
ans=[]
for i in range(1,n+1):
    if a[i-1]<=a[i]<=a[i+1] or a[i-1]>=a[i]>=a[i+1]:
        ans.append(total)
    else:
        change = total + abs(a[i+1]-a[i-1]) -(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))
        ans.append(change)
for i in range(n):
    print(ans[i])
### BUGGY CODE ###

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

SL = sorted(L)
count = 0

for i in range (0, max(L)):
	p=len([j for j in SL[count::] if j == i+1]) 
	count+=p
	print(p)

for i in range (max(L), N):
	print(0)

### FIXED CODE ###

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

K = [0]*N

for i in range (0, N-1):
	K[L[i]-1]+=1

print(*K, sep = "\n")
### BUGGY CODE ###

#!/usr/bin/env python

import sys
import numpy as np

s= sys.stdin.readline().strip()
n= len(s)
#
MOD=10**9+7
#
base = 1
dp = np.zeros( shape=(n+1,13),dtype=np.int64 )
dp[0][0] = 1
for i,c in enumerate(reversed(s)):
    prev= dp[i]
    now = dp[i+1]
    #
    if c=="?":
        for b in [ base*i for i in range(10) ]:
            for m,num in enumerate(prev):
                if num==0: continue
                idx= (m+b)%13
                now[idx]= now[idx]+num
        #
        for i in range(13): now[i] %= MOD
    else:
        b= base*int(c)
        for m in range(13):
            idx= (m+b)%13
            now[idx]= prev[m]
    #
    base = base*10
#
print(dp[n][5])


### FIXED CODE ###

import sys
 
s= sys.stdin.readline().strip()
#
MOD=10**9+7
mmap= []
for i in range(6):
    b = 10**i % 13
    mmap.append( [ [ (b*i+j)%13 for i in range(1,10) ] for j in range(13) ] )
#
dp= [ 0 ] * 13
dp[0] = 1
j= 0
for c in reversed(s):
    tmp = dp.copy()
    #
    if c=="0": pass
    elif c=="?":
        bset = mmap[j]
        for m,num in enumerate(tmp):
            if num==0: continue
            for idx in bset[m]: dp[idx]+=num
        #
        for i in range(13): dp[i]%=MOD
    else:
        b= mmap[j][0][int(c)-1]
        for m in range(13):
            idx= (m+b)%13
            dp[idx]= tmp[m]
    #
    if j==5: j=0
    else: j+=1
#
print(dp[5])
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S.reverse()
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2])
        elif q[1] == '2':
            S.append(q[2])

print(''.join(S))


### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(S)))
### BUGGY CODE ###

n = int(input())
a = [0]*n
a = list(map(int, input().split()))

a.sort()
i = 0
while a[i+1] < -a[i]:
      a[i+1] *= -1
      a[i] *= -1
      a.sort()
sum = 0
for i in range(n):
      sum += a[i]
print(sum)

### FIXED CODE ###

n = int(input())
a = [0]*n
a = list(map(int, input().split()))

a.sort()
i = 0
tmp = 0
while i + 1 < n and a[i+1] < 0:
      a[i] *= -1
      a[i+1] *= -1
      i += 2

a.sort()
if a[1] < -a[0]:
    a[1] *= -1
    a[0] *= -1


sum = 0
for i in range(n):
      sum += a[i]
print(sum)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N, Q = map(int, input().split())
ab = [None] * (N - 1)
for i in range(N - 1):
    ab[i] = list(map(int, input().split()))
ab = sorted(ab, key=lambda x: (x[0], x[1]))

px_n = [0] * N
for i in range(Q):
    p, x = list(map(int, input().split()))
    px_n[p-1] += x

ans = [0] * N
ans[0] = px_n[0]
for i in range(N - 1):
    a, b = ab[i]
    ans[b-1] += ans[a-1] + px_n[b-1]

print(*ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
ab = [None] * (N - 1)
for i in range(N - 1):
    ab[i] = list(map(int, input().split()))
ab = sorted(ab, key=lambda x: (x[0], x[1]))

px_n = [0] * N
for i in range(Q):
    p, x = list(map(int, input().split()))
    px_n[p-1] += x

ans = [0] * N
ans[0] = px_n[0]
for (a, b) in ab:
    ans[b-1] += ans[a-1] + px_n[b-1]

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

#-*-coding:utf-8-*-

def main():
    a, b, k = list(map(int, input().split()))
    cnt = 1

    for i in range(a, b+1):
        if cnt <= k or cnt >= b - a + 2 - k:
            print(i)
        cnt += 1

if __name__ == '__main__':
    main()

### FIXED CODE ###

#-*-coding:utf-8-*-

def main():
    a, b, k = list(map(int, input().split()))
    ab_set = set()
    cnt1 = 1
    cnt2 = 1
    
    for i in range(a, b+1):
        if cnt1 <= k:
            ab_set.add(i)
        else:
            break
        cnt1 += 1
        
    for j in range(b, a-1, -1):
        if cnt2 <= k:
            ab_set.add(j)
        else:
            break
        cnt2 += 1
    
    ab_list = list(ab_set)
    ab_list.sort()
    for i in ab_list:
        print(i)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

A,B,K = map(int, input().split())
if A - B > 100:
  [print(i) for i in range(A,A+K) if i - K < A]
  [print(i) for i in range(B+1-K,B+1) if i + K > B]
else:
  [print(i) for i in range(A,B+1) if i - K < A or i + K > B]

### FIXED CODE ###

A,B,K = map(int, input().split())
if B-A > 2 * K:
  [print(i) for i in range(A,A+K)]
  [print(i) for i in range(B+1-K,B+1)]
else:
  [print(i) for i in range(A,B+1) if i - K < A or i + K > B]
### BUGGY CODE ###

N , M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)
sorted_data = {i:sorted(j) for i,j in sorted_data.items()}

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for i in range(M):
    rank = sorted_data[data[i][0]].index(data[i][1]) + 1
    print(num2str(data[i][0]) + num2str(rank))

### FIXED CODE ###

N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))
### BUGGY CODE ###

"""
最長経路問題として解く。

各試合のノードを作成。
各試合ノードごとに、「この試合が終わったら、次はこの試合ができるようになる。」という対応関係を作っていく。
"""
def main():
    import sys
    sys.setrecursionlimit(1000000)

    N = int(input())

    A = [[0]*(N)]
    for _ in range(N):
        A.append([0]+list(map(int,input().split())))
    
    #選手iにとって、選手jが何番目の相手かを逆引きするメモを用意しておく。
    reverseMemo = {i:{} for i in range(1,N+1)}
    for i in range(1,N+1):
        for j in range(1,N):
            a = A[i][j]
            reverseMemo[i][a] = j

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

    edges = {}
    for match in matchs:
        edges[match] = []
        i,j = match
        if reverseMemo[i][j] != N-1:
            nx = A[i][reverseMemo[i][j]+1]
            edges[match].append((min(i,nx),max(i,nx)))
        if reverseMemo[j][i] != N-1:
            nx = A[j][reverseMemo[j][i]+1]
            edges[match].append((min(j,nx),max(j,nx)))

    stepMemo = {}
    def dfs(i,j,cnt):
        if cnt > N*N:
            print(-1)
            exit()
        #i,jの試合日を含めて、あと何日必要なのかを返す。
        if (i,j) not in stepMemo:
            res = 1
            for a,b in edges[(i,j)]:
                res = max(res,dfs(a,b,cnt+1)+1)
            stepMemo[(i,j)] = res
        return stepMemo[(i,j)]

    ans = 0
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            ans = max(ans,dfs(i,j,1))
    print(ans)
main()




### FIXED CODE ###

"""
最長経路問題として解く。

各試合のノードを作成。
各試合ノードごとに、「この試合が終わったら、次はこの試合ができるようになる。」という対応関係を作っていく。
"""
def main():
    import sys
    sys.setrecursionlimit(1000000)
    input = sys.stdin.readline

    N = int(input())

    A = [[0]*(N)]
    for i in range(N):
        A.append([0]+list(map(int,input().split())))
    
    #選手iにとって、選手jが何番目の相手かを逆引きするメモを用意しておく。
    reverseMemo = [[-1]*(N+1) for _ in range(N+1)]
    for i in range(1,N+1):
        for j in range(1,N):
            a = A[i][j]
            reverseMemo[i][a] = j
    edges = {}
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            match = (i,j)
            edges[match] = []
            if reverseMemo[i][j] != N-1:
                nx = A[i][reverseMemo[i][j]+1]
                edges[match].append((min(i,nx),max(i,nx)))
            if reverseMemo[j][i] != N-1:
                nx = A[j][reverseMemo[j][i]+1]
                edges[match].append((min(j,nx),max(j,nx)))
    
    del reverseMemo
    del A
    
    stepMemo = {}
    def dfs(i,j,path):
        #i,jの試合日を含めて、あと何日必要なのかを返す。
        if (i,j) not in stepMemo:
            if (i,j) in path:
                print(-1)
                exit()
            else:
                path.add((i,j))
            res = 1
            for a,b in edges[(i,j)]:
                res = max(res,dfs(a,b,path)+1)
            stepMemo[(i,j)] = res
        return stepMemo[(i,j)]

    ans = 0
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if (i,j) not in stepMemo:
                ans = max(ans,dfs(i,j,set()))
    print(ans)
main()
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
maxim = max(A)
select_num = 0
count_num = np.array([0]*(maxim+1))
for i in A:
  count_num[i] += 1
for i in range(1,maxim+1):
  select_num += (count_num[i])*(count_num[i] - 1)//2
for i in A:
  print(select_num -count_num[i] + 1)

### FIXED CODE ###

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

select_num = 0
count_num = [0]*(N+1)
for i in A:
  count_num[i] += 1
for i in range(1,N+1):
  select_num += (count_num[i])*(count_num[i] - 1)//2
for i in A:
  print(select_num -count_num[i] + 1)
### BUGGY CODE ###

n=int(input())
d={}
l=0
for i in range(n):
    s=input()
    if s not in d.values():
        d[l+1]=s
        l+=1

print(len(d))

### FIXED CODE ###

n=int(input())
a=[0]*n

for i in range(n):
    a[i]=input()
a=sorted(a)
ans=1
for i in range(n-1):
    if a[i]!=a[i+1]:
        ans+=1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

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


N = int(input())
A = [[int(x) for x in input().split()] for _ in range(N)]

A = [[]] + A

cnt = 0
ok = True
q = list(range(1, N+1))

for _ in range(N * (N - 1) // 2):
    can_match_today = [False] * (N+1)
    fin = True
    match = False
    for i in q:
        if can_match_today[i] or not A[i]:
            continue

        fin = False
        l = A[i][-1]

        if can_match_today[l]:
            continue
        r = A[l][-1]

        if r == i:
            match = True
            can_match_today[l] = True
            can_match_today[i] = True
            A[l].pop()
            A[i].pop()
            q.append(l)
            q.append(i)

    if fin:
        break

    if not match:
        ok = False
        break

    cnt += 1


if ok:
    print(cnt)
else:
    print(-1)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

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


N = int(input())
A = [[int(x) for x in input().split()] for _ in range(N)]

A = [[-1]] + A


def check(a, q=[]):
    if not A[a]:
        return False

    b = A[a][-1]
    b_op = A[b][-1]

    ok = False
    if a == b_op:
        ok = True

        if b < a:
            a, b = b, a
        q.append((a, b))

    return ok


q = []
for i in range(1, N + 1):
    check(i, q)

q = list(set(q))

day = 0
while q:
    nq = []
    for a, b in q:
        A[a].pop()
        A[b].pop()
        check(a, nq)
        check(b, nq)

    day += 1
    q = list(set(nq))

for i in range(1, N + 1):
    if len(A[i]) != 0:
        print(-1)
        exit()

print(day)
exit()