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

from bisect import bisect_left
n, m = map(int, input().split())
p, y = [0]*m, [0]*m
dict_p = {}
for i in range(m):
    p[i], y[i] = map(int, input().split())
    if p[i] not in dict_p.keys():
        dict_p[p[i]] = list()

    dict_p[p[i]].append(y[i])
#print(dict_p)
ans = [0]*m
for i in range(m):
    dict_p[p[i]].sort()

for i in range(m):
    x = bisect_left(dict_p[p[i]], y[i])
    ans = "{:006}".format(p[i]) + "{:006}".format(x+1)
    print(ans)


### FIXED CODE ###

from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
py = []
dict_p = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    py.append((p, y))
    dict_p[p].append(y)
#print(dict_p)
for values in dict_p.values():
    values.sort()

for p, y in py:
    x = bisect_left(dict_p[p], y)
    ans = "{:006}".format(p) + "{:006}".format(x+1)
    print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
#長さnの文字列s
def gene_hash(i,j): #特定範囲のハッシュを返す s[i:j]
    return (hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1

base1 = 1007
mod1 = 10**9+7

hash1 = [0]*(n+1)
power1 = [1]*(n+1)

for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1
    
lef = 0
rig = n//2 + 1

while rig - lef > 1:
    mid = (rig+lef)//2
    Flag = False
    for i in range(n-2*mid+1):
        if Flag:
            break
        now = gene_hash(i,i+mid)
        for j in range(i+mid,n-mid+1):
            if now == gene_hash(j,j+mid):
                Flag = True
                break
    if Flag:
        lef = mid
    else:
        rig = mid
print(lef)

### FIXED CODE ###

n = int(input())
s = input()
#長さnの文字列s
def gene_hash(i,j): #特定範囲のハッシュを返す s[i:j]
    return (hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1

base1 = 1007
mod1 = 10**9+7

hash1 = [0]*(n+1)
power1 = [1]*(n+1)

for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1
    
lef = 0
rig = n//2 + 1

while rig - lef > 1:
    mid = (rig+lef)//2
    Flag = False
    for i in range(n-2*mid+1):
        if Flag:
            break
        now = gene_hash(i,i+mid)
        for j in range(i+mid,n-mid+1):
            if now == gene_hash(j,j+mid):
                Flag = True
                break
    if Flag:
        lef = mid
    else:
        rig = mid
print(lef)
### BUGGY CODE ###

S=input()
Q=int(input())
import sys
flag=False

for _ in range(Q):
  s = list(sys.stdin.readline())
  if s[0]=="1":
    if flag:
      flag=False
    else:
      flag=True
  else:
    if s[2]=="1":
      if flag:
        S="".join( [ S,s[4] ] )
      else:
        S="".join( [ s[4],S ] )
    else:
      if flag:
        S="".join( [ s[4],S ] )
      else:              
        S="".join( [ S,s[4] ] )
        
if flag:
  S=S[::-1]
print(S)

### FIXED CODE ###

S=input()
Q=int(input())
import sys
from collections import deque
d=deque()
for _ in S:
  d.append(_)
flag=False

for _ in range(Q):
  s = list(sys.stdin.readline())
  if s[0]=="1":
    if flag:
      flag=False
    else:
      flag=True
  else:
    if s[2]=="1":
      if flag:
        d.append(s[4])
      else:
        d.appendleft(s[4])
    else:
      if flag:
        d.appendleft(s[4])
      else:
        d.append(s[4])
      
if flag:
  d.reverse()
  
print("".join(d))
### BUGGY CODE ###

import copy
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
p = 0
c.sort()
q = 0
count = 0
x = 0
for i in range(n):
    p = 0
    q = 0
    while p<n:
        if (b[p] > a[i]):
            while q<n:
                if (c[q] > b[p]):
                    count += (n-q)
                    
                    p += 1
                    break
                else:
                    q += 1
        else:
            p += 1
print(count)

### FIXED CODE ###

import bisect
n= int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    x = bisect.bisect_left(a,b[i])
    y = bisect.bisect_right(c,b[i])
    ans += x*(n-y)
print(ans)
### BUGGY CODE ###

H,W = map(int,input().split())
masu = [list(input()) for _ in range(H)]
from collections import deque
def bfs():
    que = deque()
    seen = [[0]*(W+2)] + [[0] + [-1]*(W)+[0]  for _ in range(H)] +[[0]*(W+2)] 
    for w in range(W):
        for h in range(H):
            if masu[h][w] == '#':
                que.append((w,h))
                seen[h+1][w+1] =0
    while que:
        a,b = que.popleft()
        for x,y in [[0,1],[1,0],[0,-1],[-1,0]]:
            nx = a+x
            ny = b+y
            if seen[ny+1][nx+1] == -1:
                seen[ny+1][nx+1] = seen[b+1][a+1]+1
                que.append((nx,ny))
    ans = max(map(max,seen))
    return ans
print(bfs())

### FIXED CODE ###

from collections import deque
 
def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k
 
h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))
### BUGGY CODE ###

r,g,b,n = map(int,input().split())
ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        temp = n-r*i-g*j
        if temp>=0 and temp%b==0: ans+=1
print(ans)

### FIXED CODE ###

r,g,b,n = map(int,input().split())
ans = 0
for i in range(n//r+1):
    for j in range((n-r*i)//g+1):
        if (n-r*i-g*j)%b==0:
            ans+=1
print(ans)
### BUGGY CODE ###

H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]
dp=[0]+[float('inf') for _ in range(2*10**4)]
for a, b in AB:
  for i in range(a, H+a):
    dp[i]=min(dp[i-a]+b, dp[i])
    
print(min(dp[H:]))

### FIXED CODE ###

H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]

nums=[-1]*20001
for i in range(N):
  if nums[AB[i][0]]<0:
    nums[AB[i][0]]=AB[i][1]
  else:
    nums[AB[i][0]]=min(AB[i][1], nums[AB[i][0]])
  
for i in range(1, H):
  if nums[i]>0:
    for j in range(N):
      if nums[i+AB[j][0]]>0:
        if nums[i+AB[j][0]]>nums[i]+AB[j][1]:
          nums[i+AB[j][0]]=nums[i]+AB[j][1]
      else:
        nums[i+AB[j][0]]=nums[i]+AB[j][1]
      
anss=[]
for i in range(H, 20000):
  if nums[i]>0:
    anss.append(nums[i])
    
print(min(anss))
### BUGGY CODE ###

N, K = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

K_value = 1
for i in range(K):
    K_value *= a[i]
    
score_dict = {K-1:K_value}

for i in range(K, N):
    score_dict[i] = (score_dict[i-1] * a[i]) // a[i-K]
    if score_dict[i] > score_dict[i-1]:
        print('Yes')
    else:
        print('No')



### FIXED CODE ###

N, K = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

for i in range(K, N):
    if a[i-K] < a[i]:
        print('Yes')
    else :
        print('No')
### BUGGY CODE ###

N = int(input())

ct = 0
for a in range(1, N):
    for b in range(1, N):
        if a*b >= N:
            break
        ct += 1
        
print(ct)

### FIXED CODE ###

N = int(input())

ct = 0
for i in range(1, N):
    if i * i >= N:
        break
    x = int((N - 1)/i)
    ct += (x - i)*2 + 1
print(ct)
### BUGGY CODE ###

N= input()
a = raw_input().split()
#print a

b=""
for i,val in enumerate(a):
	if i%2==1:
		if b[-1]==" ":
			b=b+val
		else:
			b=b+" "+val
	else:
		b=val+" "+b
else:
	if N%2==0:
		print b[::-1]
	else:
		print b


### FIXED CODE ###

n= input()
a = map(int,raw_input().split())
#print a

l=[ i for i in range(n)]
l_gusu=l[0::2]
l_kisu=l[1::2]

ans=[]
for i in reversed(list(l_gusu)):
	#print i,a[i]
	ans.append(a[i])

for i in l_kisu:
	ans.append(a[i])


ans_str=""
if n%2==0:
	for i in reversed(list(ans)):
		ans_str+=(str(i)+" ")
	print ans_str.strip()
else:
	for i in ans:
		ans_str+=(str(i)+" ")
	print ans_str.strip()
### BUGGY CODE ###

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = input_to_int_tuple()

    place = 1
    place_goned = [place]
    i = 0
    while i < n:
        place = a[place - 1]
        if place in place_goned:
            break

        place_goned.append(place)
        i += 1

    if k < len(place_goned):
        return place_goned[k]

    pre_loop_cnt = place_goned.index(place)
    move_cnt = k - pre_loop_cnt
    loop_list = place_goned[pre_loop_cnt:]
    return loop_list[move_cnt % len(loop_list)]


if __name__ == "__main__":
    print(main())


### FIXED CODE ###

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    visit = {place}
    place_visits = [place]
    for i in range(k):
        place = a[place]
        if place in visit:
            left = place_visits.index(place)
            return place_visits[left + (k - left) % (i + 1 - left)]
        else:
            visit.add(place)
            place_visits.append(place)

    return place


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

x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))[::-1]
c=sorted(list(map(int,input().split())))[::-1]
d=[]
for i in a:
  for j in b:
    d+=[i+j]
ans=[]
for i in c:
  for j in sorted(d)[::-1][:k]:
    ans+=[i+j]
print(*sorted(ans)[::-1][:k],sep='\n')

### FIXED CODE ###

x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
b=sorted(list(map(int,input().split())))[::-1]
c=sorted(list(map(int,input().split())))[::-1]
d=[]
for i in a:
  for j in b:
    d+=[i+j]
ans=[]
d=sorted(d)[::-1][:k]
for i in c:
  for j in d:
    ans+=[i+j]
print(*sorted(ans)[::-1][:k],sep='\n')
### BUGGY CODE ###

K, S = list(map(int, input().split()))
res = 0

for x in range(K + 1):
    tmp = S
    if tmp - x == 0:
        res += 1
        continue
    for y in range(K + 1):
        if tmp - x - y == 0:
            res += 1
            continue
        for z in range(K + 1):
            if tmp - x - y - z == 0:
                res += 1
                continue
print(res)


### FIXED CODE ###

K, S = list(map(int, input().split()))
res = 0

for x in range(K + 1):
    for y in range(K + 1):
        if S - x - y >= 0 and S - x - y <= K:
            res += 1
print(res)
### BUGGY CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)

class Node:
    def __init__(self):
        self.size = 1  # 自分以下のノードの数
        self.children = []

def dfs(v):
    V = Node()
    visited[v] = True
    for u in AL[v]:
        if visited[u]: continue
        U = dfs(u)
        V.size += U.size
        V.children.append(U)
    return V

def anaaki(V):
    ret = pow(2, n - 1, p) - 1
    for ch in V.children:
        ret -= pow(2, ch.size) - 1
        ret %= p
    ret -= pow(2, n - V.size) - 1
    ret %= p
    return ret

n = int(input())
AL = [[] for _ in range(n)]
visited = [False] * n
p = 10 ** 9 + 7
for i in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    AL[a].append(b)
    AL[b].append(a)

# dfs
root = dfs(0)
que = deque([root])
numer = 0
while que:
    next = que.popleft()
    numer += anaaki(next)
    numer %= p
    for ch in next.children:
        que.append(ch)

denom = pow(2, n, p)

print( numer * pow(denom, p - 2, p) % p)

### FIXED CODE ###

# classを使うのをやめてlistで実施する
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)
import sys
input = sys.stdin.readline

def dfs(v):
    visited[v] = True
    for i in range(len(AL[v][CHILDREN])):
        u = AL[v][CHILDREN][i]
        if visited[u]:
            AL[v][CHILDREN][i] = None
            continue
        AL[v][SIZE] += dfs(u)
    return AL[v][SIZE]


def anaaki(v):
    ret = powp - 1
    for ch in AL[v][CHILDREN]:
        if ch is None: continue
        ret -= pow(2, AL[ch][SIZE], p) - 1
        ret %= p
    ret -= pow(2, n - AL[v][SIZE], p) - 1
    ret %= p
    return ret

n = int(input())
SIZE = 0
CHILDREN = 1
AL = [[1, []] for _ in range(n)]
visited = [False] * n
p = 10 ** 9 + 7
powp = pow(2, n - 1, p)

for i in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    AL[a][CHILDREN].append(b)
    AL[b][CHILDREN].append(a)

dfs(0)
numer = 0
for i in range(n):
    numer += anaaki(i)
    numer %= p

denom = pow(2, n, p)
print(numer * pow(denom, p - 2, p) % p)
### BUGGY CODE ###


N = int(input())

con = True
for h in range(1,3500):
    for n in range(h,3500):
        memo1 = N*h*n
        memo2 = 4*h*n-N*n-N*h
        if memo2 != 0:
            memo3 = memo1/memo2
            memo4 = memo1%memo2
            if (memo4==0) and (memo3>=1):
                print(h,n,int(memo3))
                con = False
                break
    if not(con):
        break


### FIXED CODE ###

N = int(input())

con = True
for h in range(1,3500):
    for n in range(h,3500):
        memo1 = N*h*n
        memo2 = 4*h*n-N*n-N*h
        if memo2 != 0:
            memo3 = memo1/memo2
            memo4 = memo1%memo2
            if (memo4==0) and (memo3>=1):
                print(h,n,int(memo3))
                con = False
                break
    if not(con):
        break
### BUGGY CODE ###

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

        l = [0]*N

        for i in range(N-1):
                l[i] = A.count(i+1)
                print(l[i])
        print(l[N-1])

if __name__=="__main__":
        main()

### FIXED CODE ###

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

        l = [0]*N

        for a in A:
                l[a-1] += 1

        ans = "\n".join([str(x) for x in l])
        print(ans)

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

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


for i in range(len(a)):
    ans = ans * a[i]


if ans > 10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

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

ans = 1
list.sort(a, reverse = True)
ones = a.count(1)
for i in range(len(a)-ones):
    if 0 in a:
        ans =0
        break
    ans = ans * a[i]
    if ans >10**18:
        break

if ans >10**18:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

n, m = [int(i) for i in input().split()]
l = []
r = []
for _ in range(m):
    i, k = [int(i) for i in input().split()]
    l.append(i)
    r.append(k)

card = [0] * (n+1)
for i, j in zip(l, r):
    for k in range(i, j+1):
        card[k] += 1

print(card.count(m))


### FIXED CODE ###

n, m = [int(i) for i in input().split()]
l = []
r = []
for _ in range(m):
    i, k = [int(i) for i in input().split()]
    l.append(i)
    r.append(k)

res = min(r) - max(l) + 1 if min(r) >= max(l) else 0
print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict,deque
from itertools import combinations
from heapq import heappush, heappop

xs,ys,xt,yt = map(int,input().split())
N = int(input())
xyr = [list(map(int,input().split())) for i in range(N)]

#import random
#N = 1000
#xs,ys = (-10**9,-10**9)
#xt,yt = (10**9, 10**9)
#xyr = [[random.randint(-10**9, 10**9),random.randint(-10**9, 10**9),random.randint(1,10)] for i in range(N)]
#xyr = [[2*i,2*i,1] for i in range(N)]

xyr = [[xs,ys,0]] + xyr + [[xt,yt,0]]

cost = {}
for s in range(0,N+1):
    for t in range(s+1,N+2):
        x1,y1,r1 = xyr[s]
        x2,y2,r2 = xyr[t]
        R = pow((x2-x1)**2+(y2-y1)**2,0.5)
        c = max(0, R-r1-r2)
        cost[(s,t)] = c
        cost[(t,s)] = c

h = [(0,0)]
dist = [10**15] * (N+2)
dist[0] = 0
while h:
    v,d = heappop(h)
    if dist[v] < d:
        continue
    for nv in range(N+2):
        if v == nv:
            continue
        temp = d + cost[(v,nv)]
        if temp < dist[nv]:
            dist[nv] = temp
            heappush(h, (nv,temp))

print(dist[N+1])








### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict,deque
from itertools import combinations
from heapq import heappush, heappop

xs,ys,xt,yt = map(int,input().split())
N = int(input())
xyr = [list(map(int,input().split())) for i in range(N)]

#import random
#N = 1000
#xs,ys = (-10**9,-10**9)
#xt,yt = (10**9, 10**9)
#xyr = [[random.randint(-10**9, 10**9),random.randint(-10**9, 10**9),random.randint(1,10)] for i in range(N)]
#xyr = [[2*i,2*i,1] for i in range(N)]

xyr = [[xs,ys,0]] + xyr + [[xt,yt,0]]

cost = {}
for s in range(0,N+1):
    for t in range(s+1,N+2):
        x1,y1,r1 = xyr[s]
        x2,y2,r2 = xyr[t]
        R = pow((x2-x1)**2+(y2-y1)**2,0.5)
        c = max(0, R-r1-r2)
        cost[(s,t)] = c
        cost[(t,s)] = c

h = [(0,0)]
dist = [10**15] * (N+2)
dist[0] = 0
while h:
    d,v = heappop(h)
    if dist[v] < d:
        continue
    for nv in range(N+2):
        if v == nv:
            continue
        temp = d + cost[(v,nv)]
        if temp < dist[nv]:
            dist[nv] = temp
            heappush(h, (temp,nv))

print(dist[N+1])
### BUGGY CODE ###

s, k = map(int,input().split())
c = list()
while s >= 0:
    a = s % k
    c.append(a)
    s = s // k

print(len(c))


### FIXED CODE ###

s, k = map(int,input().split())
c = []
while s > 0:
    a = s % k
    c.append(a)
    s //= k

print(len(c))
### BUGGY CODE ###

from collections import Counter, defaultdict


def main():
    # n,m = [int(z) for z in input().split()]
    # table =[
    #     [int(z) for z in input().split()]
    #     for _ in range(n)
    # ]
    V = 10 ** 9 + 7
    n = int(input())
    c = [int(input()) for _ in range(n)]

    table = [0] * (n + 1)
    table[0] = 1

    D = defaultdict(lambda: [])

    for i in range(n):
        ci = c[i]
        if i != 0:
            if c[i - 1] == ci:
                table[i + 1] = table[i] % V
                continue

        pre = D[ci]
        res = table[i]
        for p_index in pre:
            res += table[p_index] % V
            res %= V
        table[i + 1] = res % V

        D[ci].append(i)

    print(table[-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import Counter, defaultdict


def main():
    # n,m = [int(z) for z in input().split()]
    # table =[
    #     [int(z) for z in input().split()]
    #     for _ in range(n)
    # ]
    V = 10 ** 9 + 7
    n = int(input())
    c = [int(input()) for _ in range(n)]

    table = [0] * (n + 1)
    table[0] = 1

    D = defaultdict(lambda: 0)

    for i in range(n):
        ci = c[i]
        if i != 0:
            if c[i - 1] == ci:
                table[i + 1] = table[i] % V
                continue

        res = table[i]
        pre = D[ci]
        res += pre
        table[i + 1] = res % V

        D[ci] = D[ci] + table[i] % V

    print(table[-1])


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

K = int(input())
if K % 2 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)


### FIXED CODE ###

K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)
### BUGGY CODE ###

R,G,B,N=map(int,input().split())
count=0
wa=0
for i in range(int(N/R)+1):
    for j in range(int((N-i*R)/G)+1):
       b=(N-i*R-j*G)/B
       if b>=0 and float.is_integer(b)==True:
           count=count+1
     
print(count)

### FIXED CODE ###

R,G,B,N=map(int,input().split())
count=0
wa=0
for i in range(int(N/R)+1):
    for j in range(int((N-i*R)/G)+1):
        b=(N-i*R-j*G)/B
        if b>=0 and float.is_integer(b)==True:
            count=count+1

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

while True:
    try:
        n = int(raw_input())
        count = 0
        for a in range(1000,-1,-1):
            na = n - a
            if 3000 < na:
                break
            elif 0 <= na <= 3000:
                for b in range(1000,-1,-1):
                    nab = n - a - b
                    if nab > 2000:
                        break
                    elif 0 <= nab <= 1000:
                        count += nab+1
                    elif 1001 < nab <= 2000:
                        count += (2000 - nab + 1)
        print count
    except:
        break

### FIXED CODE ###

import sys
def N(n):
    return (n+1)*(n+2)*(n+3)/6
for n in sys.stdin:
    n = int(n)
    if n > 2000:
        n = 4000 - n
    if n < 1001:
        print N(n)
    else:
        m = n - 1000
        print N(n) - (N(2*m) - m - 1)/2
### BUGGY CODE ###

N,M=map(int,input().split())

parent=[i for i in range(M)]
depth=[0 for i in range(M)]

def root(x):
  temp=x
  while x!=parent[x]:
    t=x
    x=parent[x]
    parent[t]=x
  parent[temp]=x
  return parent[x]
  
def same(x,y):
  return root(x)==root(y)

def union(x,y):
  x=root(x)
  y=root(y)
  if x==y:
    return
  if depth[x]>depth[y]:
    parent[y]=x
  else:
    parent[x]=y
    if depth[x]==depth[y]:
      depth[x]+=1
      
h=[None]*N
langs=set()
for i in range(N):
  k,*h=map(int,input().split())
  for j in range(k-1):
    langs.add(h[j]-1)
    union(h[j]-1,h[j+1]-1)
  langs.add(h[k-1]-1)
  
roots=set()
for l in langs:
  roots.add(root(l))
  
print(("NO","YES")[len(roots)==1])

### FIXED CODE ###

# 人も言語もグラフの頂点と見なす
# ある人がある言語を話せる場合連結となる
# 頂点のキーは[言語 or 人][番号(人番号 or 言語番号)]
# 0:言語 1:人

N,M = map(int,input().split())
from collections import defaultdict
E = [[],[]]
E[0] = [[] for i in range(M)]
E[1] = [[] for i in range(N)]

for i in range(N):
  langs = list(map(int,input().split()))[1:]
  for lang in langs:
    E[1][i].append((0,lang-1))
    E[0][lang-1].append((1,i))
    
# 任意の頂点からBFSして、全ての人の頂点が往訪済みになればOK
from collections import deque
q = deque([])
# 人で、0番目からスタート
q.append((1,0))
seen = [[],[]]
seen[0] = [False for i in range(M)]
seen[1] = [False for i in range(N)]

while q:
  kind,v = q.popleft()
  if seen[kind][v]:
    continue
  seen[kind][v] = True
  children = E[kind][v]
  for child in children:
    q.append([child[0],child[1]])
    
for s in seen[1]:
  if not s:
    print("NO")
    break
else:
  print("YES")
### BUGGY CODE ###

n=int(input())
an=[]
an=[int(input()) for i in range(n)]
for i in range(n):
    an_a=an[0:n]
    an_a.pop(i)
    print(max(an_a))

### FIXED CODE ###

n=int(input())
an=[]
an=[int(input()) for i in range(n)]
s_an=sorted(an,reverse=True)
m_an=max(an)
m_an2=s_an[1]
for i in an:
    if m_an==i:
        print(m_an2)
    else:
        print(m_an)