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

import heapq
def dijkstra(x,route):
    n=len(route)
    d=[float('inf')]*n
    d[x]=0
    visited={x}
    hq=[(0,x)]
    while hq:
        u=heapq.heappop(hq)[1]
        visited.add(u)
        for v,cost in route[u]:
            if (v not in visited) and d[v]>d[u]+cost:
                d[v]=d[u]+cost
                heapq.heappush(hq,(d[v],v))
    return d

def dist(V1,V2):
    dx=V2[0]-V1[0]; dy=V2[1]-V1[1]
    sum_r=V1[2]+V2[2]
    return max(0,(dx**2+dy**2)**0.5-sum_r)

import sys
input=sys.stdin.readline
sx,sy,gx,gy=map(int,input().split())
n=int(input())
V=[(sx,sy,0)]+[tuple(map(int,input().split())) for _ in range(n)]+[(gx,gy,0)]
Edges=[[] for _ in range(n+2)]
for i in range(n+2):
    for j in range(n+2):
        if i==j:
            continue
        d=dist(V[i],V[j])
        Edges[i].append((j,d))
print(dijkstra(0,Edges)[-1])

### FIXED CODE ###

import sys
input=sys.stdin.readline

def dijkstra(s,n,Cost):
    D=[float('inf')]*n
    Visited=[False]*n
    D[s]=0
    while True:
        v=-1
        for i in range(n):
            if (not Visited[i]) and v==-1:
                v=i
            elif (not Visited[i]) and D[i]<D[v]:
                v=i
        if v==-1:
            break
        Visited[v]=True
        for j in range(n):
            D[j]=min(D[j],D[v]+Cost[v][j])
    return D

def dist(V1,V2):
    return max(0,((V2[0]-V1[0])**2+(V2[1]-V1[1])**2)**0.5-(V1[2]+V2[2]))

sx,sy,gx,gy=map(int,input().split())
n=int(input())
V=[(sx,sy,0)]+[tuple(map(int,input().split())) for _ in range(n)]+[(gx,gy,0)]
Cost=[[float('inf')]*(n+2)for _ in range(n+2)]
for i in range(n+1):
    for j in range(i,n+2):
        d=dist(V[i],V[j])
        Cost[i][j]=d; Cost[j][i]=d
print(dijkstra(0,n+2,Cost)[-1])
### BUGGY CODE ###

n, m = map(int, input().split())
ps = list(map(int, input().split()))
s = sum(ps)
ls = []
for p in ps:
    prev = p
    while p > 0:
        p //= 2
        ls.append(prev - p)
        prev = p
ls.sort(reverse=True)
print(s - sum(ls[:m]))

### FIXED CODE ###

n, m = map(int, input().split())
ps = list(map(int, input().split()))
s = sum(ps)
ls = []
for p in ps:
    prev = p
    while p > 0:
        p //= 2
        ls.append(prev - p)
        prev = p
ls.sort(reverse=True)
print(s - sum(ls[:m]))
### BUGGY CODE ###

# coding: utf-8

n = int(input())    # 2 <= n <= 10^5
h = list(map(int, input().rstrip().split()))
cost = lambda f, t: abs(h[t] - h[f])
# dp[j][i]
#   j 回目のジャンプでiにいるために必要な最低コストを格納
dp = [[float('inf')] * n for _ in range(n)]
for i in dp:
    i[0] = 0
for j in range(1, n):
    for i in range(1, n):
        dp[j][i] = min( \
            dp[j - 1][i], \
            float('inf') if i < 1 else \
                dp[j - 1][i - 1] + abs(h[i - 1] - h[i]), \
            float('inf') if i < 2 else \
                dp[j - 1][i - 2] + abs(h[i - 2] - h[i]))
print(dp[n - 1][n - 1])


### FIXED CODE ###

# coding: utf-8

n = int(input())    # 2 <= n <= 10^5
h = list(map(int, input().rstrip().split()))
dp = [0]
for i in range(1, n):
    dp.append(min( \
        dp[i - 1] + abs(h[i - 1] - h[i]), \
        float('inf') if i < 2 else dp[i - 2] + abs(h[i - 2] - h[i])))
print(dp[- 1])
### BUGGY CODE ###

from copy import deepcopy
n,k=map(int, input().split())
a=list(map(int,input().split()))
tmp = 1
for i in range(k):
    tmp*=a[i]
p = tmp
p //= a[0]
p *= a[k]
for j in range(n-k):
    #print(tmp,p)
    if tmp < p:
        print("Yes")
    else:
        print("No")
    if k+j+1 > n-1:
        break
    tmp = p
    #print(a[j+1],a[k+j])
    p //= a[j+1]
    p *= a[k+j+1]


### FIXED CODE ###

n,k = map(int, input().split())
a=list(map(int,input().split()))
for i in range(n-k):
    #print(i,k+i)
    if a[i] < a[k+i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

l,r=map(int,input().split())
ans=2018
for i in range(l,r):
    for j in range(i+1,r+1):
        if i*j%2019<ans:
            ans=i*j%2019
        if ans==0:
            break
print(ans)


### FIXED CODE ###

l,r=map(int,input().split())
ans=2018
d=r-l
if d>2019:
    d=2019

for i in range(l%2019,l%2019+d):
    for j in range(i+1,l%2019+d+1):
        a=(i*j)%2019
        if a<ans:
            ans=a
print(ans)
### BUGGY CODE ###

def main():
    N, Q = [int(v) for v in input().split()]

    va = [N-1] * (N - 1)
    ha = [N-1] * (N - 1)

    count = 0
    black = (N - 2) * (N - 2)
    vmax = N - 1
    hmax = N - 1
    for i in range(Q):
        a, b = [int(v)-1 for v in input().split()]
        if a == 0:
            i = ha[b]
            if vmax > b:
                vmax = b
                va[1:i] = [b] * (i - 1)
            count += i - 1
        else:
            i = va[b]
            if hmax > b:
                hmax = b
                ha[1:i] = [b] * (i - 1)
            count += i - 1

    print(black - count)

main()

### FIXED CODE ###

def main():
    N, Q = [int(v) for v in input().split()]

    Query = [[int(v)-1 for v in input().split()] for _ in range(Q)]

    rows = [N-1] * (N - 1)
    cols = [N-1] * (N - 1)

    black = (N - 2) * (N - 2)
    min_row = N - 1
    min_col = N - 1

    for ty, x in Query:
        if ty == 0:
            if x < min_col:
                for j in range(x, min_col):
                    rows[j] = min_row
                min_col = x
            black -= rows[x] - 1
        else:
            if x < min_row:
                for j in range(x, min_row):
                    cols[j] = min_col
                min_row = x
            black -= cols[x] - 1

    print(black)

main()
### BUGGY CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

A_length = len(A)
# print(A_length)

left = [A.pop(0)]
right = A

# print(left)
# print(right)

left_max = max(left)
right_max = max(right)
print(right_max)


for i in range(A_length-2):
    temp = right.pop(0)
    if temp == right_max:
        right_max = max(right)
    print(max(left_max, right_max))
    if temp > left_max:
        left_max = temp
    left.append(temp)

temp = right.pop(0)
if temp > left_max:
    lef_max = temp
left.append(temp)
print(left_max)


### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

A_max = max(A)
A_second = A_max

if A.count(A_max) == 1:
  AA = []
  for a in A:
    if a != A_max:
      AA.append(a)
  A_second = max(AA)

for i in range(len(A)):
  if A[i] == A_max:
    print(A_second)
  else:
    print(A_max)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7
S=S[::-1]

dp=defaultdict(lambda: 0)

for i,x in enumerate(S):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[(i,(x*pow(10,i,13))%13)]=1
        else:
            for x in range(10):
                dp[(i,(x*pow(10,i,13))%13)]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                n=(x*pow(10,i,13)+j)%13
                dp[(i,n)]+=dp[(i-1,j)]
                dp[(i,n)]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    n=(x*pow(10,i,13)+j)%13
                    dp[(i,n)]+=dp[(i-1,j)]
                    dp[(i,n)]%=mod
print dp[(N-1,5)]%mod


### FIXED CODE ###

S=raw_input()
S=S[::-1]
l=len(S)

dp=[ 0 for j in range(13) ]
dp[0]=1

mod=10**9+7

dp2=[ 0 for _ in range(13) ]

keta=1

for i in range(1,l+1):
	dp2=[0]*13
	for j in range(13):
		if dp[j]!=0:
			if S[i-1]=="?":
				for k in range(10):
					next=(k*keta+j)%13 
					dp2[next]+=dp[j]
					dp2[next]%=mod
			else:
				k=int(S[i-1])
				next=(k*keta+j)%13
				dp2[next]+=dp[j]
				dp2[next]%=mod

	dp=dp2
	keta=(keta*10)%13

print dp[5]
### BUGGY CODE ###

#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,m = map(int, input().split())
l = [list(map(int,input().split())) for i in range(m)]

# n,mが10^5なのでO(n)は間に合わない
ans = 0
for i in range(1,n+1):
    flg = True
    for j in range(m):
        if i < l[j][0] or i > l[j][1]:
            flg = False
    if (flg):
        ans+=1
print(ans)




### FIXED CODE ###

#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,m = map(int, input().split())
l = [list(map(int,input().split())) for i in range(m)]

# n,mが10^5なのでO(n^2)は間に合わない
"""
ans = 0
for i in range(1,n+1):
    flg = True
    for j in range(m):
        if i < l[j][0] or i > l[j][1]:
            flg = False
    if (flg):
        ans+=1
print(ans)
"""

#lをO(m)で走査して上限、下限をあらかじめ確定しておく
up = 10**5+1
lo = 0

for i in range(m):
    if lo < l[i][0]:
        lo = l[i][0]
    if  up > l[i][1]:
        up = l[i][1]

ans = 0
for i in range(1,n+1):
    if i >= lo and i <= up:
        ans+=1
print(ans)
### BUGGY CODE ###

S = input()

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12
for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
    for j in range(13):
      nextdp[j] %= num_mod
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
      nextdp[(j*10 + int(S[i]))%13] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])

### FIXED CODE ###

S = input()
# S = '?'*100000

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12

for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
  for j in range(13):
    nextdp[j] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])
### BUGGY CODE ###

#!/usr/bin/env python3
#import sys; sys.stdin=open('input_file.txt')
#------------------------------------------
import numpy as np

N,K = map(int,input().split())
A = np.array(list(map(int,input().split())),dtype=np.int64)

A = np.sort(A)

hi = 10**18+1
lo = -10**18-1

while hi-lo > 1:
    mid = (hi+lo)//2
    under_mid = 0

    for i in range(N):
        if A[i] == 0:
            if mid > 0:
                under_mid += N
        elif A[i] > 0:
            under_mid += np.searchsorted(A,-(-mid//A[i]),side='left')
            #under_mid += bisect_left(A,-(-mid//A[i]))
        else:
            under_mid += N-np.searchsorted(A,mid//A[i],side='right')
            #under_mid += N-bisect_right(A,mid//A[i])
        if A[i]*A[i] < mid:
            under_mid -= 1
    under_mid //= 2

    if under_mid < K:
        lo = mid
    else:
        hi = mid

print(lo)


### FIXED CODE ###

#!/usr/bin/env python3
#import sys; sys.stdin=open('input_file.txt')
#------------------------------------------
import numpy as np

N,K = map(int,input().split())
A = np.array(input().split(),dtype=np.int64)

A = np.sort(A)

pos = A[A>0]
neg = A[A<0]
zero = len(A[A==0])

hi = 10**18+1
lo = -10**18-1

while hi-lo > 1:
    mid = (hi+lo)//2
    under_mid = 0

    if mid > 0: under_mid += N*zero
    under_mid += np.searchsorted(A,-(-mid//pos),side='left').sum()
    under_mid += (N-np.searchsorted(A,mid//neg,side='right')).sum()
    under_mid -= np.count_nonzero(A*A < mid)
    under_mid //= 2

    if under_mid < K:
        lo = mid
    else:
        hi = mid

print(lo)
### BUGGY CODE ###

N = int(input())
print(sum(range(1, N)))

### FIXED CODE ###

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

n = int(input())
num_list = list()
string = input().split()
for i in range(n):
	num_list.append(int(string[i]))
pro = 1
for number in num_list:
	pro *= number
if pro > 10**18:
	pro = -1
print(pro)

### FIXED CODE ###

n = int(input())
num_list = list()
string = input().split()
for i in range(n):
	num_list.append(int(string[i]))
del n
del string
num_list = sorted(num_list)
pro = 1
for number in num_list:
	pro *= number
	if pro > 10**18:
		pro = -1
		break
print(pro)
### BUGGY CODE ###

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

rets = [1] * n
ls = []
rs = []
for _ in range(m):
  l, r = map(int, input().split())
  for i in range(n):
    if i < l-1 or i > r-1:
      rets[i] = 0
print(sum(rets))




### FIXED CODE ###

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

import numpy as np

rets = np.array([0] * n)
lmax = 1
rmin = n
for _ in range(m):
  l, r = map(int, input().split())
  lmax = max(l, lmax)
  rmin = min(r, rmin)
print(rmin - lmax + 1 if rmin - lmax + 1 > 0 else 0)
### BUGGY CODE ###

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

l = 0
r = n
while r-l > 1:
    m = (l+r)//2
    c = s[m]
    idx = m
    for j in range(q):
        if x[j][0] == c:
            if idx == 0 and x[j][1] == "L":
                l = m
                break
            elif idx == n-1 and x[j][1] == "R":
                r = m
                break
            else:
                if x[j][1] == "L":
                    c = s[idx-1]
                    idx -= 1
                else:
                    c = s[idx+1]
                    idx += 1

        if j == q-1:
            r = m
idx1 = l

l = 0
r = n
while r-l > 1:
    m = (l+r)//2
    c = s[m]
    idx = m
    for j in range(q):
        if x[j][0] == c:
            if idx == 0 and x[j][1] == "L":
                l = m
                break
            elif idx == n-1 and x[j][1] == "R":
                r = m
                break
            else:
                if x[j][1] == "L":
                    c = s[idx-1]
                    idx -= 1
                else:
                    c = s[idx+1]
                    idx += 1

        if j == q-1:
            l = m
idx2 = r
print(max(n-(idx1+1)-(n-idx2), 0))


### FIXED CODE ###

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

l = 0
r = n
while r-l > 1:
    m = (l+r)//2
    c = s[m]
    idx = m
    for j in range(q):
        if x[j][0] == c:
            if idx == 0 and x[j][1] == "L":
                l = m
                break
            elif idx == n-1 and x[j][1] == "R":
                r = m
                break
            else:
                if x[j][1] == "L":
                    c = s[idx-1]
                    idx -= 1
                else:
                    c = s[idx+1]
                    idx += 1

        if j == q-1:
            r = m
idx1 = l

l = 0
r = n
while r-l > 1:
    m = (l+r)//2
    c = s[m]
    idx = m
    for j in range(q):
        if x[j][0] == c:
            if idx == 0 and x[j][1] == "L":
                l = m
                break
            elif idx == n-1 and x[j][1] == "R":
                r = m
                break
            else:
                if x[j][1] == "L":
                    c = s[idx-1]
                    idx -= 1
                else:
                    c = s[idx+1]
                    idx += 1

        if j == q-1:
            l = m
idx2 = r
print(n-(idx1+1)-(n-idx2))
### BUGGY CODE ###

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

s = str(input())

x = int(0)
i = int(len(s))

while "01" in s:
    s=s.replace("01","")
    s=s.replace("10","")
    x = x + i- int(len(s))
    i = int(len(s))

while "10" in s:
    s=s.replace("10","")
    x = x + i- int(len(s))
    i = int(len(s))

print(x)

### FIXED CODE ###

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

s = str(input())

x = int(0)
i = int(len(s))

s0 = int(len(s.replace("1","")))
s1 = i-s0

print(int(2*min(s0,s1)))
### BUGGY CODE ###

import numpy as np
 
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
F = [int(x) for x in input().split()]

A.sort()
F.sort(reverse=True)
 
new_list_a = np.array(A)
new_list_f = np.array(F)
time = new_list_f * new_list_a
 
for i in range(K):
  number_a = np.argmax(time)
  new_list_a[number_a] = new_list_a[number_a] - (i - (i - 1))
  time = new_list_f * new_list_a
  
print(max(time))

### FIXED CODE ###

import numpy as np

import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
F = np.array(input().split(), np.int64)

A.sort()
F.sort()

F= F[::-1]

left = -1
right = (A * F).sum()
while left + 1 < right:
  middle = (left + right) // 2
  right_arr = np.maximum(0, A - middle // F).sum() <= K
  if right_arr:
    right = middle
  else:
    left = middle
print(right)
### BUGGY CODE ###

n=int(input())
list=[]
list1=[]
for i in range(n):
    a,b=map(str,input().split())
    if a=="insert":
        list.append(b)
    if a=="find":
        if b in list:
            list1.append("yes")
        else:
            list1.append("no")

for i in list1:
    print(i)


### FIXED CODE ###

n=int(input())
list={}
list1=[]
for i in range(n):
    a,b=map(str,input().split())
    if a=="insert":
        list.setdefault(b,i)
    if a=="find":
        if b in list:
            list1.append("yes")
        else:
            list1.append("no")

for i in list1:
    print(i)
### BUGGY CODE ###

N = int(input())
AB = []
for i in range(N):
  AB_1,AB_2 = map(int,input().split())
  AB.append([AB_1,AB_2])
AB.sort(key=lambda AB: AB[0],reverse=True)
AB.sort(key=lambda AB: AB[1])
time = 0
count = 0
while count < N:
  for i in range(N):
    time += AB[i][0]
    if time > AB[i][1]:
      ans = "No"
      break

### FIXED CODE ###

N = int(input())
AB = []
for i in range(N):
  AB_1,AB_2 = map(int,input().split())
  AB.append([AB_1,AB_2])
AB.sort(key=lambda AB: AB[1])
time = 0
count = 0
ans = "Yes"

for i in range(N):
  time += AB[i][0]
  if time > AB[i][1]:
    ans = "No"
print(ans)
### BUGGY CODE ###

b,k = map(int,input().split())
a = list(map(int,input().split()))

i = 0
his = []
n = 0
his.append(0)
while(1):
    #print(his)
    i = a[i] - 1
    if i not in his:
        his.append(i)
    else:
        n = len(his)-his.index(i)
        break
m = len(his) - n
p = 0
if k > m:
    p = (k-m)%n + m
else:
    p = k
i = 0
#print(n,m,p)
for j in range(p):
    #print(a[i])
    i = a[i] - 1
print(i+1)



### FIXED CODE ###

b,k = map(int,input().split())
a = list(map(int,input().split()))

i = 0
check = [True]*b
his = []
n = 0
his.append(0)
while(1):
    #print(his)
    i = a[i] - 1
    if check[i]:
        check[i] = False
        his.append(i)
    else:
        n = len(his)-his.index(i)
        break
m = len(his) - n
p = 0
if k > m:
    p = (k-m)%n + m
else:
    p = k
i = 0
#print(n,m,p)
for j in range(p):
    #print(a[i])
    i = a[i] - 1
print(i+1)
### BUGGY CODE ###

n = int(input())
li = [int(input()) for i in range(n)]
if 2 not in li:
  print(-1)
else:
  ans = 0
  st = 0
  while st != 1:
    if st == 0 and ans > 0:
      ans = -1
      break
    st = li[st]-1
    ans += 1
  print(ans)

### FIXED CODE ###

n = int(input())
li = [int(input()) for i in range(n)]
if 2 not in li:
  print(-1)
else:
  ans = 0
  st = 0
  while st != 1:
    if (st == 0 and ans > 0) or ans > n:
      ans = -1
      break
    st = li[st]-1
    ans += 1
  print(ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(300000)


to = [[] for _ in range(200005)]
ans: list


def dfs(v, p=-1):
    global ans
    for u in to[v]:
        if u == p: continue
        ans[u] += ans[v]
        dfs(u, v)
    return


def main():
    N, Q = map(int, input().split())
    for _ in range(N-1):
        a, b = map(int, input().split())
        to[a-1].append(b-1)
        to[b-1].append(a-1)
    global ans
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    dfs(0)
    print(*ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


sys.setrecursionlimit(300000)

to = [[] for _ in range(200005)]
ans: list


def dfs(v, p=-1):
    global ans
    for u in to[v]:
        if u == p: continue
        ans[u] += ans[v]
        dfs(u, v)
    return


def main():
    N, Q = map(int, input().split())
    for _ in range(N-1):
        a, b = map(int, input().split())
        to[a-1].append(b-1)
        to[b-1].append(a-1)
    global ans
    ans = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        ans[p-1] += x
    dfs(0)
    print(*ans)


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

m = int(input())
c = 0

for i in range(m):
    c = c + i

print(c)

### FIXED CODE ###

m = int(input())

print(m*(m-1)//2)
### BUGGY CODE ###

import bisect

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

STX = [list(map(int, input().split())) for _ in range(N)]
# xの昇順に工事の区間をsort
STX = sorted(STX, key=lambda x: x[2])

D = [int(input()) for _ in range(Q)]
ans = [-1 for _ in range(Q)]
for stx in STX:
    s, t, x = stx
    left = bisect.bisect_left(D, s - x - 0.5)
    right = bisect.bisect_left(D, t - x - 0.5)
    
    for i in range(left, right):
        if ans[i] == -1:
            ans[i] = x

for a in ans:
    print(a)

### FIXED CODE ###

import sys
import bisect

input = sys.stdin.readline

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

STX = [list(map(int, input().split())) for _ in range(N)]
# xの昇順に工事の区間をsort
STX = sorted(STX, key=lambda x: x[2])

D = [int(input()) for _ in range(Q)]
ans = [-1] * Q
index = [-1] * Q
for s, t, x in STX:
    left = bisect.bisect_left(D, s - x - 0.5)
    right = bisect.bisect_left(D, t - x - 0.5)
    now = left
    while now < right:
        if index[now] == -1:  # まだansが更新されていない場合
            ans[now] = x
            index[now] = right
            now += 1
        else:
            now = index[now]
            

for a in ans:
    print(a)
### BUGGY CODE ###

import itertools
from collections import defaultdict as dict
d = dict(int)

N = int(input())
S = [int(_) for _ in input()]
s = list(itertools.combinations(S, 3))

for j in range(len(s)):

    # カウントアップ
    d[s[j]] += 1

print(len(d))

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
# 000 - 999 まで全探索
for i in range(1000):
    t = str(i).zfill(3)

    # 1桁目が存在するか
    if t[0] in S:
        t1 = S.index(t[0])
        # 2桁目を1桁目のidx + 1から探す
        if t[1] in S[t1 + 1:]:
            # 1桁目のidx + 2桁目のidx + 1 桁目から3文字目を探す
            t2 = t1 + S[t1 + 1:].index(t[1]) + 1
            if t[2] in S[t2 + 1:]:
                ans += 1

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

N = int(input())
li = []

for i in range(N):
    A = int(input())
    li.append(A)

li2 = sorted(li,reverse=True)

for i in range(N):
    ans = max(li)
    if(ans == li[i]):
        print(li2[1])
    else:
        print(ans)
    
        

### FIXED CODE ###

N = int(input())
li = []

for i in range(N):
    A = int(input())
    li.append(A)

li2 = sorted(li,reverse=True)
ans = max(li)

for i in range(N):
    if(ans == li[i]):
        print(li2[1])
    else:
        print(ans)