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

N = int(input())
A = []
t = 0
for i in range(N):
    A.append(int(input()))
while t != N:
    B = [0] * N
    for i in range(N):
        if t != i:
            B[i] = A[i]
    print(max(B))
    t += 1


### FIXED CODE ###

N = int(input())
A = []
B = [0] * N
for i in range(N):
    A.append(int(input()))
max = max(A)
B = sorted(A, reverse = True)
count = A.count(max)
if count > 1:
    for i in range(N):
        print(max)
else:
    for i in range(N):
        if A[i] != max:
            print(max)
        else:
            print(B[1])
### BUGGY CODE ###

s = input()[::-1]
m = 2019
ans = 0
x = 1
tot = 0
cnt = [0] * m
for s in s:
    cnt[tot] += 1
    tot += int(s) * x
    tot %= m
    ans += cnt[tot]
    x *= 10
print(ans)


### FIXED CODE ###

s = input()[::-1]
m = 2019
ans = 0
x = 1
tot = 0
cnt = [0] * m
cnt[0] = 1
for s in s:
    tot += int(s) * x
    tot %= m
    #ans += cnt[tot]
    x *= 10
    x %= m
    cnt[tot] += 1

print(sum(i*(i-1)//2 for i in cnt))
### BUGGY CODE ###

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

for i in range(n):
    print(a.count(i + 1))


### FIXED CODE ###

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

ans = [0]* n

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

n, m = map(int, input().split())
wars = []
for _ in range(m):
    wars.append(tuple(map(int, input().split())))
wars.sort(key = lambda x: x[1])
tasks = wars[:]
distruction = 0
for l, r in wars:
    if (l, r) in tasks:
        tasks = list(filter(lambda x: x[0] >= r,tasks))
        distruction += 1
print(distruction)


### FIXED CODE ###

n, m = map(int, input().split())
wars = []
for _ in range(m):
    wars.append(tuple(map(int, input().split())))
wars.sort(key = lambda x: x[1])
last_distruction = -1
distruction = 0
for l, r in wars:
    if l > last_distruction:
        distruction += 1
        last_distruction = r-1
print(distruction)
### BUGGY CODE ###

def main():
  (_, M) = map(int, input().split())
  A = list(map(int, input().split()))
  A.sort()
  A.reverse()
  for i in range(M):
    A[A.index(max(A), 0, i+1)] //= 2
  print(sum(A))
main()

### FIXED CODE ###

from heapq import heappush, heappop
def main():
	(N, M) = map(int, input().split())
	hq =  list(map(lambda x:-x, map(int, input().split())))
	hq.sort()
	for i in range(M):
		b = - heappop(hq) // 2
		heappush(hq, -b)
	print(-sum(hq))
main()
### BUGGY CODE ###

import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

n = int(input())
dice_list = []
flag_list = []
for _ in range(n):
    flag = False
    faces = list(map(int, input().split()))
    dice_list.append(Dice(faces))

    if n == 0:
        continue

    dice_a = dice_list[-1]
    for i in range(len(dice_list) - 1):
        dice_b = dice_list[i]

        for i in range(500):
            dice_b.roll(random.randint(0, 3))
            if dice_a.is_equal(dice_b):
                flag = True
                break

        flag_list.append(flag)

if any(flag_list):
    print('No')
else:
    print('Yes')



### FIXED CODE ###

import random


class Dice(object):
    def __init__(self):
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6

    def __init__(self, faces):
        self.t = faces[0]
        self.s = faces[1]
        self.e = faces[2]
        self.w = faces[3]
        self.n = faces[4]
        self.b = faces[5]

    def roll(self, direct):
        if direct == 0:
            self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
        elif direct == 1:
            self.t, self.w, self.b, self.e = self.e, self.t, self.w, self.b
        elif direct == 2:
            self.n, self.w, self.s, self.e = self.w, self.s, self.e, self.n

    def is_equal(self, dice):
        if self.t == dice.t and self.s == dice.s and self.e == dice.e and self.w == dice.w and self.n == dice.n and self.b == dice.b:
            return True
        else:
            return False

    def get_nums(self):
        return {self.t, self.s, self.e, self.w, self.n, self.b}

n = int(input())
dice_list = []
flag_list = []
for _ in range(n):
    flag = False
    faces = list(map(int, input().split()))
    dice_list.append(Dice(faces))

    if n == 0:
        continue

    dice_a = dice_list[-1]
    for i in range(len(dice_list) - 1):
        dice_b = dice_list[i]

        if (dice_a.get_nums() == dice_b.get_nums()):
            for i in range(1000):
                dice_b.roll(random.randint(0, 3))
                if dice_a.is_equal(dice_b):
                    flag = True
                    break

        flag_list.append(flag)

if any(flag_list):
    print('No')
else:
    print('Yes')
### BUGGY CODE ###

import numpy as np
H,W,M=map(int, input().split())
hl=np.array([0 for i in range(H+1)])
wl=np.array([0 for i in range(W+1)])
ms=[]
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.append([h,w])
a=max(hl)
b=max(wl)
hmax= [i for i, x in enumerate(hl) if x ==a]
wmax=[i for i, x in enumerate(wl) if x ==b]
# hmax=np.where(hl == hl.max())[0]
# wmax=np.where(wl == wl.max())[0]
a=max(hl)
b=max(wl)
bl=False
if len(hmax)*len(wmax)>M:
    bl=True
else:
    for x in hmax:
        for y in wmax:
            if [x,y] not in ms:
                bl=True
                break
        if bl:
            break
if bl:
    print(a+b)
else:
    print(a+b-1)

### FIXED CODE ###


H,W,M=map(int, input().split())
hl=[0 for i in range(H+1)]
wl=[0 for i in range(W+1)]
ms=[]
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.append([h,w])
a=max(hl)
b=max(wl)
hmax=[]
wmax=[]
s=0
for x in ms:
    if  hl[x[0]]==a and wl[x[1]]==b:
        s+=1
c=hl.count(a)
d=wl.count(b)
if s<c*d:
    print(a+b)
else:
    print(a+b-1)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n,MOD = [int(i) for i in input().split()]

to = [[] for _ in [0]*n]
for _ in range(n-1):
    x,y = [int(i)-1 for i in input().split()]
    to[x].append(y)
    to[y].append(x)


dp = [[0]*len(to_i) for to_i in to]
parent_index = [-9999]*n 
ans = [0]*n

def dfs(v, p):
    res = 1
    for i, vc in enumerate(to[v]):
        if vc == p:
            parent_index[v] = i
            continue
        dp[v][i] = dfs(vc, v)
        res *= dp[v][i]+1
        res %= MOD
    return res

def dfs2(v, res_p, p):
    deg = len(to[v])
    if p >= 0:
        dp[v][parent_index[v]] = res_p

    accl = [1]*(deg+1)
    for i, dpvi in enumerate(dp[v]):
        accl[i+1] = accl[i]*(dpvi+1)%MOD

    accr = [1]*(deg+1)
    for i, dpvir in enumerate(reversed(dp[v])):
        accr[-i-2] = accr[-i-1]*(dpvir+1)%MOD

    ans[v] = accr[0]
    for i,vc in enumerate(to[v]):
        if vc == p: continue
        dfs2(vc, accl[i]*accr[i+1]%MOD, v)

dfs(0,-1)
#print(dp)
dfs2(0,0,-1)
#print(dp)
for i in ans:
    print(i)

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n,MOD = [int(i) for i in input().split()]

to = [[] for _ in [0]*n]
for _ in range(n-1):
    x,y = [int(i)-1 for i in input().split()]
    to[x].append(y)
    to[y].append(x)


dp = [[0]*len(to_i) for to_i in to]
parent_index = [-9999]*n 
ans = [0]*n

def dfs(v, p):
    res = 1
    for i, vc in enumerate(to[v]):
        if vc == p:
            parent_index[v] = i
            continue
        dp[v][i] = dfs(vc, v)
        res *= dp[v][i]+1
        res %= MOD
    return res

def dfs2(v, res_p, p):
    deg = len(to[v])
    if p >= 0:
        dp[v][parent_index[v]] = res_p

    accl = [1]*(deg+1)
    accr = [1]*(deg+1)

    for i in range(1, deg+1):
        accl[i] = accl[i-1] * (dp[v][i-1] + 1) % MOD
        accr[-i-1] = accr[-i] * (dp[v][-i] + 1) % MOD

    ans[v] = accr[0]
    for i,vc in enumerate(to[v]):
        if vc == p: continue
        dfs2(vc, accl[i]*accr[i+1]%MOD, v)

dfs(0,-1)
#print(dp)
dfs2(0,0,-1)
#print(dp)
for i in ans:
    print(i)
### BUGGY CODE ###

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


def main():
    ans = 0
    for i in range(1, N):
        S1 = S[:i]
        S2 = S[i:]
        ok = 0
        ng = len(S2) + 1
        k = (ok + ng) // 2
        while ng - ok > 1:
            if S2[:k] in S1:
                ok = k
                k = (k + ng) // 2
            else:
                ng = k
                k = (k + ok) // 2
        ans = max(ans, k)
        if ans > N - i - 1:
            break
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict

N = int(input())
S = input()
mod1 = 10 ** 9 + 7
mod2 = 10 ** 9 + 9
base1 = 1007
base2 = 2009

ok = 0
ng = N // 2 + 1
mid = (ok + ng) // 2
while ng - ok > 1:
    seen1 = defaultdict(lambda: 10 ** 5)
    seen2 = defaultdict(lambda: 10 ** 5)
    rh1 = 0
    rh2 = 0
    for i in range(mid):
        rh1 += ord(S[i]) * pow(base1, mid - i - 1, mod1)
        rh2 += ord(S[i]) * pow(base2, mid - i - 1, mod2)
        rh1 %= mod1
        rh2 %= mod2
    seen1[rh1] = 0
    seen2[rh2] = 0
    flag = 0
    for i in range(1, N - mid + 1):
        if flag == 1:
            break
        rh1 = (rh1 * base1 + ord(S[i + mid - 1]) - ord(S[i - 1]) * pow(base1, mid, mod1)) % mod1
        rh2 = (rh2 * base2 + ord(S[i + mid - 1]) - ord(S[i - 1]) * pow(base2, mid, mod2)) % mod2
        if i - seen1[rh1] >= mid and i - seen2[rh2] >= mid:
            ok = mid
            mid = (ok + ng) // 2
            flag = 1
        else:
            if seen1[rh1] == 10 ** 5:
                seen1[rh1] = i
            if seen2[rh2] == 10 ** 5:
                seen2[rh2] = i
    if flag == 0:
        ng = mid
        mid = (ok + ng) // 2

print(ok)
### BUGGY CODE ###

from collections import deque

H,W=map(int,input().split())
s=[]

cnt=0
for i in range(H):
    temp=list(input())
    cnt+=temp.count("#")
    s.append(temp)

d=deque([[0,0,0]])
step=[[1,0],[0,1],[-1,0],[0,-1]]

while d:
    h0,w0,c=d.popleft()
    s[h0][w0]="#"
    c+=1
    for h1,w1 in step:
        h = h0 + h1
        w = w0 + w1
        if h<0 or h>=H or w<0 or w>=W or s[h][w]=="#":
            continue
        if h==H-1 and w==W-1:
            c+=1
            ans = H * W - cnt - c
            print(ans)
            exit()
        d.append([h,w,c])
print(-1)

### FIXED CODE ###

from collections import deque

H,W=map(int,input().split())
s=[]

cnt=0
for i in range(H):
    temp=list(input())
    cnt+=temp.count(".")
    s.append(temp)

d=deque([[0,0]])
c=[[10000]*W for i in range(H)]
step=[[-1,0],[0,-1],[1,0],[0,1]]
c[0][0]=1

while d:
    h0,w0=d.popleft()
    for h1,w1 in step:
        h = h0 + h1
        w = w0 + w1
        if h<0 or h>=H or w<0 or w>=W or s[h][w]=="#" or c[h][w]!=10000:
            continue
        if h==H-1 and w==W-1:
            ans = cnt - c[h0][w0]-1
            print(ans)
            exit()
        c[h][w]=c[h0][w0]+1
        d.append([h,w])
print(-1)
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    from itertools import combinations

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

    lst = []
    for a, b in combinations(A, 2):
        lst.append(a * b)
    lst = sorted(lst)
    print(lst[K - 1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    from bisect import bisect_left, bisect_right

    N, K = map(int, input().split())
    A = sorted([int(x) for x in input().split()])

    negative_end = bisect_left(A, 0)
    postive_start = bisect_right(A, 0)

    postive_cnt = N - postive_start
    negative_cnt = negative_end
    zero_cnt = N - postive_cnt - negative_cnt

    negative_pairs_cnt = postive_cnt * negative_cnt
    zero_pairs_cnt = (zero_cnt * (postive_cnt + negative_cnt)
                      + (zero_cnt * (zero_cnt - 1) // 2))
    
    # 答えが負の場合
    if K <= negative_pairs_cnt:
        # 二分探索：mid以下になるペアがK個以上あるか？
        ok, ng = 0, -10 ** 19
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            or_higher_cnt, right = 0, postive_start
            for left in range(negative_end):
                while right < N and A[left] * A[right] > mid:
                    right += 1
                or_higher_cnt += postive_cnt - (right - postive_start)
            if or_higher_cnt >= K:
                ok = mid
            else:
                ng = mid
        print(ok)
    # 答えが0の場合
    elif K <= negative_pairs_cnt + zero_pairs_cnt:
        print(0)
    # 答えが正の場合
    else:
        # 二分探索：mid以下になるペアがK個以上あるか？
        K -= negative_pairs_cnt + zero_pairs_cnt
        ok, ng = 10 ** 19, 0
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            # 正*正の場合
            or_higher_cnt, right = 0, N - 1
            for left in range(postive_start, N):
                while right < N and A[left] * A[right] > mid and left < right:
                    right -= 1
                or_higher_cnt += max(0, right - left)
            # 負*負の場合
            left = 0
            for right in range(negative_end - 1, -1, -1):
                while left < N and A[left] * A[right] > mid and left < right:
                    left += 1
                or_higher_cnt += max(0, right - left)

            if or_higher_cnt >= K:
                ok = mid
            else:
                ng = mid
        print(ok)


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

import sys
sys.setrecursionlimit(100001)

N = int(input())
memo = [[-1]*(N-1) for i in range(N)]

def frog(h,h2,h1):
    if memo[h2][h1]  != -1:
        return memo[h2][h1]
    elif h1 <= 0:
        if memo[h2][0]  == -1:
            memo[h2][0] = abs(h[h2] - h[0])
        return memo[h2][0]
    else:
        memo[h2][h1] = min(frog(h,h1,h1-1)  + abs(h[h2]-h[h1]),frog(h,h1,h1-2)+abs(h[h2] - h[h1]))
        return memo[h2][h1]
    
   

s = input().split()

h = []
for i in range(N):
    h.append(int(s[i]))
print(min(frog(h,N-1,N-2),frog(h,N-1,N-3)))
#print(memo)

### FIXED CODE ###

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

if N ==2:
    print(abs(h[1] - h[0]))
else:
    dp = [10**4+1]*N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,N):
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i-2] + abs(h[i-2]-h[i-1]) + abs(h[i-1] - h[i]), dp[i-1]+abs(h[i-1]-h[i]))
        
    print(dp[N-1])
### BUGGY CODE ###

def examA():
    S = SI()
    T = SI()
    N = len(S)
    ans = "No"
    for i in range(N):
        cur = S[i:] + S[:i]
        #print(cur)
        if cur==T:
            ans = "Yes"
    print(ans)
    return

def examB():
    H, W = LI()
    S = [SI()for _ in range(H)]
    flag = True
    ans = 0
    print(ans)
    return

def examC():
    L, R = LI()
    ans = inf
    if R-L>=3000:
        R = L+3000

    for l in range(L, R + 1):
        for r in range(l+1, R + 1):
            now = (l*r) %2019
            ans = min(ans,now)
    print(ans)
    return

def examD():
    T = ["dream", "dreamer", "erase", "eraser"]
    S = SI()
    ans = "NO"
    t = ""
    for s in S[::-1]:
        t += s
        if t[::-1] in T:
            t = ""
    if t=="":
        ans = "YES"
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

### FIXED CODE ###

def examC():
    St = S()
    t = ["dream", "dreamer", "erase", "eraser"]
    i = len(St)-1
    cur = ""
    while i>=0:
#        print(cur)
        cur = St[i] + cur
        i -=1
        if cur in t:
            cur = ""
    if len(cur)==0:
        ans = "YES"
    else:
        ans = "NO"
    print(ans)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N, M, Q = map(int, input().split(" "))
	N_list = [[0 for _ in range(N)] for _ in range(N)]
	
	for _ in range(M):
		l, r = map(int, input().split(" "))
		l -= 1
		r -= 1
		N_list[l][r] += 1
		
	for _ in range(Q):
		p, q = map(int, input().split(" "))
		p -= 1
		q -= 1
		
		ans = 0
		for i in range(p, q+1):
			for j in range(p, q+1):
				ans += N_list[i][j]
		print(ans)
		
	
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N, M, Q = map(int, input().split(" "))
	N_list = [[0 for _ in range(N)] for _ in range(N)]
	
	for _ in range(M):
		l, r = map(int, input().split(" "))
		l -= 1
		r -= 1
		N_list[l][r] += 1
		
	#print(N_list)
	
	for i in range(N):
		for j in range(N):
			if i == 0 and j == 0:
				continue
			if i == 0:
				N_list[i][j] = N_list[i][j] + N_list[i][j-1]
				continue
			if j == 0:
				N_list[i][j] = N_list[i][j] + N_list[i-1][j]
				continue
			N_list[i][j] = N_list[i][j] + N_list[i-1][j] + N_list[i][j-1] - N_list[i-1][j-1]
			
	#print(N_list)
		
	for _ in range(Q):
		p, q = map(int, input().split(" "))
		p -= 1
		q -= 1
		
		a = 0
		b = 0
		c = 0
		if p != 0:
			a = N_list[q][p-1]
			b = N_list[p-1][q]
			c = N_list[p-1][p-1]
		ans = N_list[q][q] - a - b + c
		print(ans)
		
	
if __name__ == "__main__":
	main()
### BUGGY CODE ###

k, s = map(int, input().split())
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i+j+l==s:
                cnt += 1
print(cnt)

### FIXED CODE ###

k, s = map(int, input().split())
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        if 0<=s-i-j<=k:
            cnt += 1
print(cnt)
### BUGGY CODE ###

import sys

s = int(input())

# (0,0),(0,x),(x,y)

for val in range(1,10**9):
    if (s/val < 10**9) and s%val==0 :
        print(0,0,val,0,0,int(s/val))
        sys.exit(0)


### FIXED CODE ###

S = int(input())
X1, Y1, X2, Y2 = 0, 0, 10**9, 1
shou, amari = divmod(S, 10**9)
 
if amari == 0:
    Y3 = shou
    X3 = 0
else:
    Y3 = shou + 1
    X3 = -(amari - 10**9)
 
print(X1, Y1, X2, Y2, X3, Y3)
### BUGGY CODE ###

mod = 10**9+7
 
s = input()
n = len(s)
 
dp = [0]*13
dp[0] = 1
 
for i in range(n):
  dp2 = [0]*13  
  for j in range(10):
    if s[i] == '?' or s[i] == str(j):
      for k in range(13):
        dp2[(k*10 + j)%13] += dp[k]
        dp2[(k*10 + j)%13] %= mod
        
  dp = dp2
 
print(dp[5])

### FIXED CODE ###

mod = 10**9+7
 
s = input()
n = len(s)
 
dp = [0]*13
dp[0] = 1
 
for i in range(n):
  dp2 = [0]*13  
  for j in range(10):
    if s[i] == '?' or s[i] == str(j):
      for k in range(13):
        dp2[(k*10 + j)%13] += dp[k]
        dp2[(k*10 + j)%13] %= mod
        
  dp = dp2
 
print(dp[5])
### BUGGY CODE ###

import sys


def main():
    n = int(sys.stdin.readline().strip())
    l = [int(s) for s in sys.stdin.readline().strip().split()]
    # n = 4
    # l = [1, 2, 3, 4]

    l.sort()

    # [lo, hi)
    # Returns -1 if no valid item
    def b_search(lo, hi, limit):
        if lo >= hi:
            return -1
        if lo + 1 == hi:
            return lo
        assert lo + 1 < hi
        mid = (lo + hi) // 2
        if l[mid] < limit:
            return b_search(mid, hi, limit)
        else:
            return b_search(lo, mid, limit)

    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            a_plus_b = l[i] + l[j]
            valid_longest_idx = b_search(j, n, a_plus_b)
            ans += valid_longest_idx - j

    print(ans)


main()


### FIXED CODE ###

import sys


def main():
    n = int(sys.stdin.readline().strip())
    l = [int(s) for s in sys.stdin.readline().strip().split()]
    # n = 4
    # l = [1, 2, 3, 4]

    l.sort()

    # [lo, hi)
    # Returns -1 if no valid item
    def b_search(lo, hi, limit):
        while lo + 1 < hi:
            mid = (lo + hi) // 2
            if l[mid] < limit:
                lo = mid
            else:
                hi = mid
        if lo >= hi:
            return -1
        if lo + 1 == hi:
            return lo

    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            a_plus_b = l[i] + l[j]
            valid_longest_idx = b_search(j, n, a_plus_b)
            ans += valid_longest_idx - j

    print(ans)


main()
### BUGGY CODE ###

import numpy as np
h,w = map(int,input().split())
stage = [["#" for x in range(w+2)] for x in range(h+2)]
for i in range(1,h+1):
    stage[i][1:w+1] = list(input())
dp = np.zeros([h+2,w+2],dtype=int)
dp[1][1] = 1
for j in range(1,h+1):
    for i in range(1,w+1):
        dp[j][i] = dp[j][i]%(10**9+7)
        if(stage[j+1][i] == "."):
            dp[j+1][i] += dp[j][i]
        if(stage[j][i+1] == "."):
            dp[j][i+1] += dp[j][i]
print(dp[h][w])


### FIXED CODE ###

h,w = map(int,input().split())
stage = [["#" for x in range(w+2)] for x in range(h+2)]
for i in range(1,h+1):
    stage[i][1:w+1] = list(input())
dp = [[0 for x in range(w+2)] for x in range(h+2)]
dp[1][1] = 1
for j in range(1,h+1):
    for i in range(1,w+1):
        dp[j][i] = dp[j][i]%(10**9+7)
        if(stage[j+1][i] == "."):
            dp[j+1][i] += dp[j][i]
        if(stage[j][i+1] == "."):
            dp[j][i+1] += dp[j][i]
print(dp[h][w])
### BUGGY CODE ###

from itertools import combinations
N = int(input())
S = input().strip()
G = {chr(i):[] for i in range(97,123)}
for i in range(N):
    G[S[i]].append(i)
cmax = 0
for a in G:
    for x in combinations(G[a],2):
        i,j = x[0],x[1]
        if i>j:
            i,j = j,i
        cnt = 0
        for k in range(j-i):
            if j+k<N and S[i+k] == S[j+k]:
                cnt += 1
            else:break
        cmax = max(cmax,cnt)
        
print(cmax)

### FIXED CODE ###

N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)