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

import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()
q = iinput()
cnt = 0
for i in range(q):
    try: t,f,c = sarr()
    except: cnt += 1; cnt %= 2; continue
    if cnt:
        if f == "1": s = s + c
        if f == "2": s = c + s
    else:
        if f == "1": s = c + s
        if f == "2": s = s + c
    #print(s)

s = s[::-1] if cnt else s
print(s)



### FIXED CODE ###

import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = col.deque(sinput().split())
q = iinput()
cnt = 0
for i in range(q):
    try: t,f,c = sarr()
    except: cnt += 1; cnt %= 2; continue
    if cnt: #反転の状態
        if f == "1": s.append(c)
        if f == "2": s.appendleft(c)
    else: #ノーマル状態
        if f == "1": s.appendleft(c)
        if f == "2": s.append(c)
    #print(s)

s = "".join(s)
s = s[::-1] if cnt else s
print(s)
### BUGGY CODE ###

def main():
    N = int(input())
    S = list(input().strip() for _ in range(N))
    print(solve(S))

def get_count(s):
    result = [0, 0]
    cum_sum = 0
    for c in s:
        if c == ')':
            cum_sum -= 1
        else:
            cum_sum += 1
        result[0] = max(result[0], -cum_sum)
    result[1] = result[0] + cum_sum
    return result

def solve(S):
    counts = list(map(get_count, S))
    first_groups = sorted(filter(lambda c: c[0] - c[1] <= 0, counts), key=lambda c: c[0])
    second_groups = sorted(filter(lambda c: c[0] - c[1] > 0, counts), key=lambda c: -c[1])
    order = first_groups + second_groups

    cum_sum = 0
    for c in order:
        cum_sum -= c[0]
        if cum_sum < 0:
            return 'No'
        cum_sum += c[1]
    if cum_sum == 0:
        return 'Yes'
    return 'No'

if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import chain
import sys

def main():
    N = int(input())
    # TLEs were caused mostly by slow input (1s+)
    # S = list(input() for _ in range(N))
    S = sys.stdin.read().split('\n')
    print(solve(S))

def get_count(args):
    s, result = args # messy input to work with map.
    cum_sum = 0
    for c in s:
        if c == ')':
            cum_sum -= 1
        else:
            cum_sum += 1
        result[0] = max(result[0], -cum_sum)
    result[1] = result[0] + cum_sum
    return result

# Made-up name, don't remember what to call this. Radix-ish
def silly_sort(array, value_min, value_max, get_value):
    if len(array) == 0:
        return
    cache = [None for _ in range(value_max - value_min + 1)]
    for elem in array:
        # Assume elem[0] is the value
        value = get_value(elem) - value_min
        if cache[value] is None:
            cache[value] = []
        cache[value].append(elem)
    for values in cache:
        if values is None:
            continue
        for value in values:
            yield value

def solve(S):
    counts = [[0,0] for _ in range(len(S))]
    counts = list(map(get_count, zip(S,counts)))
    first_group = []
    second_group = []
    min_first_group = float('inf')
    max_first_group = 0
    min_second_group = float('inf')
    max_second_group = 0

    for c in counts:
        if c[0] - c[1] <= 0:
            first_group.append(c)
            max_first_group = max(max_first_group, c[0])
            min_first_group = min(min_first_group, c[0])
        else:
            second_group.append(c)
            max_second_group = max(max_second_group, c[1])
            min_second_group = min(min_first_group, c[1])
    first_group = silly_sort(first_group, min_first_group, max_first_group, lambda c: c[0])
    second_group = reversed(list(silly_sort(second_group, min_second_group, max_second_group, lambda c: c[1])))

    order = chain(first_group, second_group)

    cum_sum = 0
    for c in order:
        cum_sum -= c[0]
        if cum_sum < 0:
            return 'No'
        cum_sum += c[1]
    if cum_sum == 0:
        return 'Yes'
    return 'No'

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

import bisect
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
for i in range(M):
  B = A.pop()
  bisect.insort_left(A,B//2)
print(sum(A))

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(lambda x: int(x)*(-1),input().split()))
import heapq
heapq.heapify(A)
for i in range(M):
  B = heapq.heappop(A)
  heapq.heappush(A,-1*((-B)//2))
print(-sum(A))
### BUGGY CODE ###

N = int(input())

for i in range(1,3500+1):
    for j in range(1,3500+1):
        h = i
        n = j
        
        low = 1
        high = 3500
        
        while low+1 < high:
            mid = (low + high) //2
            
            if 4*h*n*mid >= N*(n*mid+h*n+mid*h):
                high = mid
            else:
                low = mid
                
        if 4*h*n*high == N*(n*high+h*n+high*h):
            print(h,n,high)
            exit()
        


### FIXED CODE ###

N = int(input())

for i in range(1,3500+1):
    for j in range(1,3500+1):
        h = i
        n = j
        
        low = 1
        high = 3500
        
        if N*n+N*h-4*h*n == 0:
            continue
        if N*h*n % (N*n+N*h-4*h*n) == 0:
            w = -N*h*n // (N*n+N*h-4*h*n)
            if w > 0:
                print(h,n,w)
                exit()
### BUGGY CODE ###

import math
a, b, n = map(int, input().split())
arr = [0]
ans = 0
for i in range(n):
  x = i + 1
  if math.floor(a * x / b) - a * math.floor(x / b) < arr[-1]:
    ans = arr[-1]
    break
  else:
    arr.append(math.floor(a * x / b) - a * math.floor(x / b))
    ans = arr[-1]
ans = max(arr)
print(ans)

### FIXED CODE ###

import math
a, b, n = map(int, input().split())
x = min(b - 1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
print(ans)
### BUGGY CODE ###

def dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5


def dist_high(index1, index2):
    return max(dist(
            xyr[index1][0],
            xyr[index1][1],
            xyr[index2][0],
            xyr[index2][1]) - (xyr[index1][2] + xyr[index2][2]), 0)


def min_value_index(array):
    min_value = float("inf")
    min_index = -1
    for v, i in array:
        if min_value > v:
            min_value = v
            min_index = i
    return min_value, min_index

stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [[stx, sty, 0]] + [list(map(int, input().split())) for x in range(n)] + [[enx, eny, 0]]

nodes = [float("inf") for x in range(1002)]
nodes[0] = 0
now = 0
ends = []

while now != (len(xyr) - 1):
    ends.append(now)
    nexts = []
    for i in range(len(xyr)):
        if i == now:
            continue

        nodes[i] = min(nodes[i], nodes[now] + dist_high(now, i))
        nexts.append([nodes[i], i])
    now = min_value_index(filter(lambda x: x[1] not in ends, nexts))[1]
print(nexts[-1][0])


### FIXED CODE ###

def dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5


def dist_high(index1, index2):
    return max(dist(
            xyr[index1][0],
            xyr[index1][1],
            xyr[index2][0],
            xyr[index2][1]) - (xyr[index1][2] + xyr[index2][2]), 0)


def min_value_index(array):
    min_value = float("inf")
    min_index = -1
    for i, v in array:
        if min_value > v:
            min_value = v
            min_index = i
    return min_value, min_index

stx, sty, enx, eny = map(int, input().split())
n = int(input())
xyr = [[stx, sty, 0]] + [list(map(int, input().split())) for x in range(n)] + [[enx, eny, 0]]

nodes = {x: float("inf") for x in range(len(xyr))}
nodes[0] = 0
now = 0

while now != (len(xyr) - 1):
    for i in nodes.keys():
        if i == now:
            continue

        nodes[i] = min(nodes[i], nodes[now] + dist_high(now, i))
    del nodes[now]
    now = min_value_index(nodes.items())[1]
print(nodes[n + 1])
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
already_town =[1]
now_town=1
check=False
for i in range(K):
    if(A[now_town-1] in already_town):
        cicle_start_value=A[now_town-1]
        check=True
        break
    already_town.append(A[now_town-1])
    now_town = A[now_town-1]

if(check==False):
    print(now_town)
else:
    cicle_start=already_town.index(cicle_start_value)
    roop_town=already_town[cicle_start:]
    print(roop_town[(K-cicle_start)%((i+1)-cicle_start)])




### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
already_town_check =[False]*(N+1)
already_town_check[1] = True
already_town = [1]
now_town=1
check=False
my_append = already_town.append
for i in range(K):
    check_town=A[now_town-1]
    if(already_town_check[check_town]):
        cicle_start_value=check_town
        check=True
        break
    already_town_check[check_town]=True
    my_append(check_town)
    now_town = check_town

if(check==False):
    print(now_town)
else:
    cicle_start=already_town.index(cicle_start_value)
    roop_town=already_town[cicle_start:]
    print(roop_town[(K-cicle_start)%((i+1)-cicle_start)])
### BUGGY CODE ###

import sys
import bisect
import heapq
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
for i in range(m):
    b, c = [int(i) for i in sys.stdin.readline().split()]
    ind = bisect.bisect_left(a_ls, c)
    a_ls = (a_ls[:ind] + [c] * b + a_ls[ind:])[-n:]
print(sum(sorted(a_ls)[-n:]))

### FIXED CODE ###

import sys
from collections import Counter
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
ls = []
for j in range(m):
    b, c = [int(i) for i in sys.stdin.readline().split()]
    if ct.get(c) is None:
        ct[c] = 0
    ls.append((b, c))
    ct[c] += b
ls.sort(key=lambda x:x[1], reverse=True)
cnt = 0
for b, c in ls:
    if cnt + b < n:
        a_ls += [c] * b
        cnt += b
    else:
        a_ls += [c] * (n - cnt)
        break
a_ls.sort()
print(sum(a_ls[-n:]))
### BUGGY CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


s = input()

n = ii()
r = 0
head = ''
tail = ''
for i in range(n):
    q = input().split()

    if(q[0] == '1'):
        # reverse
        r += 1
    else:
        if(q[1] == '1'):
            if(r%2 ==0):
                s = q[2] + s
            else:
                s = s + q[2]
        else:
            if(r%2 ==0):
                s = s + q[2]
            else:
                s = q[2] + s
    

if(r%2==1):
    s = s[::-1]


print( s )


### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


s = input()

n = ii()
r = 0
head = ''
tail = ''
for i in range(n):
    q = input().split()

    if(q[0] == '1'):
        # reverse
        r += 1
    else:
        if(q[1] == '1'):
            if(r%2 ==0):
                # s = q[2] + s
                head = q[2] + head
            else:
                # s = s + q[2]
                tail = tail + q[2]
        else:
            if(r%2 ==0):
                # s = s + q[2]
                tail = tail + q[2]
            else:
                # s = q[2] + s
                head = q[2] + head

    # print('*********************',i,head,tail)
    

if(r%2==1):
    # s = s[::-1]
    # print('rev')
    print( tail[::-1] + s[::-1]+ head[::-1])
else:

    print(head +  s + tail)
### BUGGY CODE ###

def main():
    n = int(input())
    w1 = list(map(int,input().split()))
    w2 = list(map(int,input().split()))
    v1 = [0,0,0]
    for i in range(3):
        v1[i] = w2[i] - w1[i]
    dp1 = [0] * (n+1)
    for i in range(n):
        p = 0
        q = 0
        r = 0
        if i+1 - w1[0] >= 0:
            p = dp1[i+1 - w1[0]] + v1[0]
        if i+1 - w1[1] >= 0:
            q = dp1[i+1 - w1[1]] + v1[1]
        if i+1 - w1[2] >= 0:
            r = dp1[i+1 - w1[2]] + v1[2]
        dp1[i+1] = max(p,q,r,dp1[i])
    m = dp1[-1] + n

    v2 = [0,0,0]
    for i in range(3):
        v2[i] = w1[i] - w2[i]
    dp2 = [0] * (m+1)
    for i in range(m):
        p = 0
        q = 0
        r = 0
        if i+1 - w2[0] >= 0:
            p = dp2[i+1 - w2[0]] + v2[0]
        if i+1 - w2[1] >= 0:
            q = dp2[i+1 - w2[1]] + v2[1]
        if i+1 - w2[2] >= 0:
            r = dp2[i+1 - w2[2]] + v2[2]
        dp2[i+1] = max(p,q,r,dp2[i])
    print(m + dp2[-1])
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    w1 = list(map(int,input().split()))
    w2 = list(map(int,input().split()))
    v1 = [0,0,0]
    for i in range(3):
        v1[i] = w2[i] - w1[i]
    dp1 = [0] * (n+1)
    for i in range(n):
        p = 0
        q = 0
        r = 0
        if i+1 - w1[0] >= 0:
            p = dp1[i+1 - w1[0]] + v1[0]
        if i+1 - w1[1] >= 0:
            q = dp1[i+1 - w1[1]] + v1[1]
        if i+1 - w1[2] >= 0:
            r = dp1[i+1 - w1[2]] + v1[2]
        dp1[i+1] = max(p,q,r,dp1[i])
    m = dp1[-1] + n

    v2 = [0,0,0]
    for i in range(3):
        v2[i] = w1[i] - w2[i]
    dp2 = [0] * (m+1)
    for i in range(m):
        p = 0
        q = 0
        r = 0
        if i+1 - w2[0] >= 0:
            p = dp2[i+1 - w2[0]] + v2[0]
        if i+1 - w2[1] >= 0:
            q = dp2[i+1 - w2[1]] + v2[1]
        if i+1 - w2[2] >= 0:
            r = dp2[i+1 - w2[2]] + v2[2]
        dp2[i+1] = max(p,q,r,dp2[i])
    print(m + dp2[-1])
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# スペース区切りの整数の入力

n = int(input())

cnt = 0
pre = ['753', '735', '573', '537', '375', '357']

for i in range(n):

    l = [s for s in str(i+1)]
    
    #print(set(l))
    uni = ''.join(set(l))
    
    for p in pre:
        if uni == p : 
            cnt+=1
            #print(uni)
            break
            
print(cnt)

### FIXED CODE ###

n = int(input())
cnt = 0

def out(s):
    
    i_s = int(s)
    if i_s <= n:
        #7, 5, 3が1以上出現する
        if all([True if str(i_s).count(s) > 0 else False for s in '753']):
            global cnt
            #print(i_s)
            cnt +=1 
            #7, 5, 3を引っ付ける
            
        [out(str(i_s) + s) for s in '753']

out('0')
print(cnt)
### BUGGY CODE ###

# coding: utf-8
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

R,G,B,N = map(int, input().split())

if R<G: R,G=G,R
if G<B: G,B=B,G
if R<G: R,G=G,R

r=g=b=0
ans=0

#p(N//R+2)
#p(N//G+2)
#X=[]
#p(r,g,b)

for r in range(N//R+2):
	if (R*r)>N: break

	for g in range(N//G+2):
		if (R*r)+(G*g)>N:
			break
			X.append("break")
		
		b = (N-(R*r)-(G*g))//B
		n = (R*r)+(G*g)+(B*b)
		if n==N:
			ans+=1
#			X.append([r,g,b])
#		p(r,g,b,n,N,ans)

print(ans)
#p(X)


### FIXED CODE ###

# coding: utf-8
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

R,G,B,N = map(int, input().split())


r=g=b=0
ans=0

#p(N//R+2)
#p(N//G+2)
#X=[]
#p(r,g,b)

for r in range(N//R+2):
	if (R*r)>N: break

	for g in range(N//G+2):
		if (R*r)+(G*g)>N:
			break
			X.append("break")
		
		b = (N-(R*r)-(G*g))//B
		n = (R*r)+(G*g)+(B*b)
		if n==N:
			ans+=1
#			X.append([r,g,b])
#		p(r,g,b,n,N,ans)

print(ans)
#p(X)
### BUGGY CODE ###

import sys
import numpy as np

input = sys.stdin.readline

h, w = map(int, input().split())
map_arr1d = np.array([0 if s == '#' else 1 for _ in range(h) for s in input()[:-1]])
map_2d = map_arr1d.reshape(h, w)

h_map = []
for h_arr in map_2d:
    cnt = 0
    tmp_list = []
    for a in h_arr:
        if a == 0:
            if cnt > 0:
                tmp_list.extend([cnt]*cnt)
                cnt = 0
            tmp_list.append(0)
        else:
            cnt += 1
    if cnt > 0:
        tmp_list.extend([cnt]*cnt)
    h_map.extend(tmp_list)
h_map = np.array(h_map).reshape(h, w)

w_map = []
for w_arr in map_2d.T:
    cnt = 0
    tmp_list = []
    for a in w_arr:
        if a == 0:
            if cnt > 0:
                tmp_list.extend([cnt]*cnt)
                cnt = 0
            tmp_list.append(0)
        else:
            cnt += 1
    if cnt > 0:
        tmp_list.extend([cnt]*cnt)
    w_map.extend(tmp_list)
w_map = np.array(w_map).reshape(w, h).T
print((h_map + w_map).max()-1)


### FIXED CODE ###

import sys

input = sys.stdin.readline

h, w = map(int, input().split())
map_list = [[0 if s == '#' else 1 for s in input()[:-1]] for _ in range(h)]

h_map = []
for h_list in map_list:
    cnt = 0
    tmp_list = []
    for a in h_list:
        if a == 0:
            if cnt > 0:
                tmp_list.extend([cnt]*cnt)
                cnt = 0
            tmp_list.append(0)
        else:
            cnt += 1
    if cnt > 0:
        tmp_list.extend([cnt]*cnt)
    h_map.append(tmp_list)

w_map = []
for w_arr in [list(x) for x in zip(*map_list)]:
    cnt = 0
    tmp_list = []
    for a in w_arr:
        if a == 0:
            if cnt > 0:
                tmp_list.extend([cnt]*cnt)
                cnt = 0
            tmp_list.append(0)
        else:
            cnt += 1
    if cnt > 0:
        tmp_list.extend([cnt]*cnt)
    w_map.append(tmp_list)
w_map = [list(x) for x in zip(*w_map)]
max_l = 0
for h_list, w_list in zip(h_map, w_map):
    for h_num, w_num in zip(h_list, w_list):
        max_l = max(max_l, h_num + w_num)
print(max_l - 1)
### BUGGY CODE ###

X,K,D=map(int,input().split())
def walk(place,D):
    A=place-D
    B=place+D
    if abs(A)>abs(B):
        return B
    else: 
        return A

for i in range(K):
    X=walk(X,D)
print(abs(X))

### FIXED CODE ###

X,K,D=map(int,input().split())
step=-(-abs(X) // D)
if (abs(X)-step*D)>(abs(X)-(step-1)*D):
    step=step-1
if step>=K:
    print(abs(abs(X)-K*D))
else:
    if (K-step)%2==0:
        print(abs(abs(X)-step*D))
    else:
        print(D-abs(abs(X)-step*D))
### BUGGY CODE ###

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


cut = N
check =0
min = N

for i in range(1,N+1):
    
    if List[i-1]<=min:
        min = List[i-1]
        
        for k in range(1,i+1):
            if List[k-1]<List[i-1]:
                check = 1
                break
        if check==1:
            cut -= 1
        check = 0

    else:
        cut -=1

    




print(cut)

### FIXED CODE ###

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


cut = N
check =0
min = N

for i in range(1,N+1):
    
    if List[i-1]<=min:
        min = List[i-1]
        
    else:
        cut -=1

    




print(cut)
### BUGGY CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict

n = ni()
s = ns()

dic = defaultdict(list)

for st in range(n):
    for ed in range(st+1, min(st+n//2+2, n+1)):
        dic[s[st:ed]].append(st)

ans = 0
for stri, stsi in dic.items():
    if len(stsi) <= 1:
        continue

    if stsi[-1] - stsi[0] >= len(stri):
        ans = max(ans, len(stri))

print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


class RollingHash(object):
    def __init__(self, source: str, base=10**9+7, mod=(1<<64)-1):
        self.source = source
        self.base = base
        self.mod = mod
        self.hash_from_zero_to = self._get_hash_from_zero_to()
        self.base_pow = self._get_base_pow()

    # 文字列sourceの区間 [0, right) のハッシュ値を前計算する
    def _get_hash_from_zero_to(self):
        hash_from_zero_to = [0]
        for si in self.source:
            hash_from_zero_to.append((hash_from_zero_to[-1] * self.base + ord(si)) % self.mod)

        return hash_from_zero_to

    # base値をi回掛けてmodをとった値を前計算する
    def _get_base_pow(self):
        base_pow = [1]
        for i in range(len(self.source)):
            base_pow.append(base_pow[-1] * self.base % self.mod)

        return base_pow

    # 文字列sourceの区間 [left, right) のハッシュを取得する
    def get_hash(self, left: int, right: int):
        return (self.hash_from_zero_to[right]
                - self.hash_from_zero_to[left] * self.base_pow[right - left]) % self.mod


def binsearch(func, rh: RollingHash, ok: int, ng: int):
    source_length = len(rh.source)
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if func(rh, mid, source_length):
            ok = mid
        else:
            ng = mid

    return ok


# 題意を満たす長さtarget_lengthの文字列があるか判定
def judge(rh: RollingHash, target_length: int, source_length: int):
    memo = {}
    for start_idx in range(source_length - target_length + 1):
        cur_hash = rh.get_hash(start_idx, start_idx + target_length)
        if cur_hash in memo:
            if start_idx - memo[cur_hash] >= target_length:
                return True
        else:
            memo[cur_hash] = start_idx

    return False


n = ni()
s = ns()

rh = RollingHash(s)
print(binsearch(judge, rh, 0, n//2 + 2))