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

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

ans = 1

for a in A:
    ans *= a
    
    if 0 in A:
        ans = 0
        break
    elif ans > 10**18:
        ans = -1
        break
    
print(ans)

### FIXED CODE ###

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

if 0 in A:
        ans = [0]
else:
    ans = [1]*N
    
    for i,a in enumerate(A):
        if i==0:
            ans[i] = a
        else:
            ans[i] = ans[i-1]*a

        if ans[i] > 10**18:
            ans[-1] = -1
            break
    
print(ans[-1])
### BUGGY CODE ###

s = input() #sys.stdin.readlineは最後が改行
n =len(s)

num=0
tmp=0

amari= [0]

for i in range(n):
    num = tmp + int(s[-1-i])*(10**(i))
    tmp = num%2019
    amari.append(tmp)

from collections import Counter
ctr = Counter(amari)
ans = 0
for val in ctr.values():
        ans += val*(val-1)//2
print(ans)

### FIXED CODE ###

s = input() #sys.stdin.readlineは最後が改行
n =len(s)

from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0
tmp=0
ans =0

for i in range(n):
    num = tmp + int(s[-1-i])*pow(10,i,2019)
    tmp = num%2019
    amari[tmp]+=1

    if amari[tmp]>1:
        val = amari[tmp]
        ans -= (val-1)*(val-2)//2
        ans += (val)*(val-1)//2

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

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

    maks = 10**18
    mnozenje = 1
    for i in a:
        mnozenje *= i
        
    if mnozenje > maks:
        print(-1)
    else:
        print(mnozenje)


if __name__ == '__main__':
    main()


### FIXED CODE ###

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

    if 0 in a:
        print(0)
        return

    maks = 10**18
    mnozenje = 1
    for i in a:
        mnozenje *= i

        if mnozenje > maks:
            print(-1)
            return

    print(mnozenje)


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




import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    sosus = set(get_primes(max(A)+1))
    dvd = set()

    for i in A:
        tmp = set()
        for j in sosus:
            if i % j ==0:
                tmp.add(j)

                while i % j ==0:
                    i //=j
        sosus.difference_update(tmp)
        
        if i != 1:
            break
    else:
        print('pairwise coprime')
        return

    val = A[0]
    for i in A:
        val = math.gcd(i,val)

    if val ==1:
        print('setwise coprime')
    else:
        print('not coprime')

resolve()

### FIXED CODE ###


import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        A = [i for i in A if i%prime!=0]

    P.extend(A)
          
    return P


def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    sosus = set(get_primes(max(A)+1))
    dvd = set()



    val = A[0]
    for i in A:
        val = math.gcd(i,val)

    if val ==1:
        pass
    else:
        print('not coprime')
        return

    for i in A:
        tmp=[]
        for j in sosus:
            if j>i:
                break
            if i % j ==0:
                tmp.append(j)
                while i % j ==0:
                    i //=j
            if i ==1:
                break
            if i in sosus:
                
                tmp.append(i)
                i = 1
                break
        sosus.difference_update(tmp)
        
        if i != 1:
            break
    else:
        print('pairwise coprime')
        return

    print('setwise coprime')

resolve()
### BUGGY CODE ###

n=int(input())
S=set()
for i in range(n):
  S=S^set([int(input())])
print(len(S))

### FIXED CODE ###

n=int(input())
S=set()
for i in range(n):
  S^=set([input()])
print(len(S))
### BUGGY CODE ###

import math , sys
N = int( input() )

X = []
for i in range(N):
    A , B = list(map(int, input().split()))
    X.append([i , A-B , A , A+B])


X.sort(key=lambda x: x[3])

Y = X.pop(0)
Ri = Y[-1]
ans = 1

j=0

while len(X)>0:
    Y = X.pop(0)
    if Y[1]>=Ri:
        ans+=1
        Ri = Y[-1]
print(ans)


### FIXED CODE ###

import math , sys
N = int( input() )

X = []
for i in range(N):
    A , B = list(map(int, input().split()))
    X.append([i , A-B , A , A+B])


X.sort(key=lambda x: x[3])

Y = X[0]
Ri = Y[-1]
ans = 1

j=0

for i in range(1,N):
    Y = X[i]
    if Y[1] >= Ri:
        ans+=1
        Ri = Y[-1]
print(ans)
### BUGGY CODE ###

N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort()
#dp = [[0 for _ in range(X+1)] for _ in range(N+1)]
dp = [[0] * (X+1) for _ in range(N+1)]

dp[0] = [x for x in range(X+1)]

for i, n  in enumerate(numbers):
    for x in range(X+1):
        dp[i+1][x] += dp[i][x % n]
        #dp[i+1][x] = dp[i+1][x] % MOD
        
        dp[i+1][x] += dp[i][x] * i #% MOD
        #dp[i+1][x] = dp[i+1][x] % MOD

print(dp[N][X] % MOD)

### FIXED CODE ###

N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort(reverse=True)


dp = {X: 1}

for i, n in enumerate(numbers):
    tmp_dp = {}
    for k, v in dp.items():
        if k < n:
            tmp_dp[k] = (tmp_dp.get(k,0)+v*(N-i))
        else:
            tmp_dp[k]=(tmp_dp.get(k,0)+v*(N-i-1)) 
            tmp_dp[k%n]=(tmp_dp.get(k%n,0)+v) 
    dp = tmp_dp.copy()
        
ans = 0
for k, v in dp.items():
    ans += k *  v

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

line = list(map(int,input().rstrip().split()))
N = line[0]
K = line[1]
A = list(map(int,input().rstrip().split()))
sum =0
while len(A)>=2:
    sum+=1
    A.insert(0,min(A[:K]))
    del A[0:K]
print(sum)

### FIXED CODE ###

import math
N,K = map(int,input().rstrip().split())
print(math.ceil((N-1)/(K-1)))
### BUGGY CODE ###

n = int(input())
travel = list(map(int,input().split()))
plan = travel.copy()
start = 0
answer = 0
answer_list = list()

for i in range(n):
    plan.pop(i)
    for j in range(len(plan)):
        answer += abs(plan[j]-start)
        start = plan[j]
    answer += abs(plan[len(plan)-1])
    answer_list.append(answer)
    answer = 0
    start = 0
    plan = travel.copy()
    
for i in range(len(answer_list)):
    print(answer_list[i])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.insert(0,0)
a.insert(n+1,0)
total=0
#通常のコストを計算
for i in range(1,n+2):
    total+=abs(a[i]-a[i-1])
for i in range(1,n+1):
    ans=total-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))+abs(a[i+1]-a[i-1])
    print(ans)
### BUGGY CODE ###

from itertools import combinations
N, K = map(int, input().split())
P = list(map(int, input().split()))

buy = list(combinations(P, K))
sum_money = [sum(b) for b in buy]
print(min(sum_money))

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
print(sum(P[:K]))
### BUGGY CODE ###

R, G, B, N_1 = map(int, input().split())
cnt = 0

for r in range(N_1//R + 1):
    N_2 = N_1
    N_2 -= r*R
    for g in range(N_2//G + 1):
        N_3 = N_2
        N_3 -= g*G
        for b in range(N_3//B + 1):
            if N_3 == b*B:
                cnt += 1

print(cnt)


### FIXED CODE ###

R, G, B, N_1 = map(int, input().split())
cnt = 0

for r in range(N_1//R + 1):
    N_2 = N_1
    N_2 -= r*R
    for g in range(N_2//G + 1):
        N_3 = N_2
        N_3 -= g*G

        if N_3%B == 0:
            cnt += 1

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

import itertools

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

for i in itertools.combinations(a, 2):
    ans += i[0]*i[1]

print(ans % 1000000007)

### FIXED CODE ###

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

for i in range(n-1):
  num+=a[i]
  ans+=a[i+1]*num
  
print(ans%1000000007)
### BUGGY CODE ###

import copy
length = int(input())
suretsu=[int(input()) for i in range(length)]
result = []
zantei_max = max(suretsu)
for i in range(length):
    if (zantei_max == suretsu[i]):
        copy_suretsu = copy.deepcopy(suretsu)
        del copy_suretsu[i]
        new_max = max(copy_suretsu)
        result.append(str(new_max))
    else:
        result.append(str(zantei_max))
print('\n'.join(result))

### FIXED CODE ###

length = int(input())
suretsu=[int(input()) for i in range(length)]
result = []
sorted_suretsu = sorted(suretsu,reverse=True)
zantei_max = sorted_suretsu[0]

for i in range(length):
    if (zantei_max == suretsu[i]):
        result.append(str(sorted_suretsu[1]))
    else:
        result.append(str(zantei_max))
print('\n'.join(result))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np
from collections import Counter

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

a = Counter(A).values()
B = list(a)
B = np.array(B)
F = [0] * N
for i in range(1,N+1):
    F[i-1] = np.sum(np.minimum(B, i)) / i
num = N
K = 1
while K < N + 1:
    if F[num - 1] >= K:
        print(num)
        K += 1
    else:
        num -= 1
    if num == 0 and K != N + 1:
        for i in range(N-K+1):
            print(0)
        K = N + 1

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import Counter
from itertools import accumulate

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

B = list(Counter(A).values())

C = [0] * N 
for i in B:
    C[i-1] += 1

F = list(accumulate(C))

S = [0] * N
f = [0] * N
S[0] = f[0] = sum(C) 
for i in range(2, N+1):
    S[i-1] = (S[i-2] + C[i-1] + S[0] - F[i-1] ) 
    f[i-1] = S[i-1] / i

f.sort()
n = 0     
K = 1
    
while K != N+1:
    if K <= f[n]:
        print(N-n)
        K += 1
    else:
        n += 1
    if n == N:
        for i in range(N-K+1):
            print(0)
        K = N+1
### BUGGY CODE ###

import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    R, C, K = NMI()
    item = {(0,0):0}

    for i in range(K):
        r_, c_, v_, = NMI()
        item[(r_ - 1,c_ - 1)] = v_

    dp = [[[0 for _ in range(4)] for _ in range(C + 2)] for _ in range(R + 2)]

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                if (i,j) in item:
                    v = item[(i,j)]
                else:
                    v = 0

                if k == 3:
                    dp[i + 1][j][0] = max(dp[i][j][k], dp[i + 1][j][0])
                    continue
                dp[i + 1][j][0] = max(dp[i][j][k], dp[i][j][k] + v, dp[i + 1][j][0])
                dp[i][j + 1][k] = max(dp[i][j][k], dp[i][j + 1][k])
                dp[i][j + 1][k + 1] = max(dp[i][j][k] + v, dp[i][j + 1][k + 1])

    ans = max(dp[R][C][0], dp[R][C][1], dp[R][C][2], dp[R][C][3])
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    R, C, K = NMI()
    item = [[0] * (C + 1) for i in range(R + 1)]

    for i in range(K):
        r_, c_, v_, = NMI()
        item[r_ - 1][c_ - 1] = v_

    dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)]

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                v = item[i][j]

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

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

n,a,b=map(int,input().split())
mod=10**9+7
def fur(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod)%mod
print(((2**n)-1-fur(n,a)-fur(n,b))%mod)

### FIXED CODE ###

n,a,b=map(int,input().split())
mod=10**9+7
def f(k,l):
    ans=1
    for i in range(1,l+1):ans=(ans*(k-i+1)*pow(i,mod-2,mod))%mod
    return ans
print((pow(2,n,mod)-1-f(n,a)-f(n,b))%mod)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = tuple(map(int,input().split()))

dp = [0] + [float("inf")]*(n-1)
for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = tuple(map(int,input().split()))

dp = [0] + [float("inf")]*(n-1)
for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])
### BUGGY CODE ###

import sys
import heapq
n,m=map(int,sys.stdin.readline().split())
a=list(map(int,sys.stdin.readline().split()))
heapq.heapify(a)
for i in range(m):
    b,c=map(int,sys.stdin.readline().split())
    for j in range(b):
        if a[0]<c:
            heapq.heapreplace(a,c)
        else:
            break
print(sum(a))

### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1],reverse=True)
for b,c in bc:
    a.extend([c]*b)
    if len(a)>2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

from collections import Counter

N = int(input())

#約数を列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

A_list = [make_divisors(int(e)) for e in input().split()]

all_divisors_list=[]
for i in A_list:
  all_divisors_list += i

collected_adl = Counter(all_divisors_list)

ans = 1
for a in collected_adl.most_common():
  if a[1] <= N-2:
    break
  elif a[0]>ans:
    ans=a[0]
    
print(ans)

### FIXED CODE ###

from collections import Counter
from functools import lru_cache

N = int(input())

#約数を列挙
@lru_cache(maxsize=1000)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

A_list = [make_divisors(int(e)) for e in input().split()]

all_divisors_list=[]

for i in A_list:
  all_divisors_list += i

collected_adl = Counter(all_divisors_list)

ans = 1
for a in collected_adl.most_common():
  if a[1] <= N-2:
    break
  elif a[0]>ans:
    ans=a[0]
    
print(ans)
### BUGGY CODE ###

def main():
    input = sys.stdin.readline
    try:
        a, b, c = map(int, input().split())
        for i in range(a, 100000000, a):
            if i % b == c:
                print("YES")
                break
        else:
            print("NO")

    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    input = sys.stdin.readline
    try:
        a, b, c = map(int, input().split())
        for i in range(a, a * b, a):
            if i % b == c:
                print("YES")
                break
        else:
            print("NO")

    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N=int(input())
a=4/N
for h in range(1,3501):
    H=1/h
    for n in range(h,3501):
        flag=0
        if a-H-1/n-1/h<=0 and a-H-1/n-1/3500>=0:

            st,end=h,3500
            for w in [st,end]:
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    break
            while st!=end:
                #print(h,n,st,end)
                w=int((st+end)/2)
                if end-st==1:
                    end=w
                    st=w
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
                elif B>0:
                    end=w
                else:
                    st=w

        if flag:
            break
    if flag:
        break

print(h,n,w)


### FIXED CODE ###

N=int(input())
a=4/N
h_st=max(int(N*(1/4))-1,1)
#h_st=1
for h in range(h_st,3501):
    H=1/h
    for n in range(h,3501):
        flag=0
        if 4*h*n*n-(n*n+h*n+h*n)*N<=0 and 4*h*n*3500-(n*3500+h*3500+h*n)*N>=0:

            st,end=n,3500
            for w in [st,end]:
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
            while st!=end:
                #print(h,n,st,end)
                w=int((st+end)/2)
                if end-st==1:
                    end=w
                    st=w
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
                elif B>0:
                    end=w
                else:
                    st=w

        if flag:
            break
    if flag:
        break

print(h,n,w)
### BUGGY CODE ###

NN = 16
def addbit(i, x=1):
    i += 1
    while i <= 2**NN:
        BIT[i] += x
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0]*(2**NN+1)
    re = 0
    for i, l in enumerate(L):
        re += i - getsum(l)
        addbit(l)
    return re
def calc(Z):
    Z.sort()
    l, r = -1<<27, 1<<27
    for i in range(70):
        m = (l+r) / 2
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(Z)])]
        if bit(A) > N*(N-1)//4:
            l = m
        else:
            r = m
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

### FIXED CODE ###

def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush

N = int(input())
INF = float("inf")
d = [INF for n in range(N)]
d[0] = 0
adj = [[] for _ in range(N)]

searched = [False for _ in range(N)]
searched[0] = True

for n in range(N):
    inp = tuple(map(int, input().split()))
    assert n == inp[0]
    for i in range(inp[1]):
        adj[n] = list(zip(inp[2::2], inp[3::2]))

heap = [[0, 0]]

while len(heap):
    pcost, p = heappop(heap)
    searched[p] = True
    
    for v, c in adj[p]:
        if not searched[v]:
            new_cost = pcost + c
            if new_cost < d[v]:
                d[v] = new_cost
                heappush(heap, [new_cost, v])

for n in range(N):
    print("{} {}".format(n, d[n]))

### FIXED CODE ###

# -*- coding: utf-8 -*-
from heapq import heappop, heappush
def inpl(): return list(map(int, input().split()))
INF = float("inf")
N = int(input())
G = []
for _ in range(N):
    I = inpl()
    G.append(zip(*[I[3::2], I[2::2]]))

def dijkstra(G):
    C = [INF]*(N)
    C[0] = 0
    visited = [False] * (N)
    Q = [[0, 0]]

    while Q:
        c, u = heappop(Q)
        if C[u] < c:
            continue
        visited[u] = True
        for d, v in G[u]:
            if visited[v]:
                continue
            e = c + d
            if e < C[v]:
                C[v] = e
                heappush(Q, [e, v])
    return C

for i, c in enumerate(dijkstra(G)):
    print(i, c)
### BUGGY CODE ###

def summm(a):
    ans = 0
    for i in a:
        ans += (i + 1) / 2
    return ans

n, k = map(int, input().split())
p = list(map(int, input().split()))
lists = [summm(p[i:i + k]) for i in range(n - k + 1)]
print('{0:.10f}'.format(max(lists)))

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(lambda i: (i + 1) / 2, list(map(int, input().split()))))
suma = sum(p[0:k]) 
max = suma
for i in range(k, n):
    suma += (p[i] - p[i - k])
    if suma > max:
        max = suma

print('{:.8f}'.format(max))
### BUGGY CODE ###

import sys

lines = sys.stdin.readlines()
n = int( lines[0] )
eles = []
for i in range( 1, n+1 ):
	op = lines[i].rstrip().split( " " )
	if "insert" == op[0]:
		eles.insert( 0, op[1] )
	elif "delete" == op[0]:
		if op[1] in eles:
			eles.remove( op[1] )
	elif "deleteFirst" == op[0] :
		eles.pop( 0 )
	elif "deleteLast" == op[0]:
		eles.pop( )

output = []
for val in eles:
	output.append( val )
	output.append( " " )

output.pop( )
print( "".join( output ) )

### FIXED CODE ###

import sys
from collections import deque

n = int( sys.stdin.readline( ) )
que = deque( )
lines = sys.stdin.readlines()
for line in lines:
	op = line.rstrip().split( " " )
	if "insert" == op[0]:
		que.appendleft( op[1] )
	elif "delete" == op[0]:
		if op[1] in que:
			que.remove( op[1] )
	elif "deleteFirst" == op[0] :
		que.popleft( )
	elif "deleteLast" == op[0]:
		que.pop( )


print( " ".join( que ) )
### BUGGY CODE ###

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

left = 0
right = 1
max_length = 0

while left < N:
    if right - left > N - right:
        break
    serch_str = S[left:right]
    left_str = S[right:]
    if serch_str in left_str:
        max_length = max(max_length, len(serch_str))
        right += 1
    else:
        left += 1
        right = left + 1

print(max_length)

### FIXED CODE ###

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

left = 0
right = 1
max_length = 0

while left < N:
    if right - left > N - right:
        break
    serch_str = S[left:right]
    if serch_str in S[right:]:
        max_length = max(max_length, len(serch_str))
        right += 1
    else:
        left += 1

print(max_length)