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 heapq
import copy
import numpy as np

N=int(input())
A=[]
for n in range(N):
    A.append( int(input()) )
A_ = copy.deepcopy(A)
A_ = np.array(A_)
A_ *= -1
A_ = list(A_)
heapq.heapify( A_ )
max_val = heapq.heappop(A_)*(-1)
second_max_val = heapq.heappop(A_)*(-1)

is_max = []
for n in range(N):
    if A[n]==max_val:
        is_max.append(True)
    else:
        is_max.append(False)
max_val_num = np.sum( np.array(is_max) )

for n in range(N):
    if max_val_num > 1:
        print(max_val)
    else:
        if is_max[n]:
            print(second_max_val)
        else:
            print(max_val)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
for x in A:
    if x == B[-1]:
        print(B[-2])
    else:
        print(B[-1])

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

Solution (Python):
import copy
def test(a_,n_):
    return abs(round(0.1/(n_-(a_+0.1))))

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_max = sum(x == a_max for x in a)
if n_max > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    
    b = copy.copy(a)
    b.remove(a_max)
    a_max_2 = max(b)
    for i in a:
        x = test(i, a_max)
        print((1-x)*a_max + x*a_max_2)

Solution (Python):
import copy
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_ = sum(x == a_max for x in a)
if n_ > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    
    b = copy.copy(a)
    b.remove(a_max)
    a_max_2 = max(b)
    for i in a:
        if i == a_max:
            print(a_max_2)
        else:
            print(a_max)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_ = sum(x == a_max for x in a)
if n_ > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    a_max_2=sorted(set(a))[-2]
    for i in a:
        if i == a_max:
            print(a_max_2)
        else:
            print(a_max)

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

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

first = sorted(set(x))[-1]

if len(set(x))==1:
  second = -100
else:
  second = sorted(set(x))[-2]

max_count = x.count(max(x))

for i in x:
  if (i == first) and (max_count == 1):
    if second == -100:
      print(first)
    else:
      print(second)
  elif (i == first) and (max_count != 1):
    print(first)
  else:
    print(first)

Solution (Python):
import numpy as np

N = int(input())
A_s = []
for i in range(N):
  A_s.append(int(input()))
  
A_s = np.array(A_s)
  
m_index = A_s.argmax()
sort_A_s = sorted(A_s)
m_value = A_s[m_index]
m_second = sort_A_s[N-2]

for i in range(N):
  if i != m_index:
    print(m_value)
  else:
    print(m_second)

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

sa = sorted(a, reverse=True)

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

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
B = A[:]
B.sort(reverse = True)
max_A = max(A)
for i in range(n):
    if A[i] == max_A:
        print(B[1])
    else:
        print(max_A)

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

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

sorted_As = sorted(As, reverse=True)
top_As = sorted_As[:2]

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

Solution (Python):
n=int(input())
alis=[int(input()) for i in range(n)]
anslis=[max(alis)]*n
if alis.count(max(alis))==1:
	anslis[alis.index(max(alis))]=sorted(alis)[-2]
for i in range(n):
	print(anslis[i])

Solution (Python):
N = int(input())
nums = [int(input()) for _ in range(N)]
 
all_max = max(nums)
 
new_nums = list(nums)
new_nums.remove(all_max)
 
second_max = max(new_nums)  
 
for i in range(N): 
    if nums[i] == all_max: 
        print(second_max)
    else:
        print(all_max)

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

all_max = max(nums)

new_nums = list(nums)
new_nums.remove(all_max)

second_max = max(new_nums)  

for num in range(N):
    if nums[num] == all_max:
        print(second_max)
    else:
        print(all_max)

Solution (Python):
import copy

n = int(input())
l = [int(input()) for i in range(n)]
Max1 = sorted(l)[-1]
Max2 = sorted(l)[-2]
for i in range(n):
    if l[i] == Max1:
        print(Max2)
    else:
        print(Max1)

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

max_num = sorted_nums[-1]
second_max_num = sorted_nums[-2]

for num in nums:
    if num != max_num:
        print(max_num)
    else:
        print(second_max_num)

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

max_index = A.index(max(A))
A.sort(reverse=True)

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

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

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

tmp = A[:]
tmp.sort(reverse=True)
for i in range(N):
    
    if tmp[0] == A[i]:
        print(tmp[1])
    else:
        print(tmp[0])

Solution (Python):
import copy

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

V = copy.copy(A)
V.sort(reverse=True)
for i in range(N):
    if V[0] == A[i]:
        print(V[1])
    else:
        print(V[0])

Solution (Python):
def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    
    max_A = max(A)
    B = sorted(A)
    max2_A = B[N-2]

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

if __name__=="__main__":
    main()

Solution (Python):


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

max_a = max(a)
b = a[:]
b.remove(max_a)
max_b = max(b)

if max_a == max_b:
    for i in range(n):
        print(max_a)
else:
    idx = a.index(max_a)
    for i in range(n):
        if idx == i:
            print(max_b)
        else:
            print(max_a)

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

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

Solution (Python):
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
  
maxA = sorted(A, reverse=True)
maxA1 = maxA[0]
maxA2 = maxA[1]

for i in range(N):
  if A[i] == maxA1:
    print(maxA2)
  else:
    print(maxA1)

Solution (Python):
N = int(input())
list_A = []
for _ in range(N):
    A = int(input())
    list_A.append(A)
    
sorted_list = sorted(list_A)
A = sorted_list[len(sorted_list)-1]
B = sorted_list[len(sorted_list)-2]

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

Solution (Python):
N = int(input())
list_A = []
for _ in range(N):
    A = int(input())
    list_A.append(A)
    
sorted_list = sorted(list_A, reverse=True)
A = sorted_list[0]
B = sorted_list[1]

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

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    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])

if __name__ == '__main__':
    main()

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

bi = sorted(ai)

m = max(ai)

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

Solution (Python):
import copy
n = int(input())
l=[int(input()) for x in range(n)]
ll=copy.copy(l)
ll.sort()
setl=list(set(ll))
m=max(l)
for i in range(n):
    if len(setl)==1:
        print(m)
    elif l[i]==m:
        print(ll[-2])
    else:
        print(m)

Solution (Python):
N = int(input())
a = [0]*N
for i in range(N):
  a[i] = int(input())
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 = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
for n in range(N):
    if n == 0:
        print(C[1])
    elif n == N - 1:
        print(B[N - 2])
    else:
        print(max(B[n-1], C[n+1]))

Solution (Python):
N = int(input())
A = [int(input()) for _ 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=[]

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

first=max(a)
b=sorted(a)
second = b[-2]

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

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

temp = A[A_max_primary]
A[A_max_primary] = 0
A_max_secondary = A.index(max(A))
A[A_max_primary] = temp

for i in range(N):
  if i == A_max_primary:
    print(A[A_max_secondary])
  else:
    print(A[A_max_primary])

Solution (Python):
import sys
from itertools import accumulate
input=sys.stdin.readline

def resolve():
    N=int(input().rstrip())
    A=[int(input().rstrip()) for _ in range(N)]
    
    cumsum = list(accumulate(A))
    
    Amax=0
    Amax2=0
    _A=sorted(A)
    Amax2=_A[N-2]
    Amax=_A[N-1]

    for i in range(N):
        if A[i]==Amax:
            print(Amax2)
        else:
            print(Amax)
            

if __name__ == "__main__":
    
    resolve()

Solution (Python):
n = int(input())
A = []
for i in range(1, n+1):
    A.append(int(input()))
A_srt = sorted(A)
A1, A2 = A_srt[-1], A_srt[-2]
for i in A:
    if i == A1:
        print(A2)
    else:
        print(A1)

Solution (Python):


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


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

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

for _ in range(N):
    A = int(input())
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)

list_B = sorted(list_A, reverse=True)
B = list_B[1]

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

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

Solution (Python):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
x = a.index(max(a))
a0 = sorted(a)
for i in range(n):
  if i != x:
    print(a0[n-1])
  else:
    y = a[:x] + a[x+1:]
    print(max(y))

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 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 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)]
SA = list(reversed(sorted(A)))
for a in A:
    if a == SA[0]:
        print(SA[1])
    else:
        print(SA[0])

Solution (Python):
import sys
input = sys.stdin.readline

N=int(input())
a=[0]*N

max1=[0,0]
max2=[0,0]
for i in range(N):
    a=int(input())
    if max1[0]<=a:
        max2=max1
        max1=[a,i]
    elif max2[0]<=a:
        max2=[a,i]

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

Solution (Python):
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]
    anoA = sorted(A)
    mA = max(A)

    for j in range(N):
        if mA == A[j]:
            print(anoA[-2])

        else:
            print(mA)


main()

Solution (Python):
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]
    anoA = sorted(A)
    mA = max(A)

    for j in range(N):
        if mA == A[j]:
            print(anoA[-2])

        else:
            print(mA)


main()

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

a_s=sorted(a,reverse=True)
mx=a_s[0]
for i, val in enumerate(a):
    if val!=mx:
        print(mx)
    else:
        print(a_s[1])

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

for i in nlist:
  if i == s[0]:
    print(s[1])
  else:
    print(s[0])

Solution (Python):

import math
import sys
import copy

numlist = []
for line in sys.stdin.readlines():
  numlist.append(int(line.rstrip()))
N = numlist.pop(0)

nlist = copy.deepcopy(numlist)
Amax1 = max(nlist)
nlist.remove(Amax1)
Amax2 = max(nlist)

for num in numlist:
  if num != Amax1:
    print(Amax1)
  else:
    print(Amax2)

Solution (Python):
n = int(input())
a = list(int(input()) for i in range(n))
M = max(a)

if a.count(M) > 1:
  for i in range(n):
    print(M)
elif n == 1:
  print(M)
else:
  M2 = sorted(set(a))[-2]
  for i in range(n):
    if a[i] == M:
      print(M2)
    else:
      print(M)

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 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 i in range(n)]
B=sorted(A)
if B[-1]==B[-2]:
  C=[B[-1] for i in range(n)]
  print(*C,sep='\n')
else:
  max_A=B[-1]
  max_A2=B[-2]
  for i in range(n):
    if A[i]==max_A:
      print(max_A2)
    else:
      print(max_A)

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

x = A[:]
x.sort()
Amax = x[N-1]
Amax2 = x[N-2]
print("")
for a in A:
    if a < Amax:
        print(Amax)
    elif a == Amax:
        print(Amax2)

Solution (Python):
import copy
n = int(input())
l=[int(input()) for x in range(n)]
ll=copy.copy(l)
ll.sort()
setl=list(set(l))
setl.sort()
m=max(l)

for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=ll[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)

Solution (Python):
n = int(input())
l = [int(input()) for i in range(n)]
l2 = sorted(l)
c2 = l.index(l2[-2])
c = l.index(max(l))
d = max(l)
for i in range(n):
  if i != c:
    print(d)
  else:
    print(l2[-2])

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B = A[:]
B.sort()
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=[int(input()) for i in range(n)]
m=max(a)
i=a.index(m)

for j in range(n):
    if j!=i:
       print(m)
    else:
        del a[i]
        print(max(a))

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

first = max(A)
count, index = A.count(first), A.index(first)
A.sort()
second = A[-2]

if count > 1:
    ANSWERS = [first] * n
    for answer in ANSWERS:
        print(answer)
else:
    ANSWERS = [first] * n
    ANSWERS[index] = second
    for answer in ANSWERS:
        print(answer)

Solution (Python):
N = int(input())
A = [(int(input()), i) for i in range(N)]
A.sort(key=lambda x:x[0])
idx = [0] * N
for i in range(N): idx[A[i][1]] = i

for i in range(N):
    j = idx[i]
    ans = A[-1]
    if j == N-1: ans = A[-2]
    print(ans[0])

Solution (Python):
N = int(input())
M1 = 0
M2 = 0
A_list = []
for _ in range(N):
    A = int(input())
    A_list.append(A)
    if A > M1:
        M2 = M1
        M1 = A
    elif A > M2:
        M2 = A

for a in A_list:
    if a == M1:
        print(M2)
    else:
        print(M1)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
f, s = sorted(a, reverse=True)[:2]
idx = a.index(f)
if f == s:
    for _ in range(n):
        print(f)
else:
    for i in range(n):
        if i == idx:
            print(s)
        else:
            print(f)

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

A_max = max(A)

if A.count(A_max) > 1:
    A_second_max = A_max
else:
    A_second_max = max([0 if i == A_max else i for i in A])

for j in A:
    if j == A_max:
        print(A_second_max)
    else:
        print(A_max)

Solution (Python):
n = int(input())
l = []
m1, m2 = 0, 0

for i in range(n):
    a = int(input())
    l.append(a)
    if a >= m1:
        m1, m2 = a, m1
    elif a >= m2:
        m2 = a


for e in l:
    if e != m1:
        print(m1)
    else:
        print(m2)

Solution (Python):
import sys

N = int(input())

one = (0, 0)
two = (0, 0)
for i, A in enumerate(map(int, sys.stdin.readlines())):
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)

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

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

one = (0, 0)
two = (0, 0)
for i in range(N):
    A = int(input())
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)

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

Solution (Python):
N=int(input())
A = [int(input()) for i in range(N)]
m=max(A)
m2=sorted(A)[-2]
m_i=A.index(m)

ans=[m]*N
ans[m_i]=m2

print('\n'.join(list(map(str,ans))))

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

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

ls_as = sorted(ls_a, reverse=True)
fst = ls_as[0]
snd = ls_as[1]

for i in range(n):
	if ls_a[i] != fst:
		print(fst)
	elif ls_a[i] == fst:
		print(snd)

Solution (Python):
def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    sort_A = sorted(A)
    max_A = sort_A[-1]
    max_se_A = sort_A[-2]
    for a in A:
        if a == max_A:
            print(max_se_A)
        else:
            print(max_A)
    return 0

if __name__ == '__main__':
    main()

Solution (Python):
length = int(input())
suretsu=[int(input()) for i in range(length)]
result = []
sorted_suretsu = sorted(suretsu,reverse=True)
zantei_max = sorted_suretsu[0]

for i in range(length):
    if (zantei_max == suretsu[i]):
        result.append(str(sorted_suretsu[1]))
    else:
        result.append(str(zantei_max))
print('\n'.join(result))

Solution (Python):
N = int(input())
list = [int(input()) for i in range(N)]
list_max = sorted(list)
max = max(list)
for i in range(N):
	if(list[i] == max):
		print(list_max[-2])
	else:
		print(max)

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

b=sorted(a)
for i in range(n):
    if a[i]==b[n-1]:
        ama=i

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

Solution (Python):
N = int(input().strip())
A = [int(input().strip()) 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())
a = [int(input()) for _ in range(n)]

sorted_a = sorted(a)

mx = sorted_a[-1]
next = sorted_a[-2]

for _a in a:
    if _a == mx:
        print(next)
    else:
        print(mx)

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

B = sorted(A)
max = B[-1]
for i in range(n):
    if A[i] != max:
        print(max)
    else:
        print(B[-2])

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

Solution (Python):
n = int(input())
a = []
largest = 0
second_largest = 0
for i in range(n):
    temp = int(input())
    if temp > largest:
        largest = temp
    elif largest >= temp > second_largest:
        second_largest = temp
    a.append(temp)

for i in range(n):
    if a[i] == largest:
        print(second_largest)
    else:
        print(largest)

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

sorted_a = list(sorted(a,reverse=True))

ans_a = []

for i in a:
    if i == sorted_a[0]:
        ans_a.append(sorted_a[1])
    
    else:
        ans_a.append(sorted_a[0])

for i in ans_a:
    print(i)

Solution (Python):


N = int(input())
A = []
max1 = 0
max2 = 0

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






A_sorted = sorted(A)
max1 = A_sorted[-1]
max2 = A_sorted[-2]
for a in A:
    print(max1 if a != max1 else max2)

Solution (Python):


N = int(input())
A = []
max1 = 0
max2 = 0

for _ in range(N):
    a = int(input())
    if max1 <= a:
        max2 = max1
        max1 = a
    elif max2 <= a:
        max2 = a
    A.append(a)

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

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
a = [int(input()) for i in range(n)]
b=sorted(a)
x=b[-1]
y=b[-2]
for i in range(n):
  if a[i]<x:
    print(x)
  else:
    print(y)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = tuple(map(int, [input() for _ in range(n)]))
    max_a, max_a2 = sorted(a, reverse=True)[:2]
    print('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a])))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a, max_a2 = sorted(a, reverse=True)[:2]
    print('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a])))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a2, max_a = sorted(a)[-2:]
    print('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a])))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a2, max_a = sorted(a)[-2:]
    print('\n'.join([str(max_a) if i != max_a else str(max_a2) for i in a]))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a = max(a)

    if a.count(max_a) > 1:
        print('\n'.join([str(max_a) for _ in a]))
    else:
        max_a2 = sorted(a)[-2]
        print('\n'.join([str(max_a) if i != max_a else str(max_a2) for i in a]))

if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = sorted(A)
for i in range(N):
    if A[i] != A_sorted[-1]:
        print(A_sorted[-1])
    else:
        j = len(A_sorted) - 1
        count = 0
        while A[i] == A_sorted[j] and count <= 0:
            j -= 1
            count += 1
        print(A_sorted[j])

Solution (Python):
n=int(input())
l=[]
mx=-1
s=1
for _ in range(n):
    x=int(input())
    l.append(x)
    if x==mx:
        s+=1
    elif x>mx:
        mx=x
        s=1
if s>1:
    for _ in range(n):
        print(mx)
else:
    j=l.index(mx)
    for i in range(n):
        if i!=j:
            print(mx)
        else:
            l.remove(mx)
            print(max(l))

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

max_number = max(a)
max_number2 = sorted(a)[-2]

for i in range(n):
    if a[i] == max_number:
        print(max_number2)
    else:
        print(max_number)

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)
m = B[0]
n = B[1]
ind = A.index(m)
if m != n:
    ans = "\n".join([str(m) if i != ind else str(n) for i in range(N) ])
else:
    ans = "\n".join([str(m)for _ in range(N)])
print(ans)

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

s = sorted(a)

max1 = s[-1]
max1_ind = a.index(max1)
max2 = s[-2]



for i in a:
    if i is a[max1_ind]:
        print(max2)
    else:
        print(max1)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    B = sorted(A)
    max_A = B[-1]
    submax_A = B[-2]
    for i in range(N):
        if A[i] == max_A:
            print(submax_A)
        else:
            print(max_A)
    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,*a=map(int,open(0).read().split())

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

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

aa = sorted(a)
first = aa[-1]
second = aa[-2]

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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 S(): return input()
     
def main():
    N = I()
    maxA = -1
    max2A = -1
    max_i = -1
    for i in range(N):
        a = I()
        if a > maxA:
            max2A = maxA
            maxA = a
            max_i = i
        else:
            max2A = max(max2A, a)
    for i in range(N):
        if i != max_i:
            print(maxA)
        else:
            print(max2A)

main()

Solution (Python):


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

Amax=max(A)
indmax=[i for i,v in enumerate(A) if v==Amax]

if len(indmax)>1:
    for _ in range(N):
        print(Amax)
else:
    Amax2=sorted(A)[-2]
    for i in range(N):
        if i!=indmax[0]:
            print(Amax)
        else:
            print(Amax2)

Solution (Python):


N=int(input())
A=[0]*N
for i in range(N):
    A[i]=int(input())
m=sorted(A)[N-1]
m_=A.index(m)
m2=sorted(A)[N-2]
m2_=A.index(m2)
for i in range(N):
    if i!=m_:
        print(m)
    else:
        print(m2)

Solution (Python):
import sys
a = int(input())
a_list = []
for i in range(a):
    a_list.append(int(input()))
max_num = max(a_list)
if a_list.count(max_num) != 1:
    for i in range(a):
        print(max_num)
else:
    sec_num = sorted(a_list)[-2]
    for i in a_list:
        if i == max_num:
            print(sec_num)
        else:
            print(max_num)

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

Solution (Python):
from __future__ import print_function

import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return















































def main():
    
    
    
    n = int(input().strip())
    max0=0;max1=0;i0=sys.maxsize;i1=sys.maxsize               
    for i in range(n):
        n_temp=int(input())
        if n_temp >= max0 :
            max1=max0;i1=i0 
            max0=n_temp;i0=i
        elif max0>n_temp and n_temp>max1:
            max1=n_temp;i1=i
        else: 
            pass
    for i in range(n):
        if i==i0:
            print(max1)
        else:
            print(max0)
    return

if __name__ == '__main__':
    main()

    '''
    


    '''

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
B=sorted(A)[::-1]
x=B[0] 
y=B[1]
if x==y:
  for i in range(N):
    print(x)
else:
  z=A.index(x)
  for i in range(z):
    print(x)
  print(y)
  for i in range(N-z-1):
    print(x)

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

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

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

maxa = max(a)
maxcnt = 0
maxidx = 0

for i in range(n):
    if maxcnt == 0:
        maxidx = i
    if a[i] == maxa:
        maxcnt += 1
    


for i in range(n):
    if maxcnt == 1 and i == maxidx:
        a[maxidx]=0
        print(max(a))
    else:
        print(maxa)