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

from sys import exit
n = int(input())
ans = 1
a = list(map(int, input().split()))
for x in a:
	ans *= x
if ans > 10**18:
	print(-1)
	exit()
print(ans)

### FIXED CODE ###

from sys import exit
n = int(input())
ans = 1
a = list(map(int, input().split()))
if 0 in a:
	print(0)
	exit()
for x in a:
	ans *= x
	if ans > 10**18:
		print(-1)
		exit()
print(ans)
### BUGGY CODE ###

from collections import deque
q = deque('')
n = input()
List = input().split()
for l in List:
    q.append(l)
    q = deque(reversed(q))

for p in q:
    print(p)

### FIXED CODE ###

n = int(input())
List = list(map(int,input().split()))
ans = List[-1-n%2::-2]+List[::2]
print(*ans[::(-1)**n],end=" ")
### BUGGY CODE ###

n = int(input())

a = input()
#print(a)
q = int(input())

b = []
for _ in range(q):
    b.append(list(input().split(" ")))
#print(b)

d = a.split(' ')
l = len(d)
for i in range(q):
    c = a.replace(b[i][0],b[i][1],100000)
    a = c
    d = a.split(' ')
    s = 0
    for j in range(l):
        s += int(d[j]) 
    print(s)

### FIXED CODE ###

n = int(input())

a = list(map(int,input().split()))
#print(a)
q = int(input())
z = [0 for i in range(100001)]
for i in range(len(a)):
    z[a[i]] += 1
x = sum(a)
b = []
for _ in range(q):
    b.append(list(map(int,input().split())))
#print(b)


for i in range(q):
    x += (b[i][1] - b[i][0]) * z[b[i][0]]
    z[b[i][1]] += z[b[i][0]]
    z[b[i][0]] = 0
    print(x)
### BUGGY CODE ###

import copy
import bisect
N = int(input())
L = list(map(int,input().split()))
count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        #print(L[i])
        #print(L[j])
        maxi = L[i] + L[j] -1
        mini = abs(L[i] - L[j]) +1
        #print("maxi"+str(maxi)+"mini"+str(mini))
        cL = copy.copy(L)
        del cL[:j+1]
        #print(cL)
        mi = bisect.bisect_left(cL,mini)
        ma = bisect.bisect_right(cL, maxi)
        #print("mi"+str(mi)+"ma"+str(ma))
        if ma >= mi:
            count += ma-mi
print(count)


### FIXED CODE ###


import bisect
N = int(input())
L = list(map(int,input().split()))
count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        count += bisect.bisect(L,L[i]+L[j]-1)-j-1
print(count)
### BUGGY CODE ###

a,b,n = map(int,input().split())
maxans = 0

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

  if ans > maxans:
    maxans = ans

print(maxans)
 


### FIXED CODE ###

a,b,n = map(int,input().split())
 
if n<b:
  maxq = n
else:
  maxq = b-1
  
ans = a*maxq//b
 
print(ans)
### BUGGY CODE ###

import sys
sample = sys.stdin.read().splitlines()
nandk  = list(map(int, sample[0].split()))
stones = list(map(int, sample[1].split()))
n, k = nandk[0], nandk[1]
dp = [float('inf')] * n
#jumps = range(1, k+1)
dp[0] = 0
for idx in range(len(dp)):
  for jump in range(idx+1,idx+k+1):
    if jump < len(dp):
      dp[jump] =  min(dp[idx]+abs(stones[jump]-stones[idx]), dp[jump])
print(dp[-1])

### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    h = tuple(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF] * n
    dp[0] = 0
    for i in range(n):
        for j in range(1, k + 1):
            i_j = i + j
            if i_j < n:
                x = dp[i] + abs(h[i] - h[i_j])
                if dp[i_j] > x:
                    dp[i_j] = x
    print(dp[-1])


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

n, m = map(int, input().split())
a = []
for i in range(m):
    req = [int(i) for i in input().split()]
    a.append(req)
a.sort(key = lambda x: x[1])
b = []
for i in a:
    b_range = set(list(range(i[0], i[1])))
    b_set = set(b)
    if len(b_set & b_range) == 0:
        b.append(i[1] - 1)
print(len(b))

### FIXED CODE ###

n, m = map(int, input().split())
a_list = []
for _ in range(m):
    a, b = map(int, input().split())
    a_list.append([a, b])
a_list.sort(key = lambda x: (x[1], x[0]))
temp = -1
ans = 0
for a, b in a_list:
    if (temp < a):
        temp = b - 1
        ans += 1
print(ans)
### BUGGY CODE ###

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

count = 0
for i in range(N-1):
    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 ###

n = int(input())
a = list(map(int,input().split(" ")))
b = [0 for a in range(n)]
b[0] = a[0]
answer = 0
for i in range(n-1):
    b[i+1] = b[i] + a[i+1]
# print(b)
for i in b:
    if i == 0:
        answer += 1;
minimum = min(b)
for i in range(n):
    b[i] -= minimum
# print(b)
c = [0 for a in range(max(b)+1)]
for i in range(n):
    c[b[i]] += 1

for i in c:
    if i > 1:
        answer += i * (i-1) // 2
# print(c)
# print(sum(c))
print(answer)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split(" ")))
b = [0 for a in range(n)]
b[0] = a[0]
answer = 0
for i in range(n-1):
    b[i+1] = b[i] + a[i+1]
# print(b)
for i in b:
    if i == 0:
        answer += 1;
minimum = min(b)
for i in range(n):
    b[i] -= minimum
# print(b)
# c = [0 for a in range(max(b)+1)]
setb = set(b)
# print(setb)
c = {}
for key in setb:
    c[str(key)] = 0

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

for v in c.values():
    if v > 1:
        answer += v * (v-1) // 2
# print(c)
# print(sum(c))
print(answer)
### BUGGY CODE ###

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

import fractions
lcm = 1
for ai in a:
    lcm = ai * lcm // fractions.gcd(ai, lcm)

ans = 0
for ai in a:
    ans += (lcm // ai)

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

### FIXED CODE ###

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

import fractions
lcm = 1
prevlcm = 1
ans = 0
for i in range(n):
    ai = a[i]
    lcm = ai * lcm // fractions.gcd(ai, lcm)
    if prevlcm == lcm:
        ans = ans + (lcm // ai)
    else:
        ans = ans * (lcm // prevlcm) + (lcm // ai)
    #print(i, lcm, ans)
    prevlcm = lcm

print(ans % (10**9 + 7))
### BUGGY CODE ###

N = int(input())
S = list(input())
A = (S.count("R"))*(S.count("B"))*(S.count("G"))
for i in range(1,N):
    for j in range(i+1,N+1):
        if j < 2*j - i <= N:
            if S[i-1] != S[j-1] and S[i-1] != S[2*j - i - 1] and S[j-1] != S[2*j - i - 1]:
                A -= 1
print(A)

### FIXED CODE ###

N = int(input())
S = list(input())
A = (S.count("R"))*(S.count("B"))*(S.count("G"))
for i in range(1,N):
    for j in range(i+1,N+1):
        if j < 2*j - i <= N:
            if S[i-1] != S[j-1] and S[i-1] != S[2*j - i - 1] and S[j-1] != S[2*j - i - 1]:
                A -= 1
print(A)
### BUGGY CODE ###

n=int(input())

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

ans=0

for i in range(n-1):
    for j in range(i+1,n):
        
        ans += (A[i] * A[j]) % (10**9+7)

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

### FIXED CODE ###

import sys
input = sys.stdin.readline

n=int(input())

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

B=[A[0]]

for i in range(len(A)-1):
    B.append((B[i]+A[i+1]) % (10**9+7))

ans=0

for i in range(n-1):
    
    ans += (A[i] * (B[-1]-B[i])  % (10**9+7))
    
#    for j in range(i+1,n):
        
#        ans += (A[i] * A[j]) % (10**9+7)
#
print(ans % (10**9+7))
### BUGGY CODE ###

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

sa=[]
for i in range(n):
    sa.append(i+1+a[i])

sb=[]
for i in range(n):
    sb.append(max(0,i+1-a[i]))

for i in range(n-1):
    cnt=0
    h=sa[i]
    for j in range(i+1,n):
        if sb[j]==h:
            cnt+=1
    ans+=cnt

print(ans)



### FIXED CODE ###

from collections import defaultdict
n=int(input())
A=list(map(int,input().split()))
ans=0
d=defaultdict(int)

for i,a in enumerate(A):
    ans+=d[i-a] #jから先
    d[i+a]+=1

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

import numpy as np
import numba
@numba.jit
def solve(n,s):
    dp=np.zeros((n+1,n+1),dtype=int)
    for i in range(n):
        for j in range(i+1,n):
            if s[i]==s[j]:
                if dp[i][j]<j-i:
                    dp[i+1][j+1]=dp[i][j]+1
    print(np.amax(dp))
n=int(input())
s=input()
solve(n,s)

### FIXED CODE ###

n=int(input())
s=input()
dp=[[0]*n for i in range(n)]
for i in range(n-2,-1,-1):
    for j in range(n-1,i,-1):
        if j==n-1:
            if s[j]==s[i]:
                dp[i][j]=1
        else:
            if s[j]==s[i] and dp[i+1][j+1]+1<=j-i:
                dp[i][j]=dp[i+1][j+1]+1
            else:
                dp[i][j]=0
ans=0
for i in range(n):
    for j in range(n):
        ans=max(ans,dp[i][j])
print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
for _ in range(Q):
    l, r = map(int, input().split())
    print(S[l-1:r].count("AC"))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
ac = [0] * (N + 1)
ans = []
for i in range(N):
    ac[i + 1] = ac[i] + (1 if S[i:i+2] == "AC" else 0)
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(ac[r - 1] - ac[l - 1])
for i in range(Q):
    print(ans[i])
### BUGGY CODE ###

from collections import Counter
n=int(input())
s=[Counter(input()) for i in range(n)]
s = [sorted(i.items(), key=lambda x:x[0]) for i in s]
s = ["".join(str(i)) for i in s]
dp={}
for i in range(n):
  dp.setdefault(s[i],0)
  dp[s[i]]+=1
ans=0
for i in dp.keys():
  ans+=dp[i]*(dp[i]-1)//2
print(ans)

### FIXED CODE ###

n=int(input())
s=["".join(sorted(list(input()))) for i in range(n)]
s.sort()
dp=[1]
for i in range(n-1):
  if s[i]==s[i+1]:
    dp[len(dp)-1]+=1
  else:
    dp.append(1)
ans=0
for i in dp:
  ans+=i*(i-1)//2
print(ans)
### BUGGY CODE ###

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

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

sumtmp = [[0 for i in range(N) ] for j in range(10)]
sumtmp[int(S[0])][0] = 1
for i in range(1, N):
    val = int(S[i])
    for j in range(10):
        sumtmp[j][i] = sumtmp[j][i-1] 
        if j == val:
            sumtmp[j][i] += 1

pw = set()
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(10):
            if sumtmp[k][N-1] - sumtmp[k][j] > 0:
                w = S[i]+S[j]+str(k) 
                pw.add(w)

print(len(pw))


### FIXED CODE ###

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

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

ans = 0
for i in range(1000):
    pw = list("{0:03d}".format(i))

    if pw[0] in S:
        w1 = S.index(pw[0])
        if pw[1] in S[w1+1:]:
            w2 = w1+1 + S[w1+1:].index(pw[1])
            if pw[2] in S[w2+1:]:
                ans += 1

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

import fractions
import heapq

mod = 10**9+7

N = int(input())

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

q = []

for i in A:
    heapq.heappush(q,i)

for i in range(N-1):

    x = heapq.heappop(q)
    y = heapq.heappop(q)

    heapq.heappush(q , x * y // fractions.gcd(x,y))

s = q[0]
ans = 0

for i in range(N):
    ans += s // A[i]
    ans %= mod

print (ans)


### FIXED CODE ###

import fractions

def lcm(x,y):
  return x // fractions.gcd(x,y) * y


mod = 10**9+7


N = int(input())

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

B = 0
for i in A:
    B += pow(i,mod-2,mod)
    B %= mod

g = 1

for i in range(N):
    g = lcm(g,A[i])

print (g * B % mod)
### BUGGY CODE ###

from heapq import heappop,heappush
x,y,z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A = sorted(A,reverse=True)
B = sorted(B,reverse=True)
C = sorted(C,reverse=True)

def solve(p,add=False):
  cnt = 0
  for i in range(x):
    for j in range(y):
      for k in range(z):
        sum_ = A[i] + B[j] + C[k]
        if sum_ < p:
          break
        cnt += 1
        if add:
          ans.append(sum_) 
        if cnt >= K:
          return True
  return False

l = 0 
r = 3 * 10**10
while l+1 < r: 
  p = (l+r)//2
  if solve(p): # p以上がk個以上存在していたら、条件を厳しく: pを増やす (つまり→) lを増やす
    l = p    
  else:
    r = p
    
ans = []
solve(p-1,True)
for a in sorted(ans,reverse=True):
  print(a)

### FIXED CODE ###

x,y,z,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

AB = []
for xi in range(x):
  for yi in range(y):
    AB.append(A[xi]+B[yi])

AB = sorted(AB,reverse=True)
C = sorted(C,reverse=True)

i=0
j=0

ABC = []
for ab in AB[:k]:
  for c in C[:k]:
    ABC.append(ab+c)

ABC = sorted(ABC,reverse=True)
for abc in ABC[:k]:
  print(abc)
### BUGGY CODE ###

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

cnt1 = a.count(1)
cnt2 = a.count(2)
cnt3 = a.count(3)

dp = [[[-1]*(cnt1 + cnt2 + cnt3 + 1) for _ in range(cnt2 + cnt3 + 1)] for _ in range(cnt3 + 1)]
dp[0][0][0] = 0

def solve(c3, c2, c1):
    if dp[c3][c2][c1] != -1:
        return dp[c3][c2][c1]
    tmp = 0
    num = c1 + c2 + c3
    # c3を選ぶ
    if c3 != 0:
        tmp += (c3 / n) * solve(c3 - 1, c2 + 1, c1)
    # c2を選ぶ
    if c2 != 0:
        tmp += (c2 / n) * solve(c3, c2 - 1, c1 + 1)
    # c1を選ぶ
    if c1 != 0:
        tmp += (c1 / n) * solve(c3, c2, c1 - 1)
    dp[c3][c2][c1] = n / num * (tmp + 1)
    return dp[c3][c2][c1]

print(solve(cnt3, cnt2, cnt1))

### FIXED CODE ###

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

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

cnt1 = a.count(1)
cnt2 = a.count(2)
cnt3 = a.count(3)

for i in range(cnt3 + 1):
    for j in range(cnt3 + cnt2 + 1 - i):
        for k in range(cnt3 + cnt2 + cnt1 + 1 - i - j):
            if i + j + k == 0:
                continue
            res = 1
            if k > 0:
                res += (k/n) * dp[i][j][k-1]
            if j > 0:
                res += (j/n) * dp[i][j-1][k+1]
            if i > 0:
                res += (i/n) * dp[i-1][j+1][k]
            dp[i][j][k] = (n/(i+k+j)) * res

print(dp[cnt3][cnt2][cnt1])
### BUGGY CODE ###

N=int(input())  #数値入力 「N」だけの入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

# from functools import lru_cache
# @lru_cache(maxsize=100000)

# 一度差を出してから，どんどんi-1, i+1の和で縮めていく．
def check():
    for i in range(N):
        if sum(A[:i]) == sum(A[i:]):
            return True
    return False

from functools import lru_cache
@lru_cache(maxsize=100000)
def get_dist(i):
    return abs(sum(A[:i]) - sum(A[i:]))

def check_distance():
    ret = []
    for i in range(1, N):
        tmp_a = get_dist(i)
        ret.append(tmp_a)
        # print(f"at {i}, abs:{tmp_a}")
    return min(ret)

def check_distance_2():
    ret = []
    tmp_a = abs(sum(A[:1]) - sum(A[1:]))
    # print(tmp_a)
    for i in range(1, N):
        tmp_a = abs(tmp_a - (A[i]*2))
        ret.append(tmp_a)
        # print(tmp_a)
        # print(f"at {i}, abs:{tmp_a}")
    return min(ret)

print(check_distance())

### FIXED CODE ###

N=int(input())  #数値入力 「N」だけの入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

# from functools import lru_cache
# @lru_cache(maxsize=100000)

# 一度差を出してから，どんどんi-1, i+1の和で縮めていく．

def check_distance():
    ret = []
    left = A[0]
    right = sum(A[1:])
    tmp_a = abs(left - right)
    ret.append(tmp_a)

    for i in range(1, N-1):
        left += A[i]
        right -= A[i]
        tmp_a = abs(left - right)
        ret.append(tmp_a)
    return min(ret)

print(check_distance())
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
L = [0 for _ in range(n)]

for i in range(n - 1):
    if s[i:i + 2] == "AC":
        L[i + 1] = 1
        i += 1

for i in range(q):
    l, r = map(int, input().split())
    print(sum(L[l:r]))


### FIXED CODE ###

n, q = map(int, input().split())
s = input()
t = [0] * n
for i in range(1, n):
    t[i] = t[i - 1] + (1 if s[i - 1:i + 1] == "AC" else 0)
for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])
### BUGGY CODE ###

def main():
    _sum = 0
    N = int(input())
    for i in range(1, N):
        _sum += i

    print(_sum)

if __name__ == '__main__':
    main()

### FIXED CODE ###

N = int(input())
print((N-1)*(N) // 2)
### BUGGY CODE ###

n = int(input())

gacha = []

for i in range(n):
    item = input()
    check = 0
    for j in gacha:
        if(j == item):
            check = 1
            break
    if(check == 0):
        gacha.append(item)

print(str(len(gacha)))

### FIXED CODE ###

n = int(input())

gacha = []

for i in range(n):
    item = input()
    gacha.append(item)

print(str(len(set(gacha))))
### BUGGY CODE ###

import io
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 7)


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
2000 3
'''


def MAIN():
  # T_IN()
  A()


def A():
  x = IN_L_I()
  n = x[0]
  k = x[1]

  for i in range(1, k + 1):
    blue = f(k, i)

    red = 0
    red += f(n - k, i - 1)
    red += f(n - k, i)
    red += f(n - k, i)
    red += f(n - k, i + 1)

    res = int((blue * red) % (10 ** 9 + 7))
    print(res)
  return None


def f(x: int, y: int):
  if x < y:
    return 0
  if x == y == 0:
    return 1
  if y < 1:
    return 0
  return f2(x - y, y)


def f2(x: int, y: int):
  return c(x + y - 1, y - 1)


def c(a: int, b: int):
  return pascal(a, b)

HOGE = 10 ** 9 + 7

@lru_cache(maxsize=None)
def pascal(x, y):
  if x == 0 or y == 0 or x == y:
    return 1
  else:
    return (pascal(x - 1, y - 1) + pascal(x - 1, y)) % HOGE


MAIN()


### FIXED CODE ###

import io
import sys

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
2000 3
'''


def MAIN():
  # T_IN()
  cmb_init(MOD)
  A()


def A():
  x = IN_L_I()
  n = x[0]
  k = x[1]

  res = []
  for i in range(1, k + 1):
    blue = f(k, i)

    # red = 0
    # red += f(n - k, i - 1)
    # red += f(n - k, i)
    # red += f(n - k, i)
    # red += f(n - k, i + 1)
    red = f2(n - k - (i - 1), i + 1)

    res.append((blue * red) % MOD)

  [print(i) for i in res]
  return None


def f(x: int, y: int):
  if x < y:
    return 0
  if x == y == 0:
    return 1
  if y < 1:
    return 0
  return f2(x - y, y)


def f2(x: int, y: int):
  return c(x + y - 1, y - 1)


def c(a: int, b: int):
  return cmb(a, b, MOD)


def track(func):
  def tracked(*args, **kwargs):
    result = func(*args, **kwargs)
    name = func.__name__
    arg_str = ",".join(repr(arg) for arg in args)
    print("%s(%s) -> %r" % (name, arg_str, result))
    return result

  return tracked


### CMB ###############################
def cmb(n, r, mod):
  if (r < 0 or r > n):
    return 0
  r = min(r, n - r)
  return g1[n] * g2[r] * g2[n - r] % mod


def cmb_init(mod):
  for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


N = 10 ** 4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

### CMB ###############################


MAIN()
### BUGGY CODE ###

(n,q),*t=[map(int,t.split())for t in open(0)]
s=[0]
d=s*n
f=s+[1]*n
e=[[]for _ in d]
for a,b in t:
 if~-n:n-=1;e[a-1]+=b-1,;e[b-1]+=a-1,
 else:d[a-1]+=b
while s:
 v=s.pop()
 for w in e[v]:d[w]+=d[v]*f[w];s+=[w]*f[w];f[w]=0
print(*d)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def dfs(v):
    for w in e[v]:
        if root[w]>=0:continue
        root[w]=v
        dfs(w)
def dfs2(v):
    for w in e[v]:
        if f[w]:continue
        f[w]=1
        data[w]+=data[v]
        dfs2(w)
input=sys.stdin.readline
n,q=map(int,input().split())
e=[[]for _ in range(n)]
root=[0]+[-1]*(n-1)
data=[0]*n
for _ in range(n-1):
    a,b=map(int,input().split())
    e[a-1]+=b-1,
    e[b-1]+=a-1,
#dfs(0)
for _ in range(q):
    p,x=map(int,input().split())
    data[p-1]+=x
f=[1]+[0]*(n-1)
dfs2(0)
print(*data)
### BUGGY CODE ###

n,d = map(int,input().split())

xy = list()
d2 = d ** 2

for i in range(n):
    xy += map(int,input().split())

#xy_2 = int(len(xy) / 2)
#for i in range(xy_2):
#    x.append(xy.pop(0))
#    y.append(xy.pop(0))
xy2 = list()
for i in range(n):
    xy2.append(xy.pop(0)**2 + xy.pop(0)**2)
    
#xy2_2 = list(set(xy2))

#xy2.sort()

ans = 0
#ans += len(xy2) - len(xy2_2)
for i in xy2:
    if d2 >= i:
        ans += 1
#    else:
#        break

print(ans)




### FIXED CODE ###

n,d = map(int,input().split())
d2 = d ** 2

xy2 = list()
for i in range(n):
    x,y = map(int,input().split())
    xy2.append(x**2+y**2)

    ans = 0
for i in xy2:
    if d2 >= i:
        ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
power = 1
for i in range(1,N+1):
    power = power*i

print (power%1000000007)

### FIXED CODE ###

N = int(input())
power = 1
for i in range(1,N+1):
    power = (power*i)%1000000007
print (power)
### BUGGY CODE ###

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

    max_len = N // 2

    ans = 0
    for L in range(1, max_len + 1):
        found = False
        for i in range(N-L):
            if S[i:i+L] in S[i+L:]:
                found = True
                break
        if found:
            ans = L
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###


def z_algorithm(S):
    # 文字列が与えられた時、各 i について
    # 「S と S[i:|S|-1] の最長共通接頭辞の長さ」を記録した配列 A を
    #  O(|S|) で構築するアルゴリズム
    # S: aaabaaaab
    # A: 921034210
    # 例えば、A[5] = 4だが、これは、S[0:4] == S[5:5+4] 
    # (Sの0文字目からと5文字目からは、4文字一致している(aaab)) ことを意味する。

    lenS = len(S)
    A = [0] * lenS
    i = 1; j = 0
    A[0] = lenS
    # i: 調査開始点
    # iを1文字目からlen(S)-1文字目まで左から順に動かしていく
    while i < lenS:
        # j: 何文字目まで一致するか(iからの距離)
        # 一致しなくなるまでjを左から右へ動かしていく
        while i + j < lenS and S[j] == S[i + j]:
            j += 1
        # 1文字も一致しない場合は調査開始点を一つ右にずらす
        if j == 0:
            i += 1
            continue

        A[i] = j

        # 例）S: momomosumomomomo
        # A[1] = 0, A[2] = 4 (A[0:4] == A[2:2+4] = "momo")

        # i=2の調査が終わった段階で、
        # S[3] = S[2 + 1] = S[1] = "o" 
        # で、A[3] = A[1] = 0（Sの1文字目からと3文字目からは一致しない）
        # のは明らかなので、i = 3の結果はi = 1の結果を流用して0とする。
        # つまり、A[3] = A[2 + 1] = A[1] = 0

        # 今回、i + j 文字目まで、一致するか調べたので、
        # A[i + 1] ~ A[i + j - 1] までの間で、計算結果を流用できるところは流用する
        # j <= k + A[k] となるようなkの場合、
        # j文字目以降は今回調べてないので一致するか本当に分からないので、流用をやめる
        # 今回の場合、
        # k = 1: 1 + A[1] = 1 + 0 = 1 < j = 4 なので、流用できる
        # k = 2: 2 + A[2] = 2 + 4 = 6 > j = 4 なので、流用できない
        # つなり、k=2となった瞬間、流用をせずにループを抜ける。
        k = 1
        while k + A[k] < j and i + k < lenS:
            A[i + k] = A[k]
            k += 1
        # 今回 1回 (=k-1回) 流用できた、つまり A[3] = A[2(=i) + 2(=k) - 1] まで確定したので、
        # 次は A[4] = A[i + k] から調べる
        i += k

        # また、k = 2 のとき、k + A[k] >= j となって流用を打ち切られたということは、
        # k + A[i + k] >= j  => A[i + k] >= j - k
        # A[4] は少なくとも j - k = 4 - 2 = 2 以上となることが確定する。
        # つまり、S[4:]とSは、少なくとも最初の2文字 (j-k文字) は一致する。
        # よって、A[4]を調べるときは、j=2から調査を開始すればよい。
        # （つまり、S[6]とS[4:][2]が一致しているか調べるところから始める）

        #             0123456
        # S         = momomosumomomomo
        # S[2:]     =   momosumomomomo   <- 5文字目が違う
        # S[2:][2:] =     mosumomomomo   <- 3文字目が違う
        # S[4:]     =     mosumomomomo   <- 3文字目が違う
        # S[4:][2:] =       sumomomomo   <- 1文字目が違う
        j -= k
    return A

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

    ans = 0

    # Z-algorithm で、最長共通接頭辞の長さを調べる。
    # Z-algorithm は、「S と S[i:|S|-1] の最長共通接頭辞の長さ」を記録するので、
    # S[1]以降の部分文字列同士の長さは、
    # S=S[i:]としてiをずらしながら最長共通接頭辞を調べることで分かる

    for i in range(N-1):
        A = z_algorithm(S[i:])
        # print(A)
        # 例えばS = ababa のとき、
        # A = [5, 0, 3, 0, 1] となる。
        # A[2] = 3 だが、範囲が被ってしまっているので、
        # A[i] > i の場合、一致する文字数はiまでにしておく。
        ans = max(ans, max([min(i, a) for i, a in enumerate(A)]))

    print(ans)

if __name__ == '__main__':
    main()