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

N = int(input())
g = {}
for i in range(1,N+1):
    g[i] = []
def dfs(g,start,end):
    stack = [(start, [start],0)]
    while stack:
        (v, path, length) = stack.pop()
        for next,l in g[v]:
            if next in path:
                continue
            if next == end:
                yield length + l
            else:
                stack.append((next, path + [next], length + l))

for i in range(N-1):
    a, b, c = map(int,input().split())
    g[a].append((b,c))
    g[b].append((a,c))
Q, K = map(int,input().split())

for q in range(Q):
    x, y = map(int,input().split())
    a = list(dfs(g,x,K))[0]
    b = list(dfs(g,K,y))[0]
    print(a+b)

### FIXED CODE ###

N = int(input())
g = {i: [] for i in range(1, N+1)}    

l = [0] * (N + 1)

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

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

stack = [K]

while len(stack):
    v = stack.pop()
    for c,ln in g[v]:
        if l[c] != 0:
            continue
        l[c] = l[v] + ln
        stack.append(c)

for q in range(Q):
    x, y = map(int,input().split())
    print(l[x] + l[y])
### BUGGY CODE ###

N=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(N-1,0,-1):
    num=a[i]
    for j in range(i-num+1):
        if a[j]+num==i-j:
            ans+=1
print(ans)


### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
ans=0
L={}
R={}
for i in range(N):
    if a[i]+i in L:
         k=L.get(a[i]+i)
         del L[a[i]+i]
         L[a[i]+i]=k+1
    else:
        L[a[i]+i]=1
    if i-a[i]>0:
        if i-a[i] in R:
             k=R.get(i-a[i])
             del R[i-a[i]]
             R[i-a[i]]=k+1
        else:
            R[i-a[i]]=1
for x in L.keys():
    if x in R:
        ans+=L.get(x)*R.get(x)
print(ans)
### BUGGY CODE ###

def main():
    s = input()
    t = input()

    if is_match_swith_rotation(s, t):
        print('Yes')
    else:
        print('No')

def is_match_swith_rotation(s, t):
    end = l = len(t)
    while end != 0:
        try:
            pos = s.rfind(t[0], 0, end)
        except ValueError:
            return False
        if s[pos:] == t[:l-pos] and s[:pos] == t[l-pos:]:
            return True
        end = pos

    return False

main()

### FIXED CODE ###

def main():
    s = input()
    t = input()

    if is_match_swith_rotation(s, t):
        print('Yes')
    else:
        print('No')

def is_match_swith_rotation(s, t):
    if t in s + s:
        return True
    else:
        return False

main()
### BUGGY CODE ###

n,m=map(int,input().split())
gate=[]
cnt=0
for i in range(m):
    lr=list(map(int,input().split()))
    gate.append(lr)
for j in range(1,n+1):
    if all(j in range(gate[i][0],gate[i][1]+1) for i in range(len(gate))):
        cnt+=1
print(cnt)

### FIXED CODE ###

n,m=map(int,input().split())
l_max=0
r_min=10**5+1
for i in range(m):
    l,r=map(int,input().split())
    l_max=max(l_max,l)
    r_min=min(r_min,r)
print(max(0,r_min-l_max+1))
### BUGGY CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
ans=b[n//2:]+b[:n//2]
ng=set(())
ok=[]
for i in range(n):
    if a[i]==ans[i]:
        ng.add(i)
    else:
        ok.append(i)
from random import randint
if ng:
    for x in ng:
        y=ok[randint(0,len(ok)-1)]
        while ans[x]==a[y] or ans[y]==a[x]:
            y=ok[randint(0,len(ok)-1)]
        ans[x],ans[y]=ans[y],ans[x]
        ok.append(x)
print('Yes')
print(*ans,sep=' ')


### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for k in cb:
    if k in ca:
        if cb[k]+ca[k]>n:
            print('No')
            exit()
tmpc=0
tmpd=0
c=[0]
d=[0]
for i in range(1,n+1):
    if i in ca:tmpc+=ca[i]
    if i in cb:tmpd+=cb[i]
    c.append(tmpc)
    d.append(tmpd)
x=0
for i in range(n+1):
    x=max(x,c[i]-d[i-1])
ans=b[-x:]+b[:-x]
print('Yes')
print(*ans,sep=' ')
exit()
print(c)
print(d)
### BUGGY CODE ###

N = int(input())

A = []
B = []
dif = []
for i in range(N):
    a, b = [int(i) for i in input().split()]
    dif.append(a-b)
    A.append(a)
    B.append(b)

count1 = 0
count2 = 0

def fa():
    if max(dif) > 0 or min(dif) < 0:
        if max(dif) > -min(dif):
            index = dif.index(max(dif))
        else:
            index = dif.index(min(dif))
    else:
        index = A.index(max(A))

    dif.pop(index)
    B.pop(index)
    return A.pop(index)

def fb():
    if max(dif) > 0 or min(dif) < 0:
        if max(dif) < -min(dif):
            index = dif.index(max(dif))
        else:
            index = dif.index(min(dif))
    else:
        index = A.index(max(A))

    dif.pop(index)
    A.pop(index)
    return B.pop(index)

while True:
    count1 += fa()
    if len(A) == 0:
        break
    count2 += fb()
    if len(A) == 0:
        break

print(count1 - count2)

### FIXED CODE ###

N = int(input())

AB = []
sum = 0
for i in range(N):
    a, b = [int(i) for i in input().split()]
    sum -= b
    AB.append(a+b)

AB.sort(reverse=True)

count = 0
for _ in range(N//2):
    count += AB.pop(0)
    AB.pop(0)
if N%2 == 1:
    count += AB.pop(0)

print(count + sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    p = a[:i] + a[i+1:]
    ans = 0
    for j in range(1,len(p)):
        ans += abs(p[j-1] - p[j])
    ans += abs(p[0]) + abs(p[-1])
    print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

abs1 = [0]*(n-1)
abs1_sum = 0
for i in range(1,n):
    abs1[i-1] = abs(a[i-1]-a[i])
    abs1_sum += abs(a[i-1]-a[i])


abs2 = [0]*(n-2)
for i in range(2,n):
    abs2[i-2] = abs(a[i-2]-a[i])
#print(abs1)

b_0 = abs(a[0])
b_1 = abs(a[1])
b_n1 = abs(a[n-1])
b_n2 = abs(a[n-2])
ans = []
for i in range(n):
    if i == 0:
        ans.append(abs1_sum - abs1[0] + b_1 + b_n1)
    elif i == n-1:#
        #print(abs1[:n-2],abs(p[0]),abs(p[-1]))
        ans.append(abs1_sum - abs1[-1] + b_0 + b_n2)
    else:
        ans.append(b_0 + b_n1 + abs1_sum - abs1[i] - abs1[i-1] + abs2[i-1])

for i in range(n):
    print(ans[i])
### BUGGY CODE ###

def solve(h,w,ch,cw,dh,hw,s):
    d=[[1,0],[-1,0],[0,1],[0,-1]]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + d]
    INF=10**12
    path=[[INF]*w for _ in range(h)]
    ans=0
    st=[]
    st=deque()
    st.append((ch,cw,0))
    wp=[]
    wp=deque()
    while st:
      nx,ny,ncost=st.popleft()
      wp.append((nx,ny,ncost))
      path[nx][ny]=ncost
      for dx,dy in d:
        x=nx+dx
        y=ny+dy
        if (0<=x<=h-1) and (0<=y<=w-1):
          if s[x][y]!='#' and path[x][y]>ncost:
            path[x][y]=ncost
            st.append((x,y,ncost))
      if len(st)==0:
        while wp:
          nx,ny,ncost=wp.popleft()
          for dx,dy in warp:
              x,y=nx+dx,ny+dy
              if (0<=x<=h-1) and (0<=y<=w-1):
                if s[x][y]!='#' and path[x][y]>ncost+1:
                  path[x][y]=ncost+1
                  st.append((x,y,ncost+1))
    if path[dh][dw]==INF:
      print(-1)
    else:
      print(path[dh][dw])

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    from collections import deque
    h,w=map(int,input().split())
    ch,cw=map(int,input().split())
    dh,dw=map(int,input().split())
    ch-=1
    cw-=1
    dh-=1
    dw-=1
    s=[input() for _ in range(h)]
    solve(h,w,ch,cw,dh,dw,s)

### FIXED CODE ###

def solve(h,w,ch,cw,dh,hw,s):
    d=[[1,0],[-1,0],[0,1],[0,-1]]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + d]
    INF=10**12
    path=[[INF]*w for _ in range(h)]
    ans=0
    st=[]
    st=deque()
    st.append((ch,cw,0))
    wp=[]
    wp=deque()
    while st:
      nx,ny,ncost=st.popleft()
      wp.append((nx,ny,ncost))
      path[nx][ny]=ncost
      for dx,dy in d:
        x=nx+dx
        y=ny+dy
        if (0<=x<=h-1) and (0<=y<=w-1):
          if s[x][y]!='#' and path[x][y]>ncost:
            path[x][y]=ncost
            st.append((x,y,ncost))
      if len(st)==0:
        while wp:
          nx,ny,ncost=wp.popleft()
          for dx,dy in warp:
              x,y=nx+dx,ny+dy
              if (0<=x<=h-1) and (0<=y<=w-1):
                if s[x][y]!='#' and path[x][y]>ncost+1:
                  path[x][y]=ncost+1
                  st.append((x,y,ncost+1))
    if path[dh][dw]==INF:
      print(-1)
    else:
      print(path[dh][dw])

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    from collections import deque
    h,w=map(int,input().split())
    ch,cw=map(int,input().split())
    dh,dw=map(int,input().split())
    ch-=1
    cw-=1
    dh-=1
    dw-=1
    s=[input() for _ in range(h)]
    solve(h,w,ch,cw,dh,dw,s)
### BUGGY CODE ###

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

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

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

A.sort(reverse=True)
B.sort(reverse=True)

big_B = []

for b in B:
    if max(A) <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        while damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

### FIXED CODE ###

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

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

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

A.sort(reverse=True)
B.sort(reverse=True)

big_B = []

ma_A = max(A)
for b in B:
    if ma_A <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        if damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)
### BUGGY CODE ###

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


for q in range(Q):
    b, c = map(int, input().split())
    ind = [i for i, x in enumerate(A) if x==b]
    for i in ind :
        A[i] = c
    print(sum(A))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
Q = int(input())
ans = []
s = sum(A)
for _ in range(Q):
    b, c = map(int, input().split())
    n = cnt[b]
    if b in cnt:
        cnt[c] += cnt[b]
        del cnt[b]
    s += (c-b)*n
    print(s)
### BUGGY CODE ###

N=int(input())
A=[int(_) for _ in input().split()]
X=[]
for i in range(N):
    x=0
    for j in range(N):
        if ((j-i)%N)%2==0:
            x+=A[j]
        else:
            x-=A[j]
    X.append(x)
print(' '.join(map(str, X)))

### FIXED CODE ###

N=int(input())
A=[int(_) for _ in input().split()]
X=[]
x=0
for j in range(N):
    if (j%N)%2==0:
        x+=A[j]
    else:
        x-=A[j]
X.append(x)
for i in range(1,N):
    x=2*A[i-1]-X[i-1]
    X.append(x)
print(' '.join(map(str, X)))
### BUGGY CODE ###

S = list(input())

def check_S():
    check = S[0]
    for char in S:
        if check != char:
            return True
    return False

count = 0
while check_S():
    check = S[0]
    k = 0
    if check == 'B':
        while S[k] == 'B':
            S[k] = 'W'
            k += 1
    elif check == 'W':
        while S[k] == 'W':
            S[k] = 'B'
            k += 1
    count += 1

print(count)

### FIXED CODE ###

S = list(input())

count = 0
check = S[0]
for i in range(1, len(S)):
    if check != S[i]:
        count += 1
        check = S[i]

print(count)
### BUGGY CODE ###

def main():
	n, m, *L = map(int, open(0).read().split())
	AB = L[:2 * m]
	Q = L[2 * m + 1:][::-1]
	G = [[] for _ in range(n)]
	C = [0] * n
	D = [-1] * n
	for a, b in zip(*[iter(AB)] * 2):
		a -= 1
		b -= 1
		G[a] += [b]
		G[b] += [a]
	for c, d, v in zip(*[iter(Q)] * 3):
		q = [(v - 1, d)]
		while q:
			cur, dd = q.pop(0)
			if not C[cur]:
				C[cur] = c
			if not dd:
				continue
			for nxt in G[cur]:
				if D[nxt] >= dd:
					continue
				q.append((nxt, dd - 1))
	print("\n".join(map(str, C)))

if __name__=="__main__":
	main()

### FIXED CODE ###

def main():
	n, m, *L = map(int, open(0).read().split())
	AB = L[:2 * m]
	Q = L[2 * m + 1:][::-1]
	G = [[] for _ in range(n)]
	C = [0] * n
	D = [-1] * n
	for a, b in zip(*[iter(AB)] * 2):
		a -= 1
		b -= 1
		G[a] += [b]
		G[b] += [a]
	for c, d, v in zip(*[iter(Q)] * 3):
		if D[v - 1] >= d:
			continue
		D[v - 1] = d
		q = [v - 1]
		while q:
			cur = q.pop()
			dd = D[cur]
			if not C[cur]:
				C[cur] = c
			if not dd:
				continue
			for nxt in G[cur]:
				if D[nxt] >= dd - 1:
					continue
				D[nxt] = dd - 1
				q.append(nxt)
	print("\n".join(map(str, C)))

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

base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
h = dict()
while q:
    p = [ord(c) for c in input().strip()]
    pl = len(p)
    if pl > tl:
        print(0)
        q -= 1
        continue
    bs = min(20, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    print(1 if keys.issubset(h[bs]) else 0)
    q -= 1

### FIXED CODE ###

base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
ps = [input().strip() for _ in range(q)]
h = dict()
a = []
hash_len = 19
for p in ps:
    p = [ord(c) for c in p]
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(hash_len, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    a.append(1 if keys.issubset(h[bs]) else 0)
print('\n'.join(map(str, a)))
### BUGGY CODE ###

import numpy as np
n = int(input())
#a = np.array(list(map(int, input().split())))
a = list(map(int, input().split()))

d = {a.index(i)+1: i for i in a}
#print(d)
d_sorted = sorted(d.items(), key=lambda x:x[1])
#print(d_sorted)
for i in d_sorted:
  print(i[0], end=' ')
'''
#sorted_a = np.sort(a)
#print(sorted_a)
print(a)
for i in range(n):
  #print(min(a))
  print((a.index(min(a)) + 1))
  a.remove(min(a))
  '''
  
'''
inds = [i for i in range(n)]
sorted_inds = sorted(inds)
print('sorted_inds={}'.format(sorted_inds))
sorted_a = [a[i] for i in sorted_inds]
for i in sorted_a:
  print(i, end=' ')
'''

### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i in range(n):
  ans[a[i]-1] = i + 1
for i in ans:
  print(i, end=' ')
### BUGGY CODE ###

import copy

H, W = map(int, input().split())
grid = [[1 if c == "." else 0 for c in input()] for _ in range(H)]

L = copy.deepcopy(grid)
R = copy.deepcopy(grid)
U = copy.deepcopy(grid)
D = copy.deepcopy(grid)

for i in range(H):
  for j in range(1, W):
    L[i][j] = (L[i][j-1] + 1) * L[i][j]
    R[i][-1-j] = (R[i][-j] + 1) * R[i][-1-j]

for j in range(W):
  for i in range(1, H):
    U[i][j] = (U[i-1][j] + 1) * U[i][j]
    D[-1-i][j] = (D[-i][j] + 1) * D[-1-i][j]

ans = 0

for i in range(H):
  for j in range(W):
    ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3, 0)

print(ans)


### FIXED CODE ###

import copy

H, W = map(int, input().split())
grid = [[1 if c == "." else 0 for c in input()] for _ in range(H)]

L = copy.deepcopy(grid)
R = copy.deepcopy(grid)
U = copy.deepcopy(grid)
D = copy.deepcopy(grid)

for i in range(H):
  for j in range(1, W):
    L[i][j] = (L[i][j-1] + 1) * L[i][j]
    R[i][-1-j] = (R[i][-j] + 1) * R[i][-1-j]

for j in range(W):
  for i in range(1, H):
    U[i][j] = (U[i-1][j] + 1) * U[i][j]
    D[-1-i][j] = (D[-i][j] + 1) * D[-1-i][j]

ans = 0

for i in range(H):
  for j in range(W):
    ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3, 0)

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

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ans=0
while(True):
    flag=0
    for i in range(N):
        tmp=B[(i-1)%N]+B[(i+1)%N]
        if B[i]>tmp and B[i]>A[i]:
            flag=1
            ans+=1
            B[i]-=tmp
    if flag==0:
        break
flag2=1
for i in range(N):
    if A[i]!=B[i]:
        flag2=0
        break
if flag2:
    print(ans)
else:
    print(-1)


### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ans=0
while(True):
    flag=0
    #print(B)
    for i in range(N):
        tmp=B[(i-1)%N]+B[(i+1)%N]
        if B[i]>tmp>0 and B[i]>A[i]:
            beforeans=ans
            if B[i]%tmp>=A[i]:
                ans+=B[i]//tmp
                B[i]%=tmp
            else:
                k=((A[i]-1-(B[i]%tmp))//tmp)+1
                ans+=B[i]//tmp
                B[i]%=tmp
                #print(i,1,B)
                ans-=k
                B[i]+=k*tmp
                #print(i,2,B)
            if ans!=beforeans:
                flag=1
    if flag==0:
        break
flag2=1
for i in range(N):
    if A[i]!=B[i]:
        flag2=0
        break
if flag2:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li2 = []
for i in range(1,len(li)+1):
    s = li.index(i)
    li2.append(s+1)

print(' '.join(map(str, li2)))

### FIXED CODE ###

from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li2 = [0 for _ in range(n)]
for i in range(len(li)):
    li2[li[i]-1] = i+1
print(' '.join(map(str, li2)))
### BUGGY CODE ###

N = int(input())
s = []
for _ in range(N):
    s.append(input())

count = 0
for i in range(N):
    for j in range(i+1, N):
        if sorted(s[i]) == sorted(s[j]):
            count+=1

print(count)

### FIXED CODE ###

N = int(input())
S = {}

for i in range(N):
    str = ''.join(sorted(input()))
    if str in S.keys():
        S[str] += 1
    else:
        S.setdefault(str, 1)

cnt = 0
for v in S.values():
    cnt += (v * (v-1) // 2)

print(cnt)
### BUGGY CODE ###

import sys

N, M = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))
A = []
B = []
for i in range(M):
    temp_A, temp_B = map(int, sys.stdin.readline().split())
    A.append(temp_A)
    B.append(temp_B)

list2 = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    list2[A[i]-1][B[i]-1] = 1
    list2[B[i]-1][A[i]-1] = 1

count = N
for i in range(N):
    for j in range(N):
        if list2[i][j] == 1 and H[i] <= H[j]:
            count = count - 1
            break
print(count)



### FIXED CODE ###

import sys

N, M = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))
A = []
B = []
for i in range(M):
    temp_A, temp_B = map(int, sys.stdin.readline().split())
    A.append(temp_A)
    B.append(temp_B)

dame = []
for i in range(M):
    if H[B[i]-1] > H[A[i]-1]:
        dame.append(A[i])
    if H[A[i]-1] > H[B[i]-1]:
        dame.append(B[i])
    if H[A[i]-1] == H[B[i]-1]:
        dame.append(A[i])
        dame.append(B[i])
print(N - len(set(dame)))
### BUGGY CODE ###

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

def factorization(n):
    arr = set()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.add(i)

    if temp!=1:
        arr.add(temp)

    if arr==[]:
        arr.add(n)

    return arr

com={}
rem={}

for i in range(N):
  if i ==0:
    rem=factorization(A[i])
  else:
    rem=rem&factorization(A[i])

for i in range(N):
  if i ==0:
    com=factorization(A[i])
  else:
    if com&factorization(A[i])==set() or com&factorization(A[i])=={1}:
      com=com.union(factorization(A[i]))
    else:
      com={0}
      break
    
if com!={0}:
  print("pairwise coprime")
elif rem==set() or rem=={1}:
  print("setwise coprime")
else:
  print("not coprime")

### FIXED CODE ###

import math

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

a=max(A)
def era(n):
  prime=[]
  furui=list(range(2,n+1))
  while furui[0]<math.sqrt(n):
    prime.append(furui[0])
    furui=[i for i in furui if i%furui[0]!=0]
  return prime+furui

b=A[0]
for i in range(1,N):
  b=math.gcd(b,A[i])

if b!=1:
  print("not coprime")
  exit()

furui=era(10**6+7)
minfac=list(range(10**6+7))
for i in furui:
  for j in range(i,(10**6+7)//i):
    if minfac[i*j]==i*j:
      minfac[i*j]=i
      
dummy=[False]*(10**6+7)
for i in range(N):
  k=A[i]
  while k!=1:
    if dummy[minfac[k]]==True:
      print("setwise coprime")
      exit()
    else:
      dummy[minfac[k]]=True
      f=minfac[k]
      while k%f==0:
        k//=f
print("pairwise coprime")
### BUGGY CODE ###

def z_algo(s: str) -> list:
    """LCP(0,i)のlist"""
    N = len(s)
    ret = [-1] * N
    ret[0] = N
    i, j = 1, 0
    while i < N:
        while i + j < N and s[j] == s[i + j]:
            j += 1
        ret[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < N and k + ret[k] < j:
            ret[i + k] = ret[k]
            k += 1
        i += k
        j -= k
    return ret


def main():
    N = int(input())
    S = input()

    ret = 0
    t = ''
    for c in reversed(S):
        t = c + t
        lcp = z_algo(t)
        for diff, len_ in enumerate(lcp):
            ret = max(ret, min(diff, len_))
    print(ret)


if __name__ == '__main__':
    main()


### FIXED CODE ###

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

dp = [[0] * (n + 1) for _ in range(n + 1)]

res = 0
for i in range(n - 1, -1, -1):
    for j in range(n - 1, i, -1):
        if s[i] == s[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
            # dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)
        res = max(res, min(dp[i][j], j - i))
print(res)