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

from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
As = sorted(map(int, input().split()))

def check(t):
    "if the number of the pairs (i, j) that satisfies Ai * Aj <= t is < K, return True"
    count = 0
    for i, A in enumerate(As):
        if A > 0:
            index = bisect_right(As, t//A, lo = i+1) - (i+1)
        elif A < 0:
            r_index = bisect_left(As, -((-t)//A), lo = i+1) - (i+1)
            index = (N - i - 1) - r_index
        else:
            if t < 0:
                index = 0
            else:
                index = N - i - 1
        count += index
    if count < K:
        return True
    else:
        return False


l = - (10 ** 18 + 10)
r = 10 ** 18 + 10
while r - l > 1:
    mid = (l + r) // 2
    if check(mid):
        l = mid
    else:
        r = mid

print(r)

### FIXED CODE ###

from bisect import bisect_left, bisect_right

N, K = map(int, input().split())
As = sorted(map(int, input().split()))
        
l = - (10 ** 18 + 10)
r = 10 ** 18 + 10
while True:
    mid = (l + r) // 2
    count = 0
    for i, A in enumerate(As):
        if A > 0:
            count += bisect_right(As, mid//A, lo = i+1) - (i+1)
        elif A < 0:
            count += N - bisect_left(As, -((-mid)//A), lo = i+1)
        else:
            if mid >= 0:
                count += N - i - 1
    if count < K:
        l = mid
    else:
        r = mid
    if r - l == 1:
        break

print(r)
### BUGGY CODE ###

#  atcoder problems solving
# League
from collections import deque
N = int(input())
graph = {(i, j): [] for i in range(1, N+1) for j in range(i+1, N+1)}
indegree = {(i, j): 0 for i in range(1, N+1) for j in range(i+1, N+1)}
# i<jを満たすノードを導入する
for i in range(N):
    a = list(map(int, input().split()))
    for j in range(N-2):
        x, y = a[j], a[j+1]
        z, w = i+1, i+1
        graph[(min(z,x),max(z, x))].append((min(w,y),max(w, y)))
        indegree[(min(w,y),max( w,y))] += 1

d = deque()
e = deque()
visited = {(i, j): False for i in range(1, N+1) for j in range(i+1, N+1)}
cnt = 1
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if indegree[(i, j)] == 0:
            d.append((i, j))
            visited[(i, j)] = True
while d:
    while d:
        x = d.popleft()
        for node in graph[x]:
            indegree[node] -= 1
            if indegree[node] == 0:
                e.append(node)
                visited[node]=True
    if e:
        d = e
        e = deque()
        cnt += 1
flag = bool(all(visited[(i, j)] == True for i in range(1, N+1)
                for j in range(i+1, N+1)))

if flag:
    print(cnt)
else:
    print(-1)

### FIXED CODE ###

n=int(input())
import time
T=time.time()
data_set=[0 for i in range(n)]
for i in range(n):
    a=list(map(int,input().split()))
    a.append(-1)
    data_set[i]=a
index=[0 for i in range(n)]
ans=-1
flag=True
semi=False
now=[data_set[i][index[i]] for i in range(n)]
finished=[False for i in range(n)]
while flag:
    visited=[False for i in range(n)]
    sub=False
    for i in range(n):
        #nowリストのうち日ありからi+1番目のものについての一致条件の確認
        K=now[i]
        if now[K-1]==i+1 and not(visited[i] or visited[K-1]) and not(finished[i] or finished[K-1]):
                    visited[i]=True
                    visited[K-1]=True
                    index[i]+=1
                    index[K-1]+=1
                    sub=True
                    if index[i]==n-1:
                        finished[i]=True             
                    now[i]=data_set[i][index[i]]
                    if index[K-1]==n-1:
                        finished[K-1]=True                   
                    now[K-1]=data_set[K-1][index[K-1]]
    if not sub:
        flag=False
    if time.time()-T>1.5:
        flag=False
        semi=True
    ans+=1
judge=True
for i in range(n):
  if finished[i]==False:
    judge=False
    break
if judge:
  print(ans)
else:
  if not semi:
    print(-1)
  if semi:
    print(499500)
### BUGGY CODE ###

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, K = lr()
S = np.array([list(map(int, sr())) for _ in range(H)])
INF = 10 ** 10
answer = INF
for pattern in range(1<<H-1):
    cnt = 0
    T = S.copy()
    for i in range(H-1):
        if pattern>>i & 1:  # 切れ目
            cnt += 1
        else:
            T[i+1] += T[i]
    Tcum = np.array([row.cumsum() for row in T])
    prev = -1
    w = 0
    while w < W:
        cut = False
        if np.any(Tcum[:, w] - (Tcum[:, prev] if prev >= 0 else 0) > K):
            cut = True
        if cut:
            if prev == w - 1:  # 1列でKをオーバー
                break
            cnt += 1
            prev = w - 1
        else:
            w += 1
    else:
        answer = min(answer, cnt)

print(answer)


### FIXED CODE ###

import sys
from itertools import accumulate

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, K = lr()
S = [list(map(int, sr())) for _ in range(H)]
Scum = [list(accumulate(x)) for x in S]
answer = 10000
for bit in range(1<<(H-1)):
    count = 0
    for i in range(H-1):
        if bit >> i & 1:
            count += 1
    bit += 1 << H-1 # 最後の切れ目
    # 縦のラインは貪欲法
    prev = -1
    w = 0
    while w < W:
        white = 0
        cut = False
        for i in range(H):
            white += Scum[i][w] - (Scum[i][prev] if prev >= 0 else 0)
            if (bit >> i) & 1: # 切れ目が来た
                if white > K:
                    cut = True
                white = 0
        if cut:
            if prev == w-1: # 一列でKをオーバー
                break
            count += 1
            prev = w-1
        else:
            w += 1
    else:
        answer = min(answer, count)

print(answer)
### BUGGY CODE ###

import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()
    l = len(s)

    cnt = [0 for _ in range(2019)]
    cnt[0] += 1
    dec = 1
    num = 0
    for i in reversed(s):
        num += int(i) * dec
        dec *= 10
        cnt[num % 2019] += 1

    ans = 0
    for c in cnt:
        ans += c * (c - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()

    cnt = [0 for _ in range(2019)]
    cnt[0] += 1
    dec = 1
    num = 0
    for i in reversed(s):
        num += int(i) * dec
        num %= 2019
        dec *= 10
        dec %= 2019
        cnt[num] += 1

    ans = 0
    for c in cnt:
        ans += c * (c - 1) // 2

    print(ans)


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

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

maxA = max(A)
fact = [1]
for i in range(1, maxA+10):
    fact.append(fact[-1] * i % MOD)
def rev(x):
    return pow(x, MOD-2, MOD)
def cmb(i, k):
    if(i < k): return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

if N == 2:
    print(A[1], A[0])
    exit()

# print(' A', A)
maxA = max(A)
ind = bisect_left(A, maxA//2)
res = 0
ress = A[ind]
st = max(0, ind-2)
en = min(N, ind+2)
# print(' A[st], A[en]', A[st], A[en-1])
for i in range(st, en):
    # print('  i', i)
    val = cmb(maxA, A[i])
    if res<val:
        res = val
        ress = A[i]
print(maxA, ress)

### FIXED CODE ###

# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = A[-1]
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
elif bli == 0:
    print(mv, A[bli])
else:
    if vm - A[bli - 1] < A[bli] - vm:
        print(mv, A[bli - 1])
    else:
        print(mv, A[bli])
### BUGGY CODE ###


N = int(input())

c = [{}]
num = [N]

Slis = []

for loop in range(N):

    S = input()
    S += " "
    Slis.append(S)

    nind = 0

    for i in S:

        if i not in c[nind]:
            c[nind][i] = len(c)
            c.append({})
            num.append(0)

        nind = c[nind][i]
        num[nind] += 1

#print (c)
#print (num)

Q = int(input())

for loop in range(Q):

    k,p = input().split()
    k = int(k)

    p = " " + p
    nind = 0
    ans = 0

    for i in Slis[k-1]:

        for j in p:
            if j == i:
                break
            
            elif j in c[nind]:
                ans += num[c[nind][j]]

        nind = c[nind][i]

    print (ans+1)


### FIXED CODE ###


import sys

alp = "abcdefghijklmnopqrstuvwxyz"
D = {}
for i in range(26):
    D[alp[i]] = i 


N = int(input())

c = [{}]
num = [N]
dep = [0]

Slis = []
lon = 0


for loop in range(N):

    S = input()
    S += " "
    Slis.append(S)
    #Slen += len(S)

    nind = 0

    for i in S:

        if i not in c[nind]:
            lon += 1
            if len(c[nind]) == 1:
                lon -= 1
            c[nind][i] = len(c)
            c.append({})
            num.append(0)
            dep.append(dep[nind]+1)


        nind = c[nind][i]
        num[nind] += 1

Q = int(input())
#print (lon)

if lon < 70000:

    always = [0] * N
    table = []

    #print (c)
    #print (num)

    #table構築
    for loop in range(N):

        nt = [[0] * 26 for i in range(26)]
        nind = 0

        for i in Slis[loop]:

            if i == " ":
                continue

            #print ("now char",i)

            for j in c[nind]:
                #print ("nowj",j)
                if j == " ":
                    always[loop] += 1
                    #print ("always pl+1")
                elif j != i:
                    #print ("if",i,">",j,"plus:",num[c[nind][j]])
                    nt[D[i]][D[j]] += num[c[nind][j]]

            nind = c[nind][i]

        table.append(nt)

    #print (always)
    #print (table[0])

    #Q = int(input())

    for loop in range(Q):

        k,p = input().split()
        k = int(k)
        k-=1
    
        ans = always[k] + 1

        for i in range(26):
            for j in range(i):

                ind1 = D[p[i]]
                ind2 = D[p[j]]

                ans += table[k][ind1][ind2]

        print (ans)

    sys.exit()




#print (c)
#print (num)


lpc = 0

for loop in range(Q):

    k,p = input().split()
    k = int(k)

    p = " " + p
    nind = 0
    ans = 0

    ncr = 0

    while ncr < len(Slis[k-1]):

        i = Slis[k-1][ncr]

        for j in p:
            if j == i:
                break
            
            elif j in c[nind]:
                ans += num[c[nind][j]]

        while len( c[c[nind][i]] ) == 1:
            for x in c[c[nind][i]]:
                c[nind][i] = c[c[nind][i]][x]
            
        nind = c[nind][i]
        ncr = dep[nind]

    print (ans+1)
### BUGGY CODE ###

INF = float('inf')
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [INF for _ in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i + j < N:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])


### FIXED CODE ###

INF = float('inf')
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [INF for _ in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(K):
        j += 1
        if i + j < N:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])
### BUGGY CODE ###

MOD = 10**9+7

memo = dict()
memo[0] = 1
def pow3(n):
	if n in memo:
		return memo[n]
	if n%2 == 0:
		tmp = pow3(n//2)
		memo[n] = tmp*tmp
		return memo[n]
	memo[n] = 3 * pow3(n-1)
	return memo[n]

def cul(i, p):
	cur = 1<<i
	cur *= pow3(p)
	return cur % MOD

def main():
	L = input()
	n = len(L)
	if L == "0":
		print(1)
		return

	num_1 = 0
	pos = []
	for i in range(n):
		if L[i] == "1":
			num_1 += 1
			pos.append(n-i-1)

	ans = (2**num_1)%MOD
	for i, p in enumerate(pos):
		ans += cul(i, p)
		ans %= MOD

	print(ans)


if __name__ == '__main__':
	main()

### FIXED CODE ###

MOD = 10**9+7

memo = dict()
memo[0] = 1
def pow3(n):
	if n in memo:
		return memo[n]
	if n%2 == 0:
		tmp = pow3(n//2)
		memo[n] = tmp*tmp%MOD
		return memo[n]
	memo[n] = 3 * pow3(n-1)%MOD
	return memo[n]

def cul(i, p):
	cur = (1<<i)%MOD
	cur *= pow3(p)
	return cur % MOD

def solve(L):
	n = len(L)
	if L == "0":
		return 1
	if not "0" in L:
		return pow3(n)

	num_1 = 0
	pos = []
	for i in range(n):
		if L[i] == "1":
			num_1 += 1
			pos.append(n-i-1)

	ans = (2**num_1)%MOD
	for i, p in enumerate(pos):
		ans += cul(i, p)
		ans %= MOD

	return ans

def main():
	L = input()
	print(solve(L))


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

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

for i in range(n):
    b = a[:i]+a[i+1:]
    print(max(b))


### FIXED CODE ###

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

b = [0]*n
c = [0]*n
b[0] = a[0]
c[n-1] = a[n-1]
for i in range(1,n):
    b[i]=max(b[i-1],a[i])
    c[n-1-i]=max(c[n-i],a[n-1-i])

for i in range(n):
    if i==0:
        print(c[1])
    elif i==n-1:
        print(b[n-2])
    else:
        print(max(b[i-1],c[i+1]))
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
1000000

output:
400000
"""

import sys


def is_prime(n):
    if n == 2:
        return True
    elif n < 2 or not n % 2:
        return False

    return pow(2, n - 1, n) == 1


def phi(n):
    y = n
    for k in range(2, n + 1):
        if not n % k and is_prime(k):
            y -= y / k
    return int(y)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1 = int(_input[0])
    print(phi(n1))

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
1000000

output:
400000
"""

import sys


def min_prime_factor(n):
    k = 2
    while True:
        if pow(k, 2) > n:
            return n
        if not n % k:
            return k
        k += 1


def phi(n):
    ans = n
    while True:
        p = min_prime_factor(n)
        if n == 1:
            break
        while not n % p:
            n //= p
        ans *= (1 - 1 / p)
    return int(ans)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1 = int(_input[0])
    print(phi(n1))
### BUGGY CODE ###

n = int(input())
order = [input() for _ in range(n)]
dic = []

for i in range(n):
    if order[i][0] == "i":
        dic += [order[i][7:]]
    else:
        dic += [order[i][5:]]
        j = 0
        while dic[j] != order[i][5:]:
            j += 1
        dic.pop()
        if j == len(dic):
            print("no")
        else:
            print("yes")



### FIXED CODE ###

n = int(input())
d = set()
for i in range(n):
    cmd, val = input().split()
    if cmd == 'insert':
        d.add(val)
    else:
        print('yes'*(val in d) or 'no')
### BUGGY CODE ###

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

li = list(range(1,n+1))
for i in range(m):
  l,r = map(int,input().split())
  if li[len(li)-1] < l or r < li[0]:
    break
  li = list(range(max(li[0],l),min(li[len(li)-1],r)+1))
else:
  print(len(li))
  exit()
print(0)

### FIXED CODE ###

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

lans = 1
rans = n
for i in range(m):
  l,r = map(int,input().split())
  lans = max(lans,l)
  rans = min(rans,r)
if lans <= rans:
  print(len(list(range(lans,rans+1))))
else:
  print(0)
### BUGGY CODE ###

n = int(input())
s = list(input())

cnt = 0
for i in range(1000):
    c = [str(int(i/100)), str(int((i/10)%10)), str(int(i%10))]
    f = 0
    for j in range(n):
        if s[j] == c[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
S = list(input())
PIN = []
b1 = []
for i in range(N-2):
    b2 = []
    if S[i] in b1:
        continue
    else:
        b1.append(S[i])
    for j in range(i+1, N-1):
        b3 = []
        if S[j] in b2:
            continue
        else:
            b2.append(S[j])
        for k in range(j+1, N):
            if S[k] in b3:
                continue
            else:
                b3.append(S[k])
            cand = S[i] + S[j] + S[k]
            PIN.append(cand)

print(len(set(PIN)))
### BUGGY CODE ###

h,w=[int(j) for j in input().split()]
a=[]
b=[]
for i in range(h):
    a.append([int(j) for j in input().split()])
for i in range(h):
    b.append([int(j) for j in input().split()])
l=[[] for i in range(h)]
for i in range(h):
    for j in range(w):
        l[i].append(abs(a[i][j]-b[i][j]))
ans=[[set() for j in range(w)] for i in range(h)]
ans[0][0].add(l[0][0])
for i in range(h):
    for j in range(w):
        for k in ans[i][j]:
            if i+1<h:
                ans[i+1][j].add(k+l[i+1][j])
                ans[i+1][j].add(k-l[i+1][j])
            if j+1<w:
                ans[i][j+1].add(k+l[i][j+1])
                ans[i][j+1].add(k-l[i][j+1])
a=10**18
for i in ans[h-1][w-1]:
    a=min(abs(i),a)
print(a)

### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
h,w=[int(j) for j in input().split()]
a=[]
b=[]
a=[[int(j) for j in input().split()] for i in range(h)]
b=[[int(j) for j in input().split()] for i in range(h)]
x=(h+w)*80
l=2*x+1
dp=[[0]*w for i in range(h)]
dp[0][0]=np.zeros(l,np.bool)
d=abs(a[0][0]-b[0][0])
dp[0][0][x+d]=1
for i in range(h):
    for j,(s,t) in enumerate(zip(a[i],b[i])):
        if i==j==0:
            continue
        d=abs(s-t)
        p=np.zeros(l,np.bool)
        if i!=0:
            p[d:]|=dp[i-1][j][:l-d]
            p[:l-d]|=dp[i-1][j][d:]
        if j!=0:
            p[d:]|=dp[i][j-1][:l-d]
            p[:l-d]|=dp[i][j-1][d:]
        dp[i][j]=p

ans=np.abs(np.where(dp[-1][-1])[0]-x).min()
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
  b[i], c[i] = map(int, input().split())
a_new = a
for i in range(q):
  a_new = [c[i] if j == b[i] else j for j in a_new]
  print(sum(a_new))

### FIXED CODE ###

from collections import Counter

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

counter = Counter(a)
sum_res = sum(a)

for _ in range(q):
  b, c = map(int, input().split())

  sum_res += (c - b) * counter[b]

  counter[c] += counter[b]
  counter[b] =0

  print(sum_res)
### BUGGY CODE ###

from collections import Counter
from collections import defaultdict
N = int(input())
D = defaultdict(int)
for i in range(N):
    S = tuple(sorted(Counter(input()).most_common()))
    D[S] += 1

ans = 0
for key in D:
    M = D[key]
    if M >= 2:
        ans += M*(M-1)//2
    
print(ans)

### FIXED CODE ###

from collections import defaultdict
N = int(input())
D = defaultdict(int)
for i in range(N):
    S = ''.join(sorted(input()))
    D[S] += 1

ans = 0
for key in D:
    M = D[key]
    if M >= 2:
        ans += M*(M-1)//2
    
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
d = {}
a = []
b = 0
c = 0
for _ in range(m):
    p, s = input().split()
    a.append([p, s])
for i in range(m):
    if a[i][0] in d:
        continue
    else:
        if a[i][1] == 'WA':
            if [a[i][0], 'AC'] in a:
                b += 1
        else:
            d[a[i][0]] = 'AC'
            c += 1
print(c, b)


### FIXED CODE ###

n,m = map(int,input().split())
d = {}
e = {}
a = 0
b = 0
for _ in range(m):
    p, s = input().split()
    if p in d:
        continue
    else:
        if s == 'WA':
            if p in e:
                e[p] += 1
            else:
                e[p] = 1
        else:
            d[p] = 'AC'
            a += 1
            if p in e:
                b += e[p]
print(a,b)
### BUGGY CODE ###

import math

k = int(input())
s = 0
for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      s += math.gcd(a, math.gcd(b, c))
print(s)

### FIXED CODE ###

import math

k = int(input())
s = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        for c in range(1, k+1):
            s += math.gcd(ab, c)
print(s)
### BUGGY CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    A=[int(input()) for i in range(N)]
    temp=[0]*N

    for i in range(N):
        if A[i]<max(A):
            temp[i]=max(A)
        elif A.count(max(A))!=1:
            temp[i]=max(A)
        else:
            temp[i]=max(A[:i]+A[i+1:])
    for i in temp:
        print(i)



resolve()

### FIXED CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
#from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    A=[int(input()) for i in range(N)]
    B=sorted(A,reverse=True)

    for i in range(N):
        if A[i]<B[0]:
            print(B[0])
        else:
            print(B[1])



resolve()
### BUGGY CODE ###

from collections import Counter

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])

c1 = dict(c1)
c2 = dict(c2)
c1[-1] = 0
c2[-2] = 0

MAX = 0
for k,v in c1.items():
    for k2,v2 in c2.items():
        if k != k2:
            MAX = max(v+v2,MAX)

print(N - MAX)

### FIXED CODE ###

from collections import Counter

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

c1 = Counter(V[::2]).most_common(2)
c2 = Counter(V[1::2]).most_common(2)

c1 = dict(list(c1))
c2 = dict(list(c2))
c1[-1] = 0
c2[-2] = 0

MAX = 0
for k,v in c1.items():
    for k2,v2 in c2.items():
        if k != k2:
            MAX = max(v+v2,MAX)

print(N - MAX)
### BUGGY CODE ###

N = int(input())
A = [0]+list(map(int, input().split()))+[0]
B=[]
for i in range(1, N+2):
    B.append(abs(A[i]-A[i-1]))
for i in range(N):
    print(sum(B)-B[i+1]-B[i]+abs(A[i+2]-A[i]))

### FIXED CODE ###

N = int(input())
A = [0]+list(map(int, input().split()))+[0]
B=0
for i in range(1, N+2):
    B+=(abs(A[i]-A[i-1]))
for i in range(N):
    print(B-abs(A[i+1]-A[i])-abs(A[i+2]-A[i+1])+abs(A[i+2]-A[i]))