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
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: str(sys.stdin.buffer.readline().rstrip())
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
aa = [ri() for _ in range(n)]
a = sorted(aa)
m = a[-1]
if m == a[-2]:
    for _ in range(n):
        print(m)
else:
    for i in aa:
        if i < m:
            print(m)
            continue
        else:
            print(a[-2])

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

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

M = sorted(A)

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

Solution (Python):
def main():
    a=[int(input()) for _ in range(int(input()))]
    m=sorted(a, reverse=True)
    i=a.index(m[0])
    for j in range(len(a)):
        print(m[0] if i != j else m[1])
    
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    a=[int(input()) for _ in range(int(input()))]
    idx = -1
    m = -1
    n = -1
    for i, v in enumerate(a):
        if v >= m:
            idx = i
            n = m
            m = v
        elif v >= n:
            n = v
    for i, v in enumerate(a):
        if idx == i:
            print(n)
        else:
            print(m)
    
if __name__ == "__main__":
    main()

Solution (Python):
import heapq
 
n = int(input())
a = [int(input()) for _ in range(n)]
m1, m2 = heapq.nlargest(2, a)
for ai in a:
  print(m1 if ai != m1 else m2)

Solution (Python):
N = int(input())
A = []
B = []
for n in range(N):
  temp = int(input())
  A.append(temp)
  B.append(temp)
list.sort(A, reverse = True)
for n in range(N):
  if B[n] == A[0]:
    print(A[1])
  else:
    print(A[0])

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

seq=[]

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

import heapq

tmp=list(map(lambda x: x*(-1),seq))
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)

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

seq=[]

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

import heapq

tmp=list(map(lambda x: x*(-1),seq))
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)

Solution (Python):

import sys
from collections import defaultdict, deque




def solve():
    n = int(input())
    x = n
    a = []
    c = defaultdict(int)
    for _ in range(n):
        a.append(int(input()))
        c[a[-1]] += 1
    b = a[:]
    a = list(set(a))
    a.sort(reverse=True)
    for e in b:
        i = 0
        while e == a[i] and c[e] == 1:
            i += 1
        print(a[i])

        
t = 1

for case in range(1,t+1):
    ans = solve()



"""

1 4
7
RRRR
1 1 0 1
----
4

1 4
47
RCRR
1 1 0 1
----
-1

2 2
10
RR
RR
1 7
4 1
----
4

2 2
10
RR
RR
7 4
7 4
----
-1

3 3
8
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


3 3
1
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


"""

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
s = sorted(A)
s.reverse()
for i in range(N):
    if A[i] == s[0]:
        print(s[1])
    else:
        print(s[0])

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

maxa = max(a)
maxb = max(a)
cntmax = a.count(maxa)
if cntmax >= 2:
    for i in range(n):
        print(maxa)
    exit()
else:
    maxi = a.index(maxa)
    x = 0
    y = 0
    if maxi >= 1:
        x = max(a[:maxi])
    if maxi < n - 1 :
        y = max(a[maxi+1:])
    maxb = max(x,y)

for i in a:
    if i == maxa:
        print(maxb)
    else:
        print(maxa)

Solution (Python):
N = int(input())
A = []
A_max = -1
index = 0
for i in range(N):
  a = int(input())
  if A_max <= a:
    A_max,index = a,i
  A.append(a)

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

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

T.sort()
T.reverse()

first=T[0]
second=T[1]

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

Solution (Python):
import copy
a=int(input())
b=[int(input()) for _ in range(a)]
c=copy.deepcopy(b)

n=max(b)
c.remove(n)
m=max(c)

o=b.index(n)

l=0
p=0

while l!=o:
    print(n)
    l+=1

print(m)
q=a-o-1
while p!=q:
    print(n)
    p+=1

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

T.sort()
T.reverse()

first=T[0]
second=T[1]

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

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

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

l2 = l
l2 = sorted(l2)
l2.reverse()
max = max(l)


ans = []
if l2[1] == max:
    for i in range(n):
        print(max)
else:
    for j in l:
        if j != max:
            print(max)
        else:
            print(l2[1])

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

Solution (Python):
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") 

n = int(input())
a = []

for _ in range(n):
    var = int(input())
    a.append(var)

first = int(max(a))
if 1<a.count(first):
    second = int(first)
else:
    second = sorted(set(a))[-2]

for _ in a[:]:
    if _ == first:
        print(second)
    else:
        print(first)

Solution (Python):
def solve():
    n=int(input())
    num=[]
    def append(num1):
        num.append(num1)
    def count1(num2):
        return num.count(num2)
    for i in range(n):
        a=int(input())
        append(a)
    max1=max(num)
    count=count1(max1)
    if count>1:
        for i in range(n):
            print(max1)
    else:
        for i in range(n):
            if num[i]==max1:
                if i==0:
                    print(max(num[1:]))
                elif i==n-1:
                    print(max(num[:n-1]))
                else:
                    print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_sorted = sorted(A, reverse=True)
    A_max = A_sorted[0]
    A_semi_max = A_sorted[1]
    
    for i in range(N):
        if A[i] != A_max:
            print(A_max)
        else:
            print(A_semi_max)
main()

Solution (Python):
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = [int(input()) for _ in range(N)]
max_A = max(A)
sorted_A = sorted(A, reverse=True)
if sorted_A[1] == max_A:
    for _ in range(N):
        print(max_A)
    exit()

for a in A:
    if a == max_A:
        print(sorted_A[1])
    else:
        print(max_A)

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

high = sorted(A, reverse=True)[: 2]

for i in range(n):
    if A[i] == high[0]:
        ans = high[1]
    else:
        ans = high[0]
    print(ans)

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

l = sorted(a, reverse=True)
m = a.index(l[0])
for i in range(n):
    if i == m:
        print(l[1])
    else:
        print(l[0])

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

data_s = sorted(data)

for d in data:
  if d == data_s[-1]:
    print(data_s[-2])
  else:
    print(data_s[-1])

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

max1_a = sorted_A[-1]
max2_a = sorted_A[-2]
if A.count(max1_a) > 1:
    for i in range(N):
        print(max1_a)
else:
    for i in range(N):
        if A[i] == max1_a:
            print(max2_a)
        else:
            print(max1_a)

Solution (Python):
n=int(input())
l=[int(input()) for i in range(n)]
ma=sorted(l)[-2:]
for j in l:
    if j==ma[1]:
        print(ma[0])
    else:
        print(ma[1])

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

A_max = max(A)

B = A.copy()
B.sort()
B.reverse()

if B[1] == A_max:
    for i in range(n):
        print(A_max)
else:
    for a in A:
        if a != A_max:
            print(A_max)
        else:
            print(B[1])

Solution (Python):
import heapq
n = int(raw_input())
ais = [int(raw_input()) for _ in range(n)]
heap = []
for ai in ais:
	heapq.heappush(heap, ai)
	if len(heap) == 3: 
		heapq.heappop(heap)

u,v = heapq.heappop(heap),heapq.heappop(heap)
for ai in ais:
	if ai == v:
		print u
	else:
		print v

Solution (Python):
import copy

n = int(input())

lis = []
for _ in range(n):
    lis.append(int(input()))
    
slis = sorted(copy.deepcopy(lis), reverse=True)
    
m = max(lis)
s = sorted(slis, reverse=True)
s.remove(m)
sm = max(s)


for i in range(n):
    if lis[i] != m:
        print(m)
    else:
        print(sm)

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

A_max = max(A)
A_max_ind = A.index(max(A))

for i in range(N):
    if i==A_max_ind:
        print(max(A[:i]+A[i+1:]))
    else:
        print(A_max)

Solution (Python):
n = int(input())
apple = []
for _ in range(n):
    apple.append(int(input()))
big = max(apple)
orange = [big for i in range(n)]
num = apple.index(big)
del apple[num]
cat = max(apple)
orange[num] = cat
for i in orange:
    print(i)

Solution (Python):
N = int(input())
f, s = [0, 0], [0, 0]
for i in range(N):
    a = int(input())
    if f[1] < a:
        s = f
        f = [i, a]
    elif s[1] < a:
        s = [i, a]
for i in range(N):
    if f[0] == i:
        print(s[1])
    else:
        print(f[1])

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

mf = max(A)
cnt_mf = A.count(mf)

if cnt_mf > 1:
    for _ in range(n):
        print(mf)
    exit()

Aset = set(A)

ms = max((Aset - {mf}))


for e in A:
    if e != mf:
        print(mf)
    else:
        print(ms)

Solution (Python):
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
 
b = copy.deepcopy(a)
b.sort()
max1 = b[-1]
max2 = b[-2]
 
for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    d = [int(input()) for _ in range(n)]
    s_d = sorted(d)
    max = s_d[-1]
    for di in d:
        if di == s_d[-1]:
            print(s_d[-2])
        else:
            print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

b = copy.deepcopy(a)
b.sort()
max1 = b[-1]
max2 = b[-2]

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

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = list(sorted(A, reverse=True))

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

Solution (Python):
import sys
n = int(input())
ls = [int(input()) for _ in range(n)]
mx = max(ls)
c = ls.count(mx)
new = ls[:]
new.remove(mx)
nx = max(new)
if c > 1:
    for _ in range(n):
        print(mx)
    sys.exit()
for i in ls:
    if i == mx:
        print(nx)
    else:
        print(mx)

Solution (Python):
import copy

N = int(input())

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

B = copy.copy(A)
B.sort()

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

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

n, *a = map(int, read().split())
sort_a =  sorted(a)

max_1 = sort_a[-1]
max_2 = sort_a[-2]
l = [max_2 if x == max_1 else max_1 for x in a]
print(*l)

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

li2 = li1.copy()
li2.sort(reverse=True)

for i in range(n):
    if li1[i]!=li2[0]:
        print(li2[0])
    else:
        print(li2[1])

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())
A = []
for _ in range(N):
    A.append(int(input()))

import heapq

h = []
for a in A:
    if len(h) < 2:
        heapq.heappush(h, a)
    else:
        heapq.heappushpop(h, a)

for a in A:
    if a == h[1]:
        print(h[0])
    else:
        print(h[1])

Solution (Python):
import heapq


def main():
    N = int(input())
    A = [(-1)*int(input()) for _ in range(N)]
    A_ = A.copy()
    heapq.heapify(A)

    for a in A_:
        tmp1 = heapq.heappop(A)
        if a == tmp1:
            tmp2 = heapq.heappop(A)
            print((-1) * tmp2)
            heapq.heappush(A, tmp1)
            heapq.heappush(A, tmp2)
        else:
            print((-1) * tmp1)
            heapq.heappush(A, tmp1)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = []
M = 0
j = -1
for i in range(n):
    a = int(input())
    A.append(a)
    if a > M:
        M = a
        j = i
A.sort()
for i in range(n):
    if i == j:
        print(A[-2])
        continue
    print(M)

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

a = []

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

a_max = max(a)
a_max_index = a.index(a_max)

a.sort(reverse=True)
a_second_max = a[1]

for i in range(n):
    if i == a_max_index:
        print(a_second_max)
    else:
        print(a_max)

Solution (Python):
N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())
m = max(A)
if A.count(m) > 1:
    for _ in range(N):
        print(m)
else:
    mi = A.index(m)
    for i in range(N):
        if mi == i:
            print(sorted(A)[-2])
        else:
            print(m)

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

b = sorted(a,reverse=True)
x = b[0]
y = b[1]

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

Solution (Python):

n = int(input())
a = []
y = 0
for i in range(n):
    x = int(input())
    a.append(x)
    if y <= x:
        y = x
        m = i

a.sort(reverse = True)
a_1 = a[0]
a_2 = a[1]

if a_1 == a_2:
    for i in range(n):
        print(a_1)

else:
    for i in range(m):
        print(a_1)

    print(a_2)

    for j in range(m+1,n):
        print(a_1)

Solution (Python):
import copy

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

top = max(a)
if a.count(top) != 1:
  for i in range(n):
    print(top)
else:
  topind = a.index(top)

  tmp = copy.deepcopy(a)
  tmp[topind] = 0
  sub = max(tmp)
  
  for i in range(n):
    if i == topind:
      print(sub)
    else:
      print(top)

Solution (Python):
n = int(input())
l = []
dic = {}


for i in range(n):
    a = int(input())
    l.append(a)
    if(dic.get(a) is None):
        dic[a] = 1
    else:
        dic[a] += 1

mi = max(dic)
if(dic[mi]>=2):
    for i in range(n):
        print(mi)
else:
    del(dic[mi])
    mi2 = max(dic)
    for i in range(n):
        if(l[i]==mi):
            print(mi2)
        else:
            print(mi)

Solution (Python):



from itertools import permutations as perm


N = int(input())




l=[]
for i in range(N):
    B = int(input())
    l.append(B)
m=max(l)
x=l.copy()
x.remove(m)
n=max(x)
for i in l:
    if i!=m:
        print(m)
    else:
        print(n)

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
sort=sorted(A)
x,y=sort[-1],sort[-2]
for a in A:
    print(x if a!=x else y)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
Max = max(A)
x = A.count(Max)

for i in range(0 ,N) :
    if x >= 2 :
        print(Max)
    elif A[i] == Max :
        A[i] = 0
        print(max(A))
    else : print(Max)

Solution (Python):
N = int(input())
maximum = 0
max_sec = 0
A = []
for _ in range(N):
  a = int(input())
  A.append(a)
  if a > maximum:
    max_sec = maximum
    maximum = a
  elif a > max_sec:
    max_sec = a
for i in range(N):
  if A[i] == maximum:
    print(max_sec)
  else:
    print(maximum)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    first = max(A)
    idx = A.index(first)
    second = max(A[:idx]+A[idx+1:])
    for i in range(N):
        if i == idx:
            print(second)
        else:
            print(first)

if __name__ == "__main__":
    main()

Solution (Python):

def solve(N, As):
    max = sorted(As)[-1]
    secmax = sorted(As)[-2]
    if max == secmax:
        for _ in range(N):
            print(max)
    else:
        for a in As:
            if a == max:
                print(secmax)
            else:
                print(max)



if __name__ == "__main__":
    N = int(input())
    As = []
    [As.append(int(input())) for i in range(N)]
    solve(N, As)

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
s=sorted(a)
maxi=max(a)
maxi2=s[-2]
for i in a:
    if i == maxi:
        print(maxi2)
    else:
        print(maxi)

Solution (Python):


N = int(input())

max_a = 0
max_i = 0
max_a_2 = 0

for i in range(N):
    A = int(input())
    
    if A >= max_a:
        max_a_2 = max_a
        max_a = A
        max_i = i

    elif A >= max_a_2:
        max_a_2 = A

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

    else:
        print(max_a_2)

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

m = max(A)
c = A.count(m)
if c == 1:
    m2 = sorted(set(A),reverse=True)[1]
    for i in A:
        print (m) if i != m else print(m2)
else:
    for _ in range(n):
        print (m)

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

A = []
for i in range(N):
    a = int(input())
    A.append([a, i])
    
A_ = sorted(A, reverse=True)



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

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

A = []

[A.append(int(input())) for x in range(N)]

max_num = max(A)
num = A.index(max(A))
A[num] = 0

st_max_num = max(A)

for i in range(num):
    print(max_num)
print(st_max_num)

for i in range(num+1,N):
    print(max_num)

Solution (Python):
n = int(input())
a = [0 for _ in range(n)]
for i in range(n):
	a[i] = int(input())
maxa = max(a)
basho = a.index(maxa)
a[basho] = 0
for i in range(n):
	if i != basho:
		print(maxa)
	else:
		print(max(a))

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

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

idx1, ma1 = A.index(max(A)), max(A)

tmp = A[idx1]
A[idx1] = 0
idx2, ma2 = A.index(max(A)), max(A)

A[idx1] = tmp

for i in A:
	if i == ma1:
		print(ma2)
	else:
		print(ma1)

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

Solution (Python):
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    descending = sorted(A, reverse=True)
    maximum = descending[0]
    second = descending[1]
    for a in A:
        if a == maximum:
            print(second)
        else:
            print(maximum)
main()

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

A = []
for i in range(N):
    a = int(input())
    A.append([a, i])
    
A_ = sorted(A, reverse=True)



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

Solution (Python):
import copy
N = int(input())
output = []
dic = {}
A = []

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

A = sorted(A)
max_1 = A[-1]
max_2 = A[-2]

for i in range(N):
  tmp = dic[i]
  if tmp == max_1:
    output.append(max_2)
  else:
    output.append(max_1)
print(*output, sep="\n")

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


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

b=[]
b = copy.deepcopy(a)
b.sort(reverse=True)



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

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


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

b=[]
b = copy.deepcopy(a)
b.sort(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 = []
for _ in range(N):
    A += [int(input())]
sorted_A = sorted(A)

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

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

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

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

Solution (Python):
def main():
    n = int(input())
    a = [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])
   
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

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

    it = iter(sorted(enumerate(A, start=1), key=itemgetter(1), reverse=True))
    i, ma1 = next(it)
    _, ma2 = next(it)

    for j in range(1, N + 1):
        if j == i:
            print(ma2)
        else:
            print(ma1)


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

max_num = -1
max_index = []
second_num = -1
dic = {}
for i in range(1, N+1):
    num = int(input())
    dic[i] = num
    if num > max_num:
        second_num = max_num
        max_num = num
        max_index.clear()
        max_index.append(i)
    elif num == max_num:
        max_index.append(i)
    elif num > second_num:
        second_num = num

for i in range(1, N+1):
    if dic[i] < max_num:
        print(max_num)
    elif dic[i] == max_num:
        if len(max_index) > 1:
            print(max_num)
        else:
            print(second_num)

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

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

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

base=max(a)
maxkosu=a.count(base)
if maxkosu>1:
  for i in range(N):
    print(base)
else:
  maxidx=a.index(base)
  a[maxidx]=-1
  reigai=max(a)
  for i in range(N):
    if i==maxidx:
      print(reigai)
    else:
      print(base)

Solution (Python):
N=int(input())
A=[int(input())for _ in range(N)]
sort_A=sorted(A,reverse=True)
num1=sort_A[0]
num2=sort_A[1]
for i in range(N):
    if A[i]==num1:
        print(num2)
    else:
        print(num1)

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

m = max(A)
L = sorted(A)
L.sort(reverse = True)

if L[1] == m:
    for _ in range(n):
        print(m)
else:
    for i in range(n):
        if A[i] == m:
            A.pop(i)
            print(max(A))
            A.append(0)
        else:
            print(m)

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
sortedA=sorted(A,reverse=True)
for a in A:
	if a!=sortedA[0]:
		print(sortedA[0])
	else:
		print(sortedA[1])

Solution (Python):
n = int(input())
A = [int(input()) for i in range(n)]
S = sorted(A)[::-1]
m = S[0]
sm = S[1]
for a in A:
	print(m if a != m else sm)

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

for i in range(N):
    if M[N-1]>A[i]:
        print(M[N-1])
    elif M[N-1]==A[i]:
        print(M[N-2])

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

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)








n=n0()
a=n2(n)
b=sorted(a)
m1=b[-1]
m2=b[-2]
c=[]

for i in a:
    if i==m1:
        c.append(m2)
    else:
        c.append(m1)
print(*c,sep="\n")

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)








n=n0()
a=n2(n)
b=sorted(a)
m1=b[-1]
m2=b[-2]

for i in a:
    p0(i==m1,m2,m1)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  b=int(input())
  a.append(b)
s=a.copy()
a=sorted(a,reverse=True)

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

Solution (Python):
import copy

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

MaxIndex = A.index(max(A))

for i in range(N):
    if i != MaxIndex:
        print(A[MaxIndex])
    else:
        B = copy.copy(A)
        del B[MaxIndex]
        print(max(B))

Solution (Python):



def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    max1 = max(As)
    max_idx = As.index(max1)
    As.remove(max1)
    max2 = max(As)
    max_list = [max1] * N
    max_list[max_idx] = max2
    for m in max_list:
        print(m)


if __name__ == '__main__':
    main()

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

A=sorted(a)

for x in a:
    if x==A[-1]:
        print(A[-2])
    else:
        print(A[-1])

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

maximum = max(A)
maximum_index = A.index(maximum)
second = max(A[:maximum_index] + A[maximum_index+1:])

for i in range(N):
    if i == maximum_index:
        print(second)
    else:
        print(maximum)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    A = [int(i) for i in readlines()]
    B = sorted(A) 
    mx = B[-1]
    mx2 = B[-2]
    for i in A:
        if mx == i:
            print(mx2)
        else:
            print(mx)
if __name__ == '__main__':
    main()

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

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

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

A = [0]*N

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

Max = a[len(a)-1]
PreMax = a[len(a)-2]

for i in range(N):
    
    if A[i] < Max:
        print(Max)
    else:
        print(PreMax)

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
maximum=max(A)
maximum2=sorted(A)[-2]
for a in A:
    if a!=maximum:
        print(maximum)
    else:
        print(maximum2)

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

tNum = max(a)
sNum = sorted(a, reverse=True)[1]

if a.count(tNum) > 1:
  for _ in range(n):
    print(tNum)
  exit()

for i in a:
  if i == tNum:
    print(sNum)
    continue
  print(tNum)

Solution (Python):
n=int(input())
a=[int(input()) for i 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):
n = int(input())
a = [int(input()) for i in range(n)]

max_a = max(a)
if a.count(max_a) > 1:
    for i in range(n):
        print(max_a)
else:
    sec_max = sorted(a)[-2]
    max_i = a.index(max_a)
    for i in range(n):
        if i == max_i:
            print(sec_max)
        else:
            print(max_a)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
x = max(A)
k = A.index(x)
for i in range(N):
  if i != k:
    print(x)
  else:
    A.remove(x)
    print(max(A))

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

m = max(a)
count = a.count(m)

if count != 1:
    for i in range(n):
        print(m)

else:
    switch = 0
    for i in range(n-1):
        if a[i] == m:
            a.remove(m)
            m2max = max(a)
            print(m2max)
            a.append(m)
            switch = 1
        else:
            print(m)
    
    if switch == 1:
        print(m)
    else:
        a.remove(m)
        m2max = max(a)
        print(m2max)

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

for i in range(n):
    h.append(int(input()))
    
left = [0] * n
left[0] = h[0]
for i in range(1, n):
    left[i] = max(left[i - 1], h[i])

right = [0] * n
right[-1] = h[-1]
for i in reversed(range(n - 1)):
    right[i] = max(right[i + 1], h[i])

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

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

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

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