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

N = int(input())
S = input()

sa = [i for i in range(N+1)]
rank = [ord(c) for c in S] + [-1]

k = -1
key = lambda i: (rank[i], rank[i+k] if i+k <= N else -1)

def construct_sa():
    global k,rank
    k = 1
    tmp = [0] * (N+1)
    while k <= N:
        sa.sort(key=key)
        tmp[sa[0]] = 0
        for i in range(1,N+1):
            tmp[sa[i]] = tmp[sa[i-1]] + (key(sa[i-1]) < key(sa[i]))
        rank = [r for r in tmp]
        k *= 2

construct_sa()


def exist_twice(s):
    n = len(s)
    l,r = 0,N
    while r-l > 1:
        m = (l+r)//2
        if S[sa[m]:sa[m]+n] < s:
            l = m
        else:
            r = m
    if S[sa[r]:sa[r]+n] != s:
        return False
    minsa = maxsa = sa[r]
    while r <= N and S[sa[r]:sa[r]+n] == s:
        minsa = min(minsa, sa[r])
        maxsa = max(maxsa, sa[r])
        if maxsa - minsa >= n:
            return True
        r += 1
    return False

def is_ok(l):
    if l<=0: return True
    for i in range(N-l+1):
        if exist_twice(S[i:i+l]):
            return True
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

### FIXED CODE ###

N = int(input())
S = input()
from collections import deque

def is_ok(l):
    hs = set()
    q = deque()
    for i in range(N-l+1):
        h = hash(S[i:i+l])
        if h in hs:
            return True
        q.append(h)
        if len(q) >= l:
            hs.add(q.popleft())
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)
### BUGGY CODE ###

#!/usr/bin/python3

(n, x, y) = map(int, input().split())

cs = [0 for i in range(n)]

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        d = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
        if d == (abs(y - i) + 1 + abs(j - x)):
            print(i, j, d)
        cs[d] += 1

for i in range(1, n):
    print(cs[i])


### FIXED CODE ###

#!/usr/bin/python3

(n, x, y) = map(int, input().split())

cs = [0 for i in range(n)]

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        d = min(abs(j - i), abs(x - i) + 1 + abs(j - y))
        cs[d] += 1

for i in range(1, n):
    print(cs[i])
### BUGGY CODE ###

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

s=[input() for i in range(h)]

# def ok(i,j,houkou, count):
#     if i==h or j==w:
#         return count
#     elif s[i][j]=='#':
#         return count
#     elif houkou=='yoko':
#         return ok(i,j+1,houkou,count+1)
#     else:
#         return ok(i+1,j,houkou,count+1)

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

count=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='#' or j+1==w:
            for k in range(count):
                yoko[i][j-k-1]=count
            count=0

# print(yoko)


for j in range(w):
    for i in range(h):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='#' or i+1==h:
            for k in range(count):
                tate[i-k-1][j]=count
            count=0

# print(tate)

ans=0
for i in range(h):
    for j in range(w):
        if ans<yoko[i][j]+tate[i][j]-1:
            ans=yoko[i][j]+tate[i][j]-1
print(ans)

### FIXED CODE ###

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

s=[input() for i in range(h)]

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

count=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='#' or j+1==w:
            for k in range(count):
                yoko[i][j-k-1]=count
            count=0

# print(yoko)


for j in range(w):
    for i in range(h):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='#' or i+1==h:
            for k in range(count):
                tate[i-k-1][j]=count
            count=0

# print(tate)

ans=0
for i in range(h):
    for j in range(w):
        if ans<yoko[i][j]+tate[i][j]-1:
            ans=yoko[i][j]+tate[i][j]-1
print(ans)
### BUGGY CODE ###

a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
jobs.sort(key = lambda x:(x[1],x[0]))
score = 0
for i in range(b):
  for j in range(len(jobs)):
    job = jobs[len(jobs) - j - 1]
    if job[0] <= i + 1:
      score += job[1]
      jobs.remove(job)
      break;
print(score)

### FIXED CODE ###

import heapq

n ,m = map(int,input().split())
li = []
for i in range(n):
    x, y= map(int,input().split())
    li.append([x,y])
li.sort()
heap = []

ans = 0
j = 0
for i in range(1, m + 1):
    while j < n and li[j][0] <= i:
        heapq.heappush(heap,-li[j][1])
        j += 1
    if heap:
        ans += -heapq.heappop(heap)
 
print(ans)
### BUGGY CODE ###

import heapq

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.count = 0

	def find(self, x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1

			self.count += 1
			return True
		return False

n = int(input())
x = []
y = []
for i in range(n):
	a, b = map(int, input().split())
	x.append([i, a])
	y.append([i, b])

vx = sorted(x, key=lambda x: x[1])
vy = sorted(y, key=lambda x: x[1])

edges = []
uf = UnionFind(n)

for i in range(n - 1):
	if vx[i][1] == vx[i + 1][1]:
		uf.union(vx[i][0], vx[i + 1][0])
	else:
		heapq.heappush(edges, (vx[i + 1][1] - vx[i][1], vx[i][0], vx[i + 1][0]))

	if vy[i][1] == vy[i + 1][1]:
		uf.union(vy[i][0], vy[i + 1][0])
	else:
		heapq.heappush(edges, (vy[i + 1][1] - vy[i][1], vy[i][0], vy[i + 1][0]))


#edges = sorted(edges, key=lambda x: x[2], reverse=True)
#print(edges)

ans = 0

while edges != []:
	e = heapq.heappop(edges)
	if uf.union(e[1], e[2]):
		ans += e[0]
	if uf.count == n - 1:
		break

print(ans)

### FIXED CODE ###

import heapq
import sys
sys.setrecursionlimit(10 ** 7)

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.count = 0

#	def find(self, x):
#		while self.table[x] >= 0:
#			x = self.table[x]
#		return x

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1

			self.count += 1
			return True
		return False

n = int(input())
x = []
y = []
for i in range(n):
	a, b = map(int, input().split())
	x.append([i, a])
	y.append([i, b])

vx = sorted(x, key=lambda x: x[1])
vy = sorted(y, key=lambda x: x[1])

edges = []
uf = UnionFind(n)

for i in range(n - 1):
	if vx[i][1] == vx[i + 1][1]:
		uf.union(vx[i][0], vx[i + 1][0])
	else:
		heapq.heappush(edges, (vx[i + 1][1] - vx[i][1], vx[i][0], vx[i + 1][0]))

	if vy[i][1] == vy[i + 1][1]:
		uf.union(vy[i][0], vy[i + 1][0])
	else:
		heapq.heappush(edges, (vy[i + 1][1] - vy[i][1], vy[i][0], vy[i + 1][0]))


#edges = sorted(edges, key=lambda x: x[2], reverse=True)
#print(edges)

ans = 0

while edges != []:
	e = heapq.heappop(edges)
	if uf.union(e[1], e[2]):
		ans += e[0]
	if uf.count == n - 1:
		break

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

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

import collections

for i in range(N):
  ans=0
  c = collections.Counter(A)
  c[A[i]]=c[A[i]]-1
  B=list(c.values())
  for k in range(len(B)):
    ans+=B[k]*(B[k]-1)/2
  print(int(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))

import collections
c = collections.Counter(A)
B=list(c.values())
ans=0
for k in range(len(B)):
    ans+=B[k]*(B[k]-1)/2
for i in range(N):
  anser=ans
  anser=anser+1-c[A[i]]
  print(int(anser))
### BUGGY CODE ###

from collections import deque
N,K = (int(x) for x in input().split())
S = input()
count = []
d = deque(list(S))

now = d.popleft()
cum = 1
for i in range(len(S)-1):
    popped = d.popleft()
    if popped == now:
        cum += 1
    else:
        count.append(cum)
        now = popped
        cum = 1
count.append(cum)

if len(count) // 2 <= K:
    print(N-1)
else:
    m = 0
    for i in range(len(count)-2*K):
        if i == 0:
            c = sum(count[0:2*K+1]) - 1
            d = sum([j-1 for j in count[2*K+1:]])
        elif i == len(count) - 2*K + 1:
            c = sum(count[-(2*K+1):])
            d = sum([j-1 for j in count[0:-(2*K+1)]])
        else:
            c = sum(count[i:2*K+1+i]) - 1
            d1 = sum([j-1 for j in count[0:i]])
            d2 = sum([j-1 for j in count[2*K+1+i:]])
            d = d1 + d2
        m = max(m,c+d)
    print(m)

### FIXED CODE ###

from collections import deque
import numpy as np
N,K = (int(x) for x in input().split())
S = input()
count = []
d = deque(list(S))

now = d.popleft()
cum = 1
for i in range(len(S)-1):
    popped = d.popleft()
    if popped == now:
        cum += 1
    else:
        count.append(cum)
        now = popped
        cum = 1
count.append(cum)
points = [i-1 for i in count]
cs1 = np.array(count).cumsum()
cs2 = np.array(points).cumsum()

if len(count) // 2 <= K:
    print(N-1)
else:
    m = 0
    for i in range(len(count)-2*K):
        if i == 0:
            c = cs1[2*K] - 1
            d = cs2[-1] - cs2[2*K]
        elif i == len(count) - 2*K + 1:
            c = cs1[-1] - cs1[-2*K-2] - 1
            d = cs2[-2*K-2]
        else:
            c = cs1[2*K+i] - cs1[i-1] - 1
            d = cs2[i-1] + (cs2[-1]-cs2[2*K+i])
        m = max(m,c+d)
    print(m)
### BUGGY CODE ###

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

mod = 10**9 + 7
array = []

for k in range(1, K+1):
    array.append(pow((K // k), N))
    
for k in range(K, 0, -1):
    for i in range(2*k, K+1, k):
        array[k-1] -= array[i-1]

sum = 0
for k in range(1, K+1):
    array[k-1] *= k
    array[k-1] %= mod
    sum += array[k-1]
    
sum %= mod

print(sum)

### FIXED CODE ###

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

mod = 10**9 + 7
array = []

for k in range(1, K+1):
    array.append(pow((K // k), N, mod))
    
for k in range(K, 0, -1):
    for i in range(2*k, K+1, k):
        array[k-1] -= array[i-1]

sum = 0
for k in range(1, K+1):
    array[k-1] *= k
    array[k-1] %= mod
    sum += array[k-1]
    
sum %= mod

print(sum)
### BUGGY CODE ###

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

s = 0
while True:
    divided = False
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] //= 2
            divided = True
            break
    if divided:
        s += 1
    else:
        break
print(s)


### FIXED CODE ###

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

s = 0
for i in range(n):
    while a[i] % 2 == 0:
        a[i] //= 2
        s += 1
print(s)
### BUGGY CODE ###

from collections import deque
def main():
    n,m=map(int,input().split())
    root=[[0 for i in range(n)] for i in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1][b-1]=1
        root[b-1][a-1]=1
    dict={}
    for i in range(n):
        dict[i]=-1

    start=0
    check=[False]*n
    toVis=deque()
    check[start]=True
    for i in range(len(root[0])):
        if root[0][i]==1:
            toVis.append(i)
            dict[i]=start
        #   print(i,":",start)
            check[i]=True
    while len(toVis)>0:
        now=toVis.popleft()
        #print(now)
        check[now]=True
        for i in range(n):
            if root[now][i]==1 and check[i]==False:
                toVis.append(i)
                dict[i]=now
            # print(i,":",now)
                check[i]=True
    #print(dict)  
    for i in range(1,n):
        if dict[i]==-1:
            print("No")
            return 0
    print("Yes")
    for i in range(1,n):
        print(dict[i]+1)         


if __name__=="__main__":
    main()

### FIXED CODE ###

from collections import deque
def main():
    n,m=map(int,input().split())
    root=[[] for i in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1].append(b-1)
        root[b-1].append(a-1)
    dict={}
    for i in range(n):
        dict[i]=-1

    start=0
    check=[False]*n
    toVis=deque()
    check[start]=True
    for v in root[start]:
        toVis.append(v)
        dict[v]=start
    #   print(i,":",start)
        check[v]=True
    while len(toVis)>0:
        now=toVis.popleft()
        #print(now)
        check[now]=True
        for v in root[now]:
            if check[v]==False:
                toVis.append(v)
                dict[v]=now
            # print(i,":",now)
                check[v]=True
    #print(dict)  
    for i in range(1,n):
        if dict[i]==-1:
            print("No")
            return 0
    print("Yes")
    for i in range(1,n):
        print(dict[i]+1)         


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

# coding: utf-8

S = input()
Q = int(input())
# print("S:{}".format(S))
# print("Q:{}".format(Q))
query = []

for i in range(Q):
    query.append(input().split())
# for i in query:
#     print(i)
for i in query:
    if len(i) == 1:
        S = ''.join(list(reversed(S)))
    else:
        if i[1]=="1":
            S = i[2]+S
        else:
            S = S+i[2]
print(S)


### FIXED CODE ###

# coding: utf-8

S = input()
Q = int(input())

query = []

for i in range(Q):
    query.append(input().split())


bool = True
pre =''
suf =''

for i in query:
    if len(i) == 1:
        bool = not(bool)

    else:
        if i[1]=="1":
            if bool:
                pre = i[2]+pre
            else:
                suf += i[2]
        else:
            if bool:
                suf += i[2]
            else:
                pre = i[2]+pre

S = pre+ S +suf
print(S) if bool else print(S[::-1])
### BUGGY CODE ###

def func1(i,N,S):
  indexS = 0
  indexI = 0
  i2 = str(i).zfill(3)
  
  while indexS < N:
    if indexI > 2:
      break
    if i2[indexI] not in S:
      return 0
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  return 1 if indexI >2 else 0

def main():
  N = int(input())
  S = input()
  print(sum([func1(i,N,S) for i in range(1000)]))

if __name__ == '__main__':
  main()

### FIXED CODE ###

def func1(i,N,S):
  indexS = 0 #Sの見ている場所
  indexI = 0 #3桁の暗証番号の見ている場所(0~2)
  i2 = str(i).zfill(3) # 0埋めしたi
  
  while indexS < N:
    if indexI > 2:
      break #探索終了
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  return 1 if indexI >2 else 0

def main():
  N = int(input())
  S = input()
  print(sum([func1(i,N,S) for i in range(1000)]))

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

n, m = map(int, input().split())
work_list = [list(map(int, input().split())) for _ in range(n)]
work_cand = []
salary = 0
for j in range(1, m + 1):
    for i in range(n):
        if work_list[i][0] == j:
            work_cand.append(work_list[i])
        else:
            pass
    if work_cand != []:
         work_cand.sort(key = lambda x: x[1], reverse = True)
         salary += work_cand[0][1]
         del work_cand[0]
    else:
        pass
print(salary)



### FIXED CODE ###

from operator import itemgetter
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = itemgetter(0))
q = []
idx = 0
ans = 0
for i in range(1, m+1):
    while idx < n:
        a, b = ab[idx]
        if a <= i:
            heapq.heappush(q, -b)
            idx += 1
        else:
            break
    if len(q) > 0:
        b = heapq.heappop(q)
        ans -= b
print(ans)
### BUGGY CODE ###

def main():

    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    A = [a-1 for a in A]

    L = 65
    D = [[0]*n for _ in range(L+1)]

    for i, a in enumerate(A):
        D[0][i] = a

    for i in range(L):
        for j in range(n):
            D[i+1][j] = D[i][D[i][j]]

    ans = 0
    for i in range(L):
        if k & (1 << i):
            ans = D[i][ans]
    print(ans+1)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

A = [a-1 for a in A]

g = [[] for i in range(n)]
for i, a in enumerate(A):
    g[i].append(a)

s = []
visit = [-1]*n
s.append(0)
visit[0] = 0
while s:
    v = s.pop()
    for u in g[v]:
        if visit[u] == -1:
            visit[u] = visit[v]+1
            s.append(u)
        else:
            temp = visit[u]
#print(temp)
#print(visit)
d = max(visit)-temp+1
#print(d)
if k < temp:
    for i in range(n):
        if visit[i] == k:
            print(i+1)
            exit()
else:
    q, r = divmod(k-temp, d)
    for i in range(n):
        if visit[i]-temp == r:
            print(i+1)
            exit()
### BUGGY CODE ###

from itertools import accumulate
n, K = map(int,input().split())
A = list(map(int,input().split()))
b = [0 for _ in range(n+1)]

for k in range(K):
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    ac = list(accumulate(b))
    A = ac
    b = [0 for _ in range(n+1)]

print(*ac[:-1])

### FIXED CODE ###

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

for _ in range(K):
    b = [0 for _ in range(n+1)]
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    for i in range(n):
        b[i+1] += b[i]

    A = b[:-1]
    if all(a == n for a in A):
        break
print(*A)
### BUGGY CODE ###

import sys
def main():
    s=list(sys.stdin.readline().strip())
    t=list(sys.stdin.readline().strip())
    S,T=len(s),len(t)
    dp=[[[''] for _ in range(T+1)] for _ in range(S+1)]
    for i in range(1,S+1):
        for j in range(1,T+1):
            if s[i-1]==t[j-1]:
                dp[i][j]=dp[i-1][j]+[s[i-1]]
            else:
                dp[i][j]=dp[i-1][j] if len(dp[i-1][j])>len(dp[i][j-1]) else dp[i][j-1]
    print(''.join(dp[S][T]))
if __name__=='__main__':main()

### FIXED CODE ###

import sys
def main():
    s=list(sys.stdin.readline().strip())
    t=list(sys.stdin.readline().strip())
    S,T=len(s),len(t)
    dp=[[0 for _ in range(T+1)] for _ in range(S+1)]
    for i in range(S):
        for j in range(T):
            if s[i]==t[j]:dp[i+1][j+1]=dp[i][j]+1
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j],dp[i][j+1])
    res=''
    i,j=S,T
    while i>0 and j>0:
        if dp[i][j]==dp[i-1][j]:i-=1
        elif dp[i][j]==dp[i][j-1]:j-=1
        else:
            res=s[i-1]+res
            i,j=i-1,j-1
    print(res)
if __name__=='__main__':main()
### BUGGY CODE ###

#from math import gcd
from fractions import gcd
from functools import reduce

mod = 10**9 + 7

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


N = int(input())
A = [i for i in map(int, input().split())]

ans = reduce(lcm, A)

#print(ans)
B = [ans//i for i in A]

print(sum(B) % mod)


### FIXED CODE ###

#from math import gcd
from fractions import gcd
from functools import reduce

mod = 10**9 + 7

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


N = int(input())
A = [i for i in map(int, input().split())]

ans = reduce(lcm, A)

#print(ans)
B = [ans//i for i in A]

print(sum(B) % mod)
### BUGGY CODE ###

from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-10

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r)) 


### FIXED CODE ###

from math import ceil

def BinarySearch(x):
    ans = sum([ceil(a/x)-1 for a in A])
    if ans <= K:
        return True
    else:
        return False

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

r = max(A)
l = 0
eps = 10**-6

while abs(r-l) > eps:

    m = (r+l)/2

    if BinarySearch(m):
        r = m
    else:
        l = m

print(ceil(r))
### BUGGY CODE ###

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

r = 0

for a in range(1, N+1):
    for b in range(1, N+1):
        if a % b >= K:
            r += 1

print(r)


### FIXED CODE ###

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

result = 0
if K == 0:
    result = N * N
else:
    for i in range(K+1, N+1):
        result += (N//i * (i - K) + max(N%i-K+1, 0))

print(result)
### BUGGY CODE ###

import math
a,b,c=map(int,input().split())
d=[]
a=float(a)
b=float(b)
for i in range(0,c+1):
    e=int(math.floor(a*i/b)-a*math.floor(i/b))
    d.append(e)
print(max(d))


### FIXED CODE ###

import math
a,b,c=map(int,input().split())
if b>c:
    print(math.floor((a*c)/b)-a*(math.floor(c/b)))
else:
    print(math.floor((a*(b-1))/b)-a*(math.floor((b-1)/b)))
### BUGGY CODE ###

import numpy as np

N,M = map(int, input().split())
t_table = {}
for i in range(M):
	x,y = map(int, input().split())
	if x-1 in t_table: t_table[x-1].append(y-1)
	else: t_table[x-1] = [y-1]
ans = 0
dp = np.ones(N, dtype='int32')
while True:
	pnode = dp.copy()
	dp = np.zeros(N, dtype='int32')
	for i in np.where(pnode)[0]:
		if i in t_table :
			dp[t_table[i]] += 1
	dp[dp>0] = 1
	if((dp == 0).all()):
	 	print(ans)
	 	break
	ans += 1

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int, input().split())
lst_edge = [[] for _ in range(N)]
for _ in range(M):
	x,y = map(int, input().split())
	lst_edge[x-1].append(y-1)

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)
### BUGGY CODE ###

n = input()
s = input().strip().split(" ")
q = int(input().strip())
t = input().strip().split(" ")

count = 0
for i in t:
    if i in s:
        count += 1
print(count)

### FIXED CODE ###

n = int(input().strip())
s = list(map(int, input().strip().split(" ")))
q = int(input().strip())
t = list(map(int, input().strip().split(" ")))

s.sort()
t.sort()

count = 0
index = 0
for number in t:
    while (number > s[index] and index < n - 1):
        index += 1
    if number == s[index]:
        count += 1
print(count)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

def yoi(s, a, b):
  for i in range(n):
    for j in range(i+1, n):
      if s[(i + a) % n][(j + b) % n] != s[(j + a) % n][(i + b) % n]:
        return 0
  return 1

sol = sum(yoi(s, 0, b) for b in range(n))
print(sol * n)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
st = [str().join(s_) for s_ in zip(*s)]

sol = 0

for i in range(n):
    for k in range(n):
        if s[k] != st[k]:
            break
    else:
        sol += 1
    
    s = [s_l[1:]+s_l[0] for s_l in s]
    st = st[1:] + [st[0]]
    
print(sol * n)