Problem:
 Score : 300 points    Problem Statement You are given a sequence of length N : A_1, A_2, ..., A_N .
For each integer i between 1 and N (inclusive), answer the following question:   Find the maximum value among the N-1 elements other than A_i in the sequence.       Constraints  2 \leq N \leq 200000  1 \leq A_i \leq 200000  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  :  A_N       Output Print N lines. The i -th line ( 1 \leq i \leq N ) should contain the maximum value among the N-1 elements other than A_i in the sequence.        Sample Input 1 3
1
4
3      Sample Output 1 4
3
4   The maximum value among the two elements other than A_1 , that is, A_2 = 4 and A_3 = 3 , is 4 .  The maximum value among the two elements other than A_2 , that is, A_1 = 1 and A_3 = 3 , is 3 .  The maximum value among the two elements other than A_3 , that is, A_1 = 1 and A_2 = 4 , is 4 .        Sample Input 2 2
5
5      Sample Output 2 5
5

Solution (Python):

import sys






"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

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


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    a = ip.ILS(n)

    m = max(a)
    m2 = sorted(a)[-2]
    

    if m == m2:
        for _ in r(n):
            print(m)
    else:
        for i in r(n):
            if a[i] == m:
                print(m2)
            else:
                print(m)


main()

Solution (Python):
import copy
N = int(input())
A = list(int(input()) for _ in range(N))

B  = copy.deepcopy(A)
B.sort()
M1 = B[-1]
M2 = B[-2]

for i in range(N):
    if A[i] == M1:
        print(M2)
    else:
        print(M1)

Solution (Python):
n = int(input())
l = []
mx = 0
mn = 0
for i in range(n):
    a = int(input())
    l.append(a)
    if a > mx:
        mx = a
        mn = i+1
l.sort()
if l.count(mx) > 1:
    for i in range(n):
        print(mx)
else:
    for i in range(mn-1):
        print(mx)
    print(l[n-2])
    for i in range(n-mn):
        print(mx)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]

B = sorted(A, reverse=True)


MAX1 = B[0]
MAX2 = B[1]


if MAX1 == MAX2:
    for a in range(N):
        print(MAX1)
else:
    for a in A:
        if a != MAX1:
            print(MAX1)
        else:
            print(MAX2)

Solution (Python):
n = int(input())
a_list = []
first = 0
second = 0
for i in range(n):
    a = int(input())
    if a >= first:
        second = first
        first = a
    elif a >= second:
        second = a
    a_list.append(a)

for i in a_list:
    if i == first:
        print(second)
    else:
        print(first)

Solution (Python):
import sys
n = int(input())
A=[]
for _ in range(n):
    A.append(int(input()))

left = [0 for i in range(n+1)]
right = [0 for i in range(n+1)]

for i in range(n+1):
    if i == 0:
        left[i] = -10000000000
        continue
    if A[i-1] > left[i-1]:
        left[i] = A[i-1]
    else:
        left[i] = left[i-1]

for i in reversed(range(n+1)):
    if i == n:
        right[i] = -10000000000
        continue
    if A[i] > right[i+1]:
        right[i] = A[i]
    else:
        right[i] = right[i+1]

for i in range(n):
    print(max(left[i], right[i+1]))

Solution (Python):
n = int(input())
first = 0
second = 0
x1 = 0
for i in range(n):
  a = int(input())
  if a > second:
    if a > first:
      second = first
      first = a
      x1 = i
    else:
      second = a
for i in range(x1):
  print(first)
print(second)
for i in range(x1+1,n):
  print(first)

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
l,r=0,0
lm=[0]
rm=[0]
for i in range(n):
    l=max(l,a[i])
    r=max(r,a[-1-i])
    lm.append(l)
    rm.append(r)
for i in range(n):
    print(max(lm[i],rm[n-i-1]))

Solution (Python):
from collections import *
n=int(input())
l=[int(input()) for i in range(n)]
dic=Counter(l)
s=set(l)
a=max(s)
if(len(s)>1):
    s.remove(a)
    b=max(s)
for i in range(n):
    if(l[i]==a and dic[a]>1):
        print(a)
    elif(l[i]!=a):
        print(a)
    else:
        print(b)

Solution (Python):
N = int(input())
A = []
for i in range(N):
    temp = int(input())
    A.append((temp, i))
A.sort(key = lambda x: -x[0])

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

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=[0]*2
index=[-1]*2
for i in range(n):
    if m[0]<a[i]:
        m[1]=m[0]
        index[1]=index[0]
        m[0]=a[i]
        index[0]=i
    elif m[1]<=a[i]:
        m[1]=a[i]
        index[1]=i
for i in range(n):
    if i==index[0]:
        print(m[1])
    else:
        print(m[0])

Solution (Python):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

m = list(sorted(A))
if m[-1] == m[-2]:
    for _ in range(N):
        print(m[-1])
else:
    for _ in A:
        if _ == m[-1]:
            print(m[-2])
        else:
            print(m[-1])

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())

first, second = sorted(A,reverse=True)[:2]
for i in range(N):
    if A[i] == first:
        print(second)
    else:
        print(first)

Solution (Python):
N = int(input())

max1 = 0
max2 = 0

arr = []

for i in range(N):
    a = int(input())
    arr.append(a)
    if a >= max1:
        max2 = max1
        max1 = a
    elif a > max2:
        max2 = a

for i in range(N):
    if arr[i] == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
from sys import stdin
from sys import stdout
n = int(input())
a = [int(stdin.readline()) for _ in range(n)]
s = max(a)
cnt = a.count(s)
if cnt > 1:
    for x in a:
        stdout.write("{}\n".format(s))
    quit()
t = -1
for x in a:
    if x != s:
        t = max(t, x)
for x in a:
    stdout.write("{}\n".format(s if x != s else t))

Solution (Python):
def getlist():
	return list(map(int, input().split()))

L = []
n = []

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

L = sorted(L)
if L[-1] == L[-2]:
	for i in range(N):
		print(L[-1])
else:
	for i in range(N):
		if n[i] == L[-1]:
			print(L[-2])
		else:
			print(L[-1])

Solution (Python):
N = input()
N = int(N)
S = [int(input()) for _ in range(N)]
S2 = sorted(S, reverse=True)
onon = S2[0]

for i in range(N):
    if S[i] != onon:
        print(onon)
    else:
        print(S2[1])

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]


max_a = max(a)

max_a_count = 0
for i in range(n):
    if a[i] == max_a:
        max_a_count += 1

if max_a_count > 1:
    for i in range(n):
        print(max_a)
elif max_a_count == 1:
    b = sorted(range(len(a)), key=a.__getitem__)
    for i in range(n):
        if a[i] != max_a:
            print(max_a)
        else:
            print(a[b[-2]])

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]

from collections import Counter

a_c = Counter(a)

first = max(a_c)
a_c[first] -= 1
second = max(+a_c)

for ai in a:
    if ai != first:
        print(first)
    else:
        print(second)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)

    B = sorted(A, key=lambda x: -x)
    for a in A:
        if a == B[0]:
            print(B[1])
        else:
            print(B[0])


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = []
m = 0
count = 0
for _ in range(N):
    a = int(input())
    A.append(a)
    if a > m:
        m = a
        count = 1
    elif a == m:
        count += 1
B = A[:]
B.sort(reverse=True)

for a in A:
    if a == m:
        if count > 1:
            print(a)
        else:
            print(B[1])
    else:
        print(m)

Solution (Python):
N = int(input())
A = []
first = 0
second = 0
for i in range(N):
    Ai = int(input())
    A.append(Ai)
    if Ai > first:
        second = first
        first = Ai
    elif Ai > second:
        second = Ai

for i in range(N):
    if A[i] == first:
        print(second)
    else:
        print(first)

Solution (Python):


n = int(input())
max_a, max_ai = 0, 0
arr = []
for i in range(n):
    a = int(input())
    arr.append(a)
    if a > max_a:
        max_a = a
        max_ai = i + 1
arr = sorted(arr)

for i in range(n):
    if max_ai == i + 1:
        print(arr[-2])
    else:
        print(max_a)

Solution (Python):
N = int(input())

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

sort_A = sorted(A)
max_A = sort_A[-1]
next_max_A = sort_A[-2]

for a in A:
    if a == max_A:
        print(next_max_A)
    else:
        print(max_A)

Solution (Python):



import sys  
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools



sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe


def local_input():
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)


def solve():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    
    b = sorted(a, reverse = True)
    
    for i in range(n):
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])


    return 0

if __name__ == "__main__":
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

Solution (Python):
N = int(input())
max_1 = 0
max_2 = 0
max_1_index = -1
for i in range(N):
	new_num = int(input())
	if max_1 <= new_num:
		max_2 = max_1
		max_1 = new_num
		max_1_index = i
	elif max_2 <= new_num:
		max_2 = new_num
	
for i in range(N):
	if max_1_index == i:
		print(max_2)
	else:
		print(max_1)

Solution (Python):
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = ii2nn(N)
    Ai = [(i, a) for i, a in enumerate(A)]
    Ai.sort(key=lambda v: v[1])
    i1 = Ai[-1][0]
    M = max(A)
    M2 = Ai[-2][1]
    for i, a in enumerate(A):
        if i == i1:
            print(M2)
        else:
            print(M)

main()

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
xs = []
fst = 0
snd = 0
for i in range(n):
    x = int(input())
    xs.append(x)
    if x > fst:
        t = fst
        fst = x
        x = t
    if x > snd:
        snd = x

for a in xs:
    if a == fst:
        print(snd)
    else:
        print(fst)

Solution (Python):
n = int(input())

a = []

for i in range(n):
    a.append(int(input()))
    
sorted_a = sorted(a, reverse=True)    

for i in range(n):
    if a[i] == sorted_a[0]:
        print(sorted_a[1])
    else:
        print(sorted_a[0])

Solution (Python):
N=int(input())
A=[]

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

sorted_a = sorted(A)
max_a = sorted_a[-1]
max_i = A.index(max_a)

second_a = sorted_a[-2]
second_i = A.index(second_a)

for i in range(N):
    if i == max_i:
        print(second_a)
    else:
        print(max_a)

Solution (Python):
N = int(input())
li = [int(input()) for i in range(N)]
lis = sorted(li)
k = lis[-1]
for i in range(N):
    if li[i] == k:
        print(lis[-2])
    else:
        print(k)

Solution (Python):
n = int(input())

maxNum = 0
maxcount = 0
tugi = 0
ls = [0]*n
for i in range(n):
    o = int(input())
    maxNum = max(maxNum,o)
    ls[i] = o
for i in range(n):
    if ls[i] == maxNum:
        maxcount+=1
    else:
        tugi = max(tugi,ls[i])
if maxcount > 1:
    for i in range(n):
        print(maxNum)
else:
    for i in range(n):
        if ls[i] == maxNum:
            print(tugi)
        else:
            print(maxNum)

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

keep = 0
maxcount = 0
for i in range(N):
    if A[i] >= maxcount:
        maxcount = A[i]
        keep = i
    
for i in range(N):
    if i == keep:
        A[i] = 1
        print(max(A))
    else:
        print(maxcount)

Solution (Python):
N = int(input())
A = [int(input())for _ in range(N)]
all_m = max(A)
maxs = A.count(all_m)
for ind,i in enumerate(A):
    if(all_m==i):
        if(maxs>=2):
            print(all_m)
        else:
            print(max(A[:ind]+A[ind+1:]))
    else:
        print(all_m)

Solution (Python):
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(int(input()))
    b.append(a[i])
b.sort()
m0=b[-1]
m1=b[-2]

for i in range(n):
    if a[i]!=m0:
        print(m0)
    else:
        print(m1)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]

m = max(a[0], a[1])
mm = min(a[0], a[1])
for i in range(2, n):
    if a[i] >= m:
        mm = m
        m = a[i]
    elif a[i] > mm:
        mm = a[i]

for i in range(n):
    if a[i] == m:
        print(mm)
    else:
        print(m)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a = max(a)
    if a.count(max_a) > 1:
        for i in range(n):
            print(max_a)
    else:
        index = a.index(max_a)
        max2_a = sorted(a, reverse=True)[1]
        for i in range(n):
            if index == i:
                print(max2_a)
            else:
                print(max_a)

Solution (Python):
import numpy as np
n = int(input())
A = [int(input()) for i in range(n)]

A_np = np.asarray(A)
max = np.max(A_np)
idx = np.argmax(A_np)
A_temp = A_np
A_temp[idx] = 0

for i in range(n):
    if i == idx:
        print(np.max(A_temp))
    else:
        print(max)

Solution (Python):
n = int(input())
a = sorted([(int(input()), i) for i in range(n)], reverse=True)
for i in range(n):
    print(a[1][0] if a[0][1] == i else a[0][0])

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]

B = sorted(A, reverse=True)
ma = B[0]

for i in range(N):
    if A[i] != ma:
        print(ma)
    else:
        print(B[1])

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
B = sorted(A, reverse=True)
Ap = B[0]
As = B[1]

for a in A:
    if a == Ap:
        print(As)
        continue
    print(Ap)

Solution (Python):
def main():
    n = int(input())
    a = []

    m = 0
    s = 0

    for i in range(n):
        tmp = int(input())
        if tmp>=m:
            s = m
            m = tmp
        elif tmp>=s:
            s = tmp
            
        a.append(tmp)

    for i in a:
        if i == m:
            print(s)
        else:
            print(m)


main()

Solution (Python):
n = int(input())
a_list = [int(input()) for i in range(n)]

a_sort = sorted(a_list,reverse=True)

for i in range(n):
    if a_list[i] == a_sort[0]:
        print(a_sort[1])
    else:
        print(a_sort[0])

Solution (Python):
N = int(input())
A = []
for _ in range(N):
    A += [int(input())]

right = [0] * (N + 1)
left = [0] * (N + 1)
for i in range(1, N + 1):
    right[i] = max(right[i-1], A[i-1])
    left[N - i] = max(left[N + 1 -i], A[N - i])




for i in range(N):
    print (max(right[i], left[i + 1]))

Solution (Python):
n = int(input())
dat = []
dat2 = []
for i in range(n):
    a = int(input())
    dat.append(a)
    dat2.append(a)
dat.sort()
m = dat[n-1]

for i in range(n):
    
    if dat2[i] == m:
        print(dat[n-2])
    else:
        print(m)

Solution (Python):
import copy
N=int(input())
A=list(int(input()) for _ in range(N))
a=copy.deepcopy(A)
a.sort(reverse=True)
x=a[0]
y=a[1]

for i in range(N):
    if A[i]==x:
        print(y)
    else:
        print(x)

Solution (Python):
N = int(input())
As = []
for i in range(N):
    As.append(int(input()))
Ss = sorted(As, reverse=True)
for i in range(N):
    if As[i] == Ss[0]:
        print(Ss[1])
    else:
        print(Ss[0])

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A, reverse=True)
m1 = B[0]
m2 = B[1]
for a in A:
    if a == m1:
        print(m2)
    else:
        print(m1)

Solution (Python):
n=int(input())
A=[]

for i in range(n):
    A.append(int(input()))
    
est=max(A)
B=A[:]
A.remove(est)
er=max(A)
A=B

for i in range(n):
    if A[i] != est:
        print(est)
    else:
        print(er)

Solution (Python):
n = int(input())

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

max_arr = max(arr)
next_max = 0

cnt = 0
for i, a in enumerate(arr):
    if a == max_arr:
        cnt += 1
        idx = i
    else:
        next_max = max(next_max, a)

if cnt >= 2:
    ans = [max_arr] * n
else:
    ans = [max_arr] * idx + [next_max] + [max_arr] * (n - idx - 1)

print(*ans, sep="\n")

Solution (Python):
a=int(input())
b=[int(input()) for i in range(a)]

c=max(b)
d=b.index(c)
b.pop(d)
e=max(b)

for i in range(a):
  if i==d:
    print(e)
  else:
    print(c)

Solution (Python):
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

sorted_A = sorted(A, reverse=True)
A1 = sorted_A[0]
A2 = sorted_A[1]
for A_i in A:
    if A_i == A1:
        print(A2)
    else:
        print(A1)

Solution (Python):
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = [int(input()) for _ in range(n)]

    a_sorted = sorted(a_list)
    a_max = a_sorted[-1]
    a_second = a_sorted[-2]
    for a in a_list:
        if a == a_max:
            print(a_second)
        else:
            print(a_max)

Solution (Python):
import math
def myinput_int():
    return list(map(int, input().split()))

N, = myinput_int()
hairetu=[]
max=-1
max_pos=-1
next=-1
for i in range(N):
    temp, = myinput_int()

    if max<temp :
        max=temp
        max_pos=i
    elif next<temp :
        next=temp

for i in range(N):
    if i==max_pos:
        print(next)
    else:
        print(max)

Solution (Python):
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
b = sorted(a)
b = b[::-1]
for i in range(n):
    if a[i] == b[0]:
        print(b[1])
    else:
        print(b[0])

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = []
for i in range(N):
    A.append(_I())

max_v = max(A)
max_v_count = A.count(max_v)
if max_v_count >= 2:
    
    for a in A:
        print(max_v)
else:
    for a in A:
        if a == max_v:
            second_max_v = [_ for _ in A]
            second_max_v.remove(max_v)
            second_max_v = max(second_max_v)
            print(second_max_v)
        else:
            print(max_v)

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

Amax = max(A)
if A.count(Amax) > 1:
    for i in range(N):
        print(Amax)

else:
    for i in A:
        if i != Amax:
            print(Amax)
        else:
            print(sorted(A)[-2])

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a)

if b[-1]==b[-2]:
    for i in range(n):
        print(b[-1])
else:
    for i in range(n):
        if a[i]==b[-1]:
            print(b[-2])
        else:
            print(b[-1])

Solution (Python):
n = int(input())

a = []
ans = []

for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a)
a_max1 = a_sorted[-1]
a_max2 = a_sorted[-2]
for a_value in a:
    if a_value != a_max1:
        ans.append(str(a_max1))
    else:
        ans.append(str(a_max2))

print("\n".join(ans))

Solution (Python):

import sys
INF = float("inf")


def argmax(a):
    m, n = -(1 << 31), -1
    for i, v in enumerate(a):
        if m < v:
            m, n = v, i
    return m, n


def solve(N: int, A: "List[int]"):
    m, mi = argmax(A)
    m2, mi2 = argmax(A[:mi]+A[mi+1:])
    for i in range(N):
        if i == mi:
            print(m2)
        else:
            print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]

b = sorted(a, reverse=True)
max1 = b[0]
max2 = b[1]

for ai in a:
    if ai != max1:
        print(max1)
    else:
        print(max2)

Solution (Python):
N = int(input())
A = []
for _ in range(N):
  a = int(input())
  A.append(a)

A_max = max(A)
max_index = A.index(A_max)
A.pop(max_index)
A_second = max(A)
for i in range(N):
  if i == max_index:
    print(A_second)
  else:
    print(A_max)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right

import re




def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 



N = i_inpl()
A = line_inpl(N)

max_val = max(A)
s_max = sorted(A)[-2]
max_cnt = A.count(max_val)

for Ai in A:
    if Ai == max_val and max_cnt == 1:
        print(s_max)
    else:
        print(max_val)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
sorted_A = sorted(A)

for i in range(N):
    if A[i] == sorted_A[-1]:
        print(sorted_A[-2])
    else:
        print(sorted_A[-1])

Solution (Python):





N = int(input())
An = [int(input()) for _ in range(N)]
mxAn = [0,0]
for a in An:
  if mxAn[0] < a:
    mxAn = sorted([mxAn[1],a])

for a in An:
  if a == mxAn[1]:
    print(mxAn[0])
  else:
    print(mxAn[1])

Solution (Python):
N = int(input())
As = []
for i in range(N):
  A = int(input())
  As.append(A)
A2s = sorted(As)

for i in range(N):
  A = As[i]
  if A == A2s[N-1]:
    print(A2s[N-2])
  else:
    print(A2s[N-1])

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

max1_a = -1
max1_i = -1
max2_a = -1
max2_i = -1

for i in range(N):
    a = A[i]
    if a >= max1_a:
        max1_a = a
        max1_i = i

for i in range(N):
    if i == max1_i:
        continue
    a = A[i]
    if a >= max2_a:
        max2_a = a
        max2_i = i

for i in range(N):
    if i == max1_i:
        print(max2_a)
    else:
        print(max1_a)

Solution (Python):
n = int(input())

max = 0
next = 0
a = []
for i in range(n):
    temp = int(input())
    a.append(temp)
    if max < temp:
        next = max
        max = temp
    elif next < temp:
        next = temp




for i in a:
    if i == max:
        print(next)
    else:
        print(max)

Solution (Python):
import sys, math

readline = sys.stdin.readline

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

top1 = max(A)
top1_ind = A.index(top1)

A[top1_ind] = -1
top2 = max(A)
A[top1_ind] = top1

for i in range(N):
    if i == top1_ind:
        print(top2)
    else:
        print(top1)

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
As = sorted(A)
A1 = As[-1]
A2 = As[-2]
if A1 != A2:
    for j in range(N):
        if A[j]==A1:
            print(A2)
        else:
            print(A1)
else:
    for j in range(N):
        print(A1)

Solution (Python):
n = int(input())
ai = []
for i in range(0, n):
    ai.append(int(input()))

a_sorted = sorted(ai)
a_max = a_sorted[-1]
a_max2 = a_sorted[-2]
for i in range(0, n):
    if ai[i] == a_max:
        print(a_max2)
    else:
        print(a_max)

Solution (Python):
import sys
from itertools import accumulate
N = int(input())
A = [int(sys.stdin.readline()) for _ in range(N)]

Ar = [-1] + list(accumulate(A, max)) + [-1]
Al = [-1] + list(accumulate(A[::-1], max))[::-1] +[-1]
Ans = [None]*(N+1)
for i in range(1, N+1):
    Ans[i] = max(Ar[i-1], Al[i+1])
print('\n'.join(map(str, Ans[1:])))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
import math
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def L(): return list(map(int, input().split()))
def TWO(M):
  L=[0]*M
  R=[0]*M
  for i in range(M):
    L[i],R[i] = II()
  return L, R

N = I()
A = [0]*N
for i in range(N):
  A[i] = I()
  
import numpy as np

index = np.argsort(A)

for i in range(N):
  if i == index[N-1]:
    print(A[index[N-2]])
  else:
    print(A[index[N-1]])

Solution (Python):
n = int(input())
max1 = 0
max2 = 0
max_index = 0
for i in range(n):
    a = int(input())
    if a >= max1:
        max2 = max1
        max1 = a
        max_index = i
    elif a > max2:
        max2 = a

for i in range(n):
    if i == max_index:
        print(max2)
    else:
        print(max1)

Solution (Python):
import copy
n=int(input())
A=[int(input()) for _ in range(n)]
A_=copy.deepcopy(A)
A_.sort()
MA=A_[-1]
mA=A_[-2]
for i in range(n):
    if A[i]<MA:
        print(MA)
    else:
        print(mA)

Solution (Python):
N = int(input())

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

L = [-10**9]
m = -10**9

for i in range(N):
    m=max(m,A[i])
    L.append(m)


R = [-10**9]
m = -10**9

for i in range(N):
    m=max(m,A[N-i-1])
    R.append(m)

R = R[::-1]

for i in range(N):
    print(max(L[i],R[i+1]))

Solution (Python):
N = int(input())
A = [0] * N
first = 0
second = 0
n = -1
for i in range(N):
  a = int(input())
  if a >= first:
    second = first
    first = a
    n = i
  else:
    second = max(a, second)
for i in range(N):
  if i == n:
    print(second)
    continue
  print(first)

Solution (Python):
N = int(input())
a_list = [int(input()) for _ in range(N)]

b_list = a_list.copy()
b_list.sort(reverse=True)
max_num = max(b_list)

for i in range(N):

    a = a_list[i]

    if a != max_num:
        print(max_num)
    else:
        f = True
        cnt = 0
        for b in b_list:
            if a != b:
                print(b)
                f = False
                break
            else:
                cnt += 1
                if cnt >= 2:
                    break
        if f:
            print(b)

Solution (Python):
n = int(input())
l = [int(input()) for _ in range(n)]
a, b = sorted(l)[-2:]
print('\n'.join(str(a) if e == b else str(b) for e in l))