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):
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)

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

ma = max(A)
ma2 = sorted(A)[-2]
for a in A:
    if a==ma:
        ans = ma2
    else:
        ans = ma
    print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = ''
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    M, M2 = sorted(A)[-1], sorted(A)[-2]
    for i in range(N):
        if A[i] == M:
          ans += str(M2) + '\n'
        else:
          ans += str(M) + '\n'
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):




geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)
a1, a2, i1 = 0, -1, -1

for i in range(N):
    ai = gete(int)
    if ai >= a1:
        a1, a2 = ai, a1
        i1 = i
    elif ai >= a2:
        a2 = ai

if a1 == a2:
    print(*[a1] * N, sep="\n")
else:
    print(*[a2 if i == i1 else a1 for i in range(N)], sep="\n")

Solution (Python):
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque



def input1():
	return int(input())


def input2():
	return map(int,input().split())


def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets


def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	
	return fact(x+y)/fact(x)/fact(y)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True


n=int(input())
A=[]
for _ in range(n):
	A.append(input1())
B=sorted(A)
max_1=B[-1]
max_2=B[-2]

for i in A:
	if i==max_1:
		print(max_2)
	else:
		print(max_1)

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

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

A_max = A_List2[-1]
A_max2 = A_List2[-2]

for a in A_List:
    if a ==A_max:
        print(A_max2)
    else:
        print(A_max)

Solution (Python):
def resolve():
    a = [int(input()) for _ in range(int(input()))]
    st = sorted(a)
    first = st[-1]
    second = st[-2]
    for i in a:
        if i == first:
            print(second)
        else:
            print(first)


resolve()

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

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[-1])
    else:
        print(sorted_a[-2])

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

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a)
m,M=b[-2:]
for i in range(n): print(m if a[i]==M else M)

Solution (Python):

n= int(input())
a = [int(input()) for i in range(n)]
a_s = sorted(a,reverse=True)

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

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

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
B=sorted(A)
A0=B[N-1]
A1=B[N-2]
for i in range(N):
  if A[i]!=A0:
    print(A0)
  else:
    print(A1)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))


def resolve():
    N,=pin()
    A=[int(input())for i in range(N)]
    B=sorted(A)
    first=B[-1]
    second=B[-2]
    for a in A:
        if a==first:print(second);continue
        print(first)
          

resolve()

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

a_s=sorted(a)
m1=a_s[-1]
m2=a_s[-2]

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

Solution (Python):
n = int(input())
top_val = 0
top_idx = set()
semi_top = 0

for i in range(n):
  a = int(input())
  if a > top_val:
    semi_top = top_val
    top_val = a
    top_idx.clear()
    top_idx.add(i)
  elif a == top_val:
    top_idx.add(i)
  elif a > semi_top:
    semi_top = a

if len(top_idx) > 1:
  semi_top = top_val

semi_top = str(semi_top)
top_val = str(top_val)

print("\n".join([semi_top if i in top_idx else top_val for i in range(n)]))

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
left = [0]*n
right = [0]*n
for i in range(1, n):
    left[i] = max(left[i-1], a[i-1])
    right[n-i-1] = max(right[n-i], a[n-i])
for i in range(n):
    print(max(left[i], right[i]))

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
AMax = max(A)
x = A.index(AMax)
Aelse = A[:x]+A[x+1:]
AelseMax = max(Aelse)
if AMax == AelseMax:
    for i in range(N):
        print(AMax)
else:
    for i in range(N):
        if x == i:
            print(AelseMax)
        else:
            print(AMax)

Solution (Python):
N=int(input())
arr = [int(input()) for _ in range(N)]
arr2 = sorted(arr)
max1 =arr2[-1]
max2=arr2[-2]


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

Solution (Python):
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
s = copy.copy(a)
s.sort(reverse=True)
first = s[0]
second = s[1]
mx = []
for i in range(n):
    if a[i] == first:
        mx.append(second)
    else:
        mx.append(first)
for i in range(n):
    print(mx[i])

Solution (Python):
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
max_a=max(a)
second=b[-2]
for i in range(n):
    if a[i] != max_a:
        print(max_a)
    else:
        print(second)

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

s_a_ls = sorted(a_ls)
max_val = s_a_ls[-1]

for item in a_ls:
    if item == max_val:
        print(s_a_ls[-2])
    else:
        print(max_val)

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

l = sorted(A)
b = l[-1]
c = l[-2]

for i in range(N):
    if A[i] == b:
        print(c)
    else:
        print(b)

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

sorted_A_list = sorted(A_list, reverse=True)

for a in A_list:
    if a == sorted_A_list[0]:
        ans = sorted_A_list[1]
    else:
        ans = sorted_A_list[0]
    print(ans)

Solution (Python):
n=int(input())
as_=[int(input()) for _ in range(n)]
l=sorted(as_)
m1=l[-1]
m2=l[-2]
for a in as_:
    if a==m1:
        print(m2)
    else:
        print(m1)

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

t = []
for _ in range(n):
  t.append(int(input()))

s = sorted(t)
m = s[-1]
m1 = s[-2]

for i in t:
  if i!=m:
    print(m)
  else:
    print(m1)

Solution (Python):
import numpy

N = int(input())

la = list()
for i in range(N):
    la.append(int(input()))

max1 = sorted(la)[-1]
max2 = sorted(la)[-2]

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = IR(n)

B = sorted(A)
a = B.pop()
b = B.pop()
for x in A:
    if x == a:
        print(b)
    else:
        print(a)

Solution (Python):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]

for i in range(N):
  if A[i] == m1:
    print(m2)
  else:
    print(m1)

Solution (Python):
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

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

Solution (Python):
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

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

Solution (Python):
n = int(input())
a = list(int(input()) for i in range(n))
l = a[:]
l.sort(reverse=True)
x = l[0]
y = l[1]
ans = 0
for i in range(n):
    if a[i] == x:
        ans = y
    else:
        ans = x
    print(ans)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    A=int(input())
    a.append(A)
b=sorted(a)
for i in range(n):
    if a[i]==b[-1]:
        print(b[-2])
    else:
        print(b[-1])

Solution (Python):
def solve():
    N = int(input())
    A = []
    m_A = [0, 0]
    for i in range(N):
        a = int(input())
        A.append(a)
        if m_A[1] < a:
            m_A[0] = m_A[1]
            m_A[1] = a
        elif m_A[0] < a:
            m_A[0] = a
    for i in range(N):
        if A[i] == m_A[1]:
            print(m_A[0])
        else:
            print(m_A[1])


solve()

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

max_A_1 = sorted(A)[-1]
max_A_2 = sorted(A)[-2]

for i in range(N):
    if A[i] != max_A_1:
        print(max_A_1)
    else:
        print(max_A_2)

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

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

comp = sorted(a, reverse = True)

Fmax = comp[0]
Smax = comp[1]

for i in range(n):
    if a[i] == Fmax:
        print(Smax)
    
    else:
        print(Fmax)

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

first = sorted(A)[-1]
second = sorted(A)[-2]

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

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

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

first = sorted(A)[-1]
second = sorted(A)[-2]

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

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

Solution (Python):
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    maxi = max(A)
    a = A.copy()
    a.sort()
    submaxi = max(a[:N-1])
    for i in range(N):
        if A[i] != maxi:
            print(maxi)
        else:
            print(submaxi)


if __name__ == "__main__":
    main()

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

B = sorted(A,reverse=True)
for i in A:
    if i==B[0]:
        print(B[1])
    else:
        print(B[0])

Solution (Python):


N = int(input())
A = [int(input()) for _ in range(N)]
mx1 = sorted(A)[-1]
mx2 = sorted(A)[-2]
for i in range(N):
    if A[i] != mx1:
        print(mx1)
    else:
        print(mx2)

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
A = [int(input()) for _ in range(N)]
sortA = sorted(A, reverse=True)

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

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
A = [int(input()) for _ in range(N)]
sortA = sorted(A, reverse=True)

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

Solution (Python):

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

a_sort=sorted(a)

max_a=max(a)
next_max=a_sort[-2]

lis=[0]*n

for i in range(n):
    if a[i]!=max_a:
        lis[i]=max_a
    else:
        lis[i]=next_max

L=[str(a) for a in lis]
L="\n".join(L)
print(L)

Solution (Python):
N,*A =map(int,open(0).read().split())
B =sorted(A)
biggest = B[-1]
for i in A:
  if i==biggest:
    print(B[-2])
  else:
    print(biggest)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
s = sorted(a)
one, two = s[-1], s[-2]
for i in a:
  print(one if i != one else two)

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

B = sorted(A, reverse=True)
first = B[0]
second = B[1]

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

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

B = sorted(A, reverse=True)
first = B[0]
second = B[1]

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

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

B = sorted(A)
first = B[-1]
second = B[-2]

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

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

first = max(A)
B = A.copy()
B.remove(first)
second = max(B)

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

Solution (Python):
n=int(input())
maxx=0
sec=0
lis=[]
for i in range(n):
  s=int(input())
  lis.append(s)
  if s>=maxx:
    sec=maxx
    maxx=s
  elif s>sec:
    sec=s
for j in range(0,n):
  if lis[j]==maxx:
    print(sec)
  else:
    print(maxx)

Solution (Python):
n=int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())
sorteda = a.copy()
sorteda.sort(reverse=True)
maxa = sorteda[0]
secmaxa = sorteda[1]
for i in range(n):
  if a[i]==maxa:
    print(secmaxa)
  else:
    print(maxa)

Solution (Python):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)  
max_A = B[N-1]
smax_A = B[N-2]

for i in range(N):
  if A[i] == max_A:
    print(smax_A)
  else:
    print(max_A)

Solution (Python):
n = int(input())
aaa = [int(input()) for _ in range(n)]
max_a = sorted(aaa)[-1]
second_a = sorted(aaa)[-2]
for a in aaa:
    if a == max_a:
        print(second_a)
    if a != max_a:
        print(max_a)

Solution (Python):
def main():
    N = int(input())
    A = list()
    max_value = 0
    second_max_value = 0
    max_index = -1
    for i in range(N):
        a = int(input())
        A.append(a)
        if a > max_value:
            second_max_value = max_value
            max_value = a
            max_index = i
        elif a > second_max_value:
            second_max_value = a
    for i, a in enumerate(A):
        if i == max_index:
            print(second_max_value)
        else:
            print(max_value)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = sorted(((i, int(input())) for i in range(N)), key=lambda x: x[1])

maxidx, maxi = A[-1]
secidx, second = A[-2]

A.sort()
for a in A:
    if a[0] == maxidx:
        print(second)
    else:
        print(maxi)

Solution (Python):

N = int(input())
A = [int(input()) for _ in range(N)]
first, second = sorted(A)[::-1][:2]
for a in A:
    print(first if a != first else second)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a, reverse=True)
mx = sorted(b)[-1]
mx2 = sorted(b)[-2]

for i in a:
    if i != mx:
        print(mx)
    else:
        print(mx2)

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

maxR = [0] * n
maxL = [0] * n
maximum = 0
for i in range(n):
    maximum = max(maximum,a[i])
    maxL[i] = maximum
maximum = 0
for i in range(n):
    maximum = max(maximum,a[n-i-1])
    maxR[n-i-1] = maximum



for i in range(n):
    if i == 0:
        print(maxR[1])
    elif i == n-1:
        print(maxL[n-2])
    else:
        print(max(maxL[i-1],maxR[i+1]))

Solution (Python):

n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
east=[0]*(n+1)
west=[0]*(n+1)
for i in range(1,n+1):
    east[i]=max(east[i-1],a[i-1])
    west[-i-1]=max(west[-i],a[-i])
for k in range(1,n+1):
    print(max(east[k-1],west[k]))

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

left = [a[0]]
right = [a[-1]]
for i in range(1, n):
    left.append(max(left[i-1], a[i]))
    right.append(max(right[i-1], a[n-i-1]))
right = right[::-1]
print(right[1])

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

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

a = sorted(s,reverse=True)
M = a[0]

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

Solution (Python):
n = int(input())
a = [[i, int(input())] for i in range(n)]
a.sort(reverse=True, key=lambda x:x[1])
first, second = a[0][1], a[1][1]
a.sort(key=lambda x:x[0])
for i in range(n):
  print(first if a[i][1] != first else second)

Solution (Python):
import numpy as np

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

max_idx = np.argmax(a)
first = a[max_idx]
a[max_idx] = 0
second = max(a)
a[max_idx] = first

for i in range(n):
  if a[i] == first:
    print(second)
  else:
    print(first)

Solution (Python):
import copy
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int, read().split()))

max_a = max(a)
b = copy.copy(a)
b.remove(max_a)
nxt_a = max(b)

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

Solution (Python):

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

a2=sorted(a)
amax1=a2[n-1]
amax2=a2[n-2]

for i in range(n):
    if a[i]==amax1:
        print(amax2)
    else:
        print(amax1)

Solution (Python):
import sys
import math
from collections import Counter
import itertools
import fractions



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")


 
N=II()
A=[II() for i in range(N)]

b=sorted(A)
b.reverse()
for i in range(N):
    if A[i] == b[0]:
        print(b[1])
    else:
        print(b[0])

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

maxi = [0, 0]
for i in range(n):
  if lst[i] > maxi[0]:
    maxi = [lst[i], i]
    
maxi2 = 0
for j in range(n):
  if j == maxi[1]:
    continue
  else:
    if lst[j] > maxi2:
      maxi2 = lst[j]
    
for i in range(n):
  if i != maxi[1]:
    print(maxi[0])
  else:
    print(maxi2)

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


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

if A.count(greatest)==1:
    B = list(set(A))
    B.remove(greatest)
    for i in range(N):
        if A[i] != greatest:
            print(greatest)
        else:
            print(max(B))

else:
    for i in range(N):
        print(greatest)

Solution (Python):
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[1])
    else:
        print(b[0])

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

b = sorted(a)
b.reverse()

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

Solution (Python):
n = int(input())
a_list = [int(input()) for i in range(n)]
a_list_sort = sorted(a_list)
a_list_max1 = max(a_list)
a_list_max2 = a_list_sort[-2]
for i in range(n):
    if a_list_max1 == a_list[i]:
        print(a_list_max2)
    else:
        print(a_list_max1)

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

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

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())
Aa = A[:]
Aa.sort()
maxa = Aa[-1]
for i in range(N):
    if A[i] != maxa:
        print(maxa)
    else:
        print(Aa[-2])

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

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
maxi = max(a)
s = sorted(a,reverse=True)

for i in range(n):
    if a[i] != maxi:
        print(maxi)
    else:
        print(s[1])

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
D=sorted(A)
num=max(D)
num2=D[-2]
for i in range(N):
    if A[i]==num:
        print(num2)
    else:
        print(num)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A, reverse=True)
result = [B[0]]*N
x = A.index(B[0])
if B[0] != B[1]:
    result[x] = B[1]

for a in result:
    print(a)

Solution (Python):
N = int(input())
a1 = 0
a2 = 0
a1_ind = -1

for i in range(0,N):
    x = int(input())
    if a1 < x:
        a2 = a1
        a1 = x
        a1_ind = i
    elif a2 < x:
        a2 = x

for i in range(0,N):
    if i == a1_ind:
        print(a2)
    else:
        print(a1)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int(input())
    A = deque([int(input()) for i in range(N)])
    MAX = max(A)
    MAX2 = 0
    Ms = [-1]*N
    for i in range(N):
        if A[i] == MAX:
            if MAX2 != 0:
                Ms[i] = MAX2
            else:
                A[i] = 0
                MAX2 = max(A)
                Ms[i] = MAX2
        else:
            Ms[i] = MAX
    for i in range(N):
        print(Ms[i])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int(input())
    A = deque([int(input()) for i in range(N)])
    MAX = max(A)
    MAX2 = 0
    Ms = [-1]*N
    for i in range(N):
        if A[i] == MAX:
            if MAX2 != 0:
                Ms[i] = MAX2
            else:
                A[i] = 0
                MAX2 = max(A)
                Ms[i] = MAX2
        else:
            Ms[i] = MAX
    for i in range(N):
        print(Ms[i])

if __name__ == '__main__':
    main()

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

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

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

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

Bs = sorted(As)
maxA2, maxA = Bs[-2:]

anss = []
for A in As:
    if A == maxA:
        anss.append(maxA2)
    else:
        anss.append(maxA)

print('\n'.join(map(str, anss)))

Solution (Python):
import copy
import sys
input = sys.stdin.readline
n=int(input())
A = [int(input()) for _ in range(n)]
A2 = copy.deepcopy(A)
max1 = max(A)
A.remove(max1)
max2 = max(A)
for i in range(n):
    if A2[i]==max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
sortedA=sorted(A,reverse=True)
large_1=sortedA[0]
if sortedA[1]==large_1 or len(A)==1:
    for i in range(N):
        print(large_1)
else:
    num=A.index(large_1)
    for i in range(num):
        print(large_1)
    print(sortedA[1])
    for j in range(N-num-1):
        print(large_1)

Solution (Python):


n = int(input())
a = [int(input()) for i in range(n)]
a_sort = sorted(a)
amax = a_sort[-1]
asmas = a_sort[-2]

for i in range(n):
  if a[i] == amax:
    print(asmas)
  else:
    print(amax)

Solution (Python):
n=int(input())
A=[int(input()) for _ in range(n)]
m=max(A)
p=A.index(m)
l=1
for i in range(n):
	if i!=p:
		l=max(l,A[i])
for i in range(n):
	if i==p:
		print(l)
	else:
		print(m)

Solution (Python):


n=int(input())
a=[int(input()) for _ in range(n)]
max_=max(a)
cnt=a.count(max_)
pos=a.index(max_)

if cnt>1:
    for i in range(n):
        print(max_)
else:
    a[pos]=0
    max2_=max(a)
    for i in range(n):
        if i==pos:
            print(max2_)
        else:
            print(max_)

Solution (Python):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = sorted(a)
max = b[-1]
max_sec = b[-2]

for A in a:
    if A == max:
        print(max_sec)
    else:
        print(max)

Solution (Python):
n = int(input())
A = [int(input()) for i in range(n)]
B = sorted(A)
x = B[-1]
y = B[-2]

for i in A:
    if i == x:
        print(y)
    else:
        print(x)

Solution (Python):
N = int(input())
A = list(int(input()) for _ in range(N))
B = A[:]
B.sort()
mx = B[-1]
mx2 = B[-2]

for a in A:
  if a == mx:
    print(mx2)
  else:
    print(mx)

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

for i in A:
  if i < S[N-1]:
    print(S[N-1])
  else:
    print(S[N-2])

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

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

Solution (Python):
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
m = max(l)
ans = [m]*n
if len(set(l)) == 1 or l.count(m) > 1:
    for i in ans:
        print(i)
else:
    x = sorted(set(l))[-2]
    a = l.index(m)
    ans[a] = x
    for i in ans:
        print(i)

Solution (Python):
import sys
import os
import math
import string
import collections

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = [ii() for _ in range(N)]
    SA = sorted(A, reverse=True)
    for a in A:
        if a == SA[0]:
            print(SA[1])
        else:
            print(SA[0])


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  ai=int(input())
  a.append(ai)
b=sorted(a)
for i in range(n):
  if a[i]==b[-1]:
    print(b[-2])
  else:
    print(b[-1])

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

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

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