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
n= int(input())
a =[int(input()) for i in range (n)]
b=max(a)
c=sorted(a)[-2]
for i in (a):
    if i == b:
        print(c)
    else:
        print(b)

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

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

a = [int(input()) for l in range(n)]
b = max(a)
c = sorted(a)[-2]
for i in (a):
	if not i==b:
		print(b)
	else:
		print(c)

Solution (Python):
import copy

n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(copy.copy(a))
ma = b[-1]
mi = b[-2]
for i in range(n):
  if a[i] == ma:
    print(mi)
  else:
    print(ma)

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

A_copy = A[:]
A_copy.sort()
A_max = A_copy[len(A_copy)-1]
A_second = A_copy[len(A_copy)-2]

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

Solution (Python):

import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)


def solve(N: int, A: "List[int]"):
    if N == 1:
        print(0)
    else:
        m1 = max(A)
        max_idx = np.where(np.array(A) == max(A))
        if len(max_idx[0]) > 1:
            for i in range(N):
                print(m1)
        else:
            m2 = sorted(set(A))[-2]
            max_idx = np.argmax(np.array(A))
            for i in range(N):
                if i == max_idx:
                    print(m2)
                else:
                    print(m1)
    return




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


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = []
max_num = -1
for i in range(n):
    ipt = int(input())
    if ipt > max_num:
        max_num = max(ipt, max_num)
        idx = i
    a.append(ipt)
a = sorted(a)
if a[-1] == a[-2]:
    for i in range(n):
        print(max_num)
else:
    for i in range(n):
        if i == idx:
            print(a[-2])
        else:
            print(max_num)

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

a = []

top_num = 0
second_num = 0

for _ in range(n):
    a_i = int(input())
    if a_i >= top_num:
        second_num = top_num
        top_num = a_i
    else:
        second_num = max(a_i, second_num)
    a.append(a_i)

for a_i in a:
    if a_i == top_num:
        print(second_num)
    else:
        print(top_num)

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

A_max = A_copy[len(A_copy)-1]
A_second = A_copy[len(A_copy)-2]
for i in range(N):
    if A[i] != A_max:
        print(A_max)
    else:
        print(A_second)

Solution (Python):
N = int(input())
A = list(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 = A[:]
B.sort()

a_max = B[len(B)-1]
a_next = B[len(B)-2]

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

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

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

a_L = []
for val in range(n):
    a_L.append(int(input()))

s_L = sorted(a_L)

for val in a_L:
    if s_L[-1] != val:
        print(s_L[-1])
    else:
        print(s_L[-2])

Solution (Python):
def slove():
    import sys
    import copy
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = copy.deepcopy(a)
    b.sort(reverse=True)
    for v in a:
        if v == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    slove()

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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

B = list(reversed(sorted(A)))

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)]
first = sorted(A)[-1]
second = sorted(A)[-2]
if first == second:
    for i in range(N):
        print(first)
else:
    idx = A.index(first)
    for i in range(N):
        if i == idx:
            print(second)
        else:
            print(first)

Solution (Python):
import heapq
from collections import defaultdict

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

dd = defaultdict(int)
for key in a:
    dd[key] += 1

heapq.heapify(minus_a)
max1=-heapq.heappop(minus_a)
max2=-heapq.heappop(minus_a)

for item in a:
  if item!=max1:
    print(max1)
  elif dd[max1]==1:
    print(max2)
  else:
    print(max1)

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

Solution (Python):
import copy
N = int(input())
A_list = [int(input()) for _ in range(N)]
sort_list = copy.copy(A_list)
sort_list.sort()
for i in range(N):
    if A_list[i] == sort_list[-1]:
        print(sort_list[-2])
    else:
        print(sort_list[-1])

Solution (Python):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Solution (Python):
n=int(input())
l1=[int(input()) for i in range(n)]
l2=sorted(l1)
max1=l2[-1]
max2=l2[-2]
for i in l1:
  if i == max1:
    print(max2)
  else:
    print(max1)

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

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

biggest_num = 0
secondly_biggest_num=0
for i in range(n):
    a = int(input())
    suretsu0.append(a)

suretsu = [x for x in suretsu0]
suretsu.sort()


biggest_num = suretsu[-1]
secondly_biggest_num=suretsu[-2]




for ele in suretsu0:
    if ele==biggest_num:
        print(secondly_biggest_num)
    else:
        print(biggest_num)

Solution (Python):
N=int(input())
A=[]
B=[]
for i in range(N):
  n=int(input())
  A.append(n)
  B.append(n)
B.sort()
for i in range(N):
  print(B[-1] if A[i]!=B[-1] else B[-2])

Solution (Python):

import math




def main():
    n = int(input())
    lista = []
    for i in range(0, n):
        lista.append(int(input()))
    maxim1 = -999999
    maxim2 = -9999999
    for element in lista:
        if element > maxim1:
            maxim2 = maxim1
            maxim1 = element
        elif element <= maxim1 and element > maxim2:
            maxim2 = element
    
    for element in lista:
        if element == maxim1:
            print(maxim2)
        else:
            print(maxim1)



if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
L = IR(n)
sorted_L = sorted(L)
k1, k2 = sorted_L[-1], sorted_L[-2]


for i in range(n):
    if L[i] == k1:
        print(k2)
    else:
        print(k1)

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

A_sorted = sorted(A)

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

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

sorted_A = sorted(A)
gt1 = sorted_A[-1]
gt2 = sorted_A[-2]

for a in A:
    if a == gt1:
        print(gt2)
    else:
        print(gt1)

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

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

new = sorted(L)


ans = 0
for i in range(N):
    if L[i] != new[-1]:
        ans = new[-1]
    else:
        ans = new[-2]
    print(ans)

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

b = sorted(a)
max_ind = a.index(b[n - 1])

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

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

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

maxv = max(A)
max_id = A.index(maxv)
second = max(A[:max_id] + A[max_id+1:])

for i in range(N):
  if i == max_id:
    print(second)
  else:
    print(maxv)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
 
A2 = sorted(A)[::-1]
for a in A:
  if a == A2[0]:
    print(A2[1])
  else:
    print(A2[0])

Solution (Python):
import copy

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

tmp = copy.deepcopy(A)
tmp.sort(reverse=True)

M = max(A)
if A.count(M) >= 2:
    for _ in range(n):
        print(M)
else:
    for a in A:
        if a == M:
            print(tmp[1])
        else:
            print(M)

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

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)]
MAX1=max(A)
copyA=A.copy()
copyA.remove(MAX1)
MAX2=max(copyA)
for i in A:
  if (i==MAX1):
    print(MAX2)
  else:
    print(MAX1)

Solution (Python):


N = int(input())
A_max = 0
A_max_s = 0
flag = 0
A = []

for i in range(N):
    a = int(input())
    A.append(a)
    if a > A_max:
        A_max_s = A_max
        A_max = a
        ind_max = i
        flag = 0
    elif A_max_s < a < A_max:
        A_max_s = a
    elif a == A_max:
        flag += 1
        
if flag >= 1:
    for i in range(N):
        print(A_max)
elif flag == 0:
    for i in range(N):
        if i != ind_max:
            print(A_max)
        else:
            print(A_max_s)

Solution (Python):
from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    heappush(hq, -A[i])
max1 = -heappop(hq)
max2 = -heappop(hq)
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\n")

Solution (Python):
N = int(input())
A = []
for c in range(N):
  A.append(int(input()))
m, i = 0, -1
for j in range(len(A)):
  if A[j] > m:
    m, i = A[j], j
B = A[:]
B.remove(m)
M = max(B)
for k in range(len(A)):
  if k != i:
    A[k] = m
  else:
    A[k] = M
for l in range(len(A)):
  print(A[l])

Solution (Python):
n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind = -1
    elif m < a:
        k, m = m, a
        ind = i
    elif k < a:
        k = a
if ind == -1:
    print("\n".join(map(str, [m for i in range(n)])))
else:
    print("\n".join(map(str, [k if i == ind else m for i in range(n)])))

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

if A.count(base_ans) >= 2:
    for i in range(N):
        print(base_ans)
else:
    ans_list=[base_ans]*N
    A.remove(base_ans)
    ans_min = max(A)
    ans_list[index]=ans_min
    for i in range(N):
        print(ans_list[i])

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

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
c=0
m=0
for i in range(N):
  if m<A[i]:
    m=A[i]
    d=i
B=A
B[d]=0
for i in range(N):
  if i==d:
    print(max(B))
  else:
    print(m)

Solution (Python):
import copy 

n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
count_max = a.count(max_a)

if count_max > 1:
    for i in range(n):
        print(max_a)
else:
    for i in range(n):
        if a[i] != max_a:
            print(max_a)
        else:
            b = copy.deepcopy(a) 
            b.pop(b.index(max_a))
            print(max(b))

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

A_sort = sorted(A)
first = A_sort[-1]
second = A_sort[-2]
if first == second:
    for n in range(N):
        print(first)
else:
    for i in range(N):
        if A[i] == first:
            print(second)
        else:
            print(first)

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

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if a.count(maxa)>=2:
    for i in range(n):
        print(maxa)
else:
    maxi=a.index(maxa)
    a.remove(maxa)
    maxa2=max(a)
    for i in range(n):
        if i==maxi:
            print(maxa2)
        else:
            print(maxa)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = list(int(input()) for i in range(N))
B = sorted(A)
print(*((B[N-2] if A[i]==B[N-1] else B[N-1]) for i in range(N)), sep="\n")

Solution (Python):


n = int(input())
l = [int(input()) for _ in range(n)]
m = max(l)
n = sorted(l)[-2]
for i in l:
    if i != m:
        print(m)
    else:
        print(n)

Solution (Python):

def main(): 

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

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

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




if __name__ == "__main__":
    main()

Solution (Python):

def main(): 

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

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

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




if __name__ == "__main__":
    main()

Solution (Python):
def test():
    n = int(input())
    s = 0; t = 0; index_ = 0
    for i in range(n):
        a = int(input())
        if s < a:
            index_ = i
            s = a
        elif t < a and a <= s:
            t = a
    for i in range(n):
        if index_ == i:
            print(t)
        else:
            print(s)


if __name__ == "__main__":
    test()

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

Solution (Python):
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


N=int(input())
l=[]
for i in range(N):
	l.append(int(input()))
	
l_sort=sorted(l)

max=l_sort[-1]
sub_max=l_sort[-2]

for i in l:
	if i == max:
		print(sub_max)
	else:
		print(max)

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

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

sorted_A = sorted(A)
max_a = sorted_A[-1]
second_max = sorted_A[-2]

for i in A:
  if i == max_a:
    print(second_max)
  else:
    print(max_a)

Solution (Python):
import copy
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
cnt = 0
for i in range(N):
    if A[i] == Max:
        cnt += 1
for i in range(N):
    if A[i] == Max:
        if cnt > 1:
            print(Max)
        else:
            print(set_A[1])
    else:
        print(Max)

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

max = 0
sub_max = 0
for x in A:
    if max <= x:
        sub_max = max
        max = x
    elif sub_max <= x:
        sub_max = x

for x in A:
    if x == max:
        print(sub_max)
    else:
        print(max)

Solution (Python):

import copy
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
orig_a = copy.copy(a)
a.sort(reverse=True)
max_a = a[0]
semi_max_a = a[1]

if max_a == semi_max_a:
    for i in range(n):
        print(semi_max_a)
else:
    for i in range(n):
        if orig_a[i] == max_a:
            print(semi_max_a)
        else:
            print(max_a)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
max_num = max(A)
temp = A.copy()
temp.remove(max_num)
max_num2 = max(temp)

for a in A:
    if a == max_num:
        print(max_num2)
    else:
        print(max_num)

Solution (Python):


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

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

Solution (Python):
while True:
    try:
        N = int(input())
        A = [int(input()) for _ in range(N)]
        B = sorted(A)
        max1 = B[-1]
        max2 = B[-2]
        for _ in A:
            if _ == max1:
                print(max2)
            else:
                print(max1)
    except:
        break

Solution (Python):
N = raw_input()
counter = 0
num_array = []
max_data = 0
second_max = 0
while counter < int(N):
  num_array.append(int(raw_input()))
  if(num_array[counter] > max_data):
    max_data = num_array[counter]
  elif(num_array[counter] > second_max):
    second_max = num_array[counter]
  counter += 1
counter = 0  
while counter < int(N):
  if(num_array[counter] != max_data):
    print max_data
  else:
    print second_max
  counter += 1

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

for j in a:
    if j==sort_a[0]:
        print(sort_a[1])
    else:
        print(sort_a[0])

Solution (Python):
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    AS = [int(input()) for _ in range(N)]
    AS_dup = AS[:]
    AS.sort()
    for i in range(N):
        if AS_dup[i] == AS[-1]:
            print(AS[-2])
        else:
            print(AS[-1])


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
b=sorted(a)
ans=[b[-1]]*n
ans[a.index(b[-1])]=b[-2]
print(*ans,sep="\n")

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

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

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A,reverse=True)
if B[0] == B[1]:
    for i in range(N):
        print(B[0])
else:
    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)]
s = max(a)
if a.count(s) >= 2:
  for i in range(n):  
    print(s)
else:
  for i in range(n):
    if a[i] == s:
      l = a.copy()
      l.sort()
      print(l[-2])
    else:
      print(s)

Solution (Python):
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
a_sorted = sorted(a)
max_a = a_sorted.pop()
second_a = a_sorted.pop()
if max_a == second_a:
    for _ in range(N):
        print(max_a)
else:
    idx = 0
    while idx < N:
        if a[idx] == max_a:
            print(second_a)
        else:
            print(max_a)
        idx += 1

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

B = [A[i] for i in range(N)]
  
m1 = max(A)
idx = A.index(m1)
B.pop(idx)
m2 = max(B)

for i in range(N):
  if i == idx:
    print(m2)
  else:
    print(m1)

Solution (Python):
n = int(input())
seq = [int(input()) for i in range(n)]
s_seq = sorted(seq, reverse = True)

for x in seq:
    print(s_seq[s_seq[0] == x])

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

data_set = sorted(data, reverse=True)

max1, max2 = data_set[0], data_set[1]

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = sorted({i: int(input()) for i in range(N)}.items(), key=lambda x: x[1])
    for index in range(N):
        if not A[-1][0] == index:
            print(A[-1][1])
        else:
            print(A[-2][1])

Solution (Python):
import sys
input = sys.stdin.readline
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[-1])
    else:
        print(b[-2])

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
m1,m2 = sorted(A)[-2:]

for i in A:
    print(m1 if i==m2 else m2)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
m1,m2,*_ = sorted(A)[::-1]

for i in A:
    if m1 == i:
        print(m2)
    else:
        print(m1)

Solution (Python):
n=int(input())
A=[int(input()) for _ in range(n)]
m1, m2=0, 0
for a in A:
  if a >= m1:
    m1, m2 = a, m1
  elif a >= m2:
    m2=a
for a in A:
  if a==m1:
    print(m2)
  else:
    print(m1)

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

a1=max(a)
b=sorted(a)
a2=b[N-2]

for j in range(N):
  if a[j] != a1:
    print(a1)
  else:
    print(a2)

Solution (Python):
N = int(input())
A =[]
ma = 0
se = 0
for i in range(N):
  a = int(input())
  A.append(a)
  ma = max(ma,a)
b = sorted(A)
ma = b[N-1]
se = b[N-2]
for i in range(N):
  if A[i]==ma:
    print(se)
  else:
    print(ma)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    x = sorted(A)
    for i in A:
        if(i == x[-1]):
            print(x[-2])
        else:
            print(x[-1])
            
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
lis=list(int(input()) for _ in range(n))
lis2=lis
lis2=sorted(lis2)
MAX=lis2[-1]
second=lis2[-2]
if lis.count(MAX) ==1:
    lis3=[MAX for _ in range(n)]
    lis3[lis.index(MAX)]=second
    for i in range(n):
        print(lis3[i])
        
else:
    for _ in range(n):
        print(MAX)

Solution (Python):
import heapq as hq
n = int(input())
arr = []
stack = []
for i in range(n):
    arr.append(int(input()))
    hq.heappush(stack, -arr[-1])

first = -hq.heappop(stack)
second = - hq.heappop(stack)

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

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

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

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

lis = sorted(li)
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-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())

idx_1st=1
val_1st=1
idx_2nd=0
val_2nd=0

for i in range(N):
  Ai = int(input())
  if Ai>=val_1st:
    idx_2nd=idx_1st
    val_2nd=val_1st
    
    idx_1st=i
    val_1st=Ai
    
  elif Ai<val_1st:
    if Ai>val_2nd:
      idx_2nd=i
      val_2nd=Ai
  else:
    raise ValueError

for i in range(N):
  if i!=idx_1st:
    print(val_1st)
  elif i==idx_1st:
    print(val_2nd)
  else:
    raise ValueError

Solution (Python):
n = int(input())
a = [int(input()) for x in range(n)]
b = sorted(a[::])
a_1, a_2 = b[-1], b[-2]
c = a.count(a_1)

for i in a:
  if c == 1 and i == a_1:
    print(a_2)
  else:
    print(a_1)

Solution (Python):


n = int(input())

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

a.sort(reverse=True)

for x in a_copy:
    if x == a[0]:
        print(a[1])
    else:
        print(a[0])

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a, reverse=True)
    for i in a:
        if i == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    slove()

Solution (Python):
n, *a = map(int, open(0).read().split())
a2 = sorted(a)[-2:]
for i in range(n):
    if a[i]==a2[1]:
        print(a2[0])
    else:
        print(a2[1])

Solution (Python):
import numpy as np
ls = []
n = int(input())
for i in range(n):
    ls.append(int(input()))
ls = np.array(ls)
maxindex1 = np.argmax(ls)
for j in range(n):
    if j != maxindex1:
        print(ls[maxindex1])
    else:
        tmp = ls[maxindex1]
        ls[maxindex1] = 0 
        maxindex2 = np.argmax(ls)
        print(ls[maxindex2])
        ls[maxindex1] = tmp

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

sorted_a = sorted(a)
a_first = sorted_a[-1]
a_second = sorted_a[-2]

for i in range(n):
    if a[i] == a_first:
        print(a_second)
    else:
        print(a_first)

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


first_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for i in range(N):
    if (A[i]== first_A):
        print(second_A)
    else:
        print(first_A)

Solution (Python):
N = int(input())
A = [0] * N
for i in range(N):
  A[i] = int(input())
  
A_Max = sorted(A)[-1]
A_2nd = sorted(A)[-2]

for i in range(N):
  if A[i] == A_Max:
    print(A_2nd)
  else:
    print(A_Max)

Solution (Python):
n = int(input())
a1 = [int(input()) for i in range(n)]
a2 = sorted(a1, reverse=True)

for v1 in a1:
    count = 0
    for v2 in a2:
        if v1 == v2 and count == 0:
            count += 1
        else:
            print(v2)
            break

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

Solution (Python):


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

B = sorted(A, reverse=True)
m1 = B[0]
m2 = B[1]

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

"""

B = copy.copy(A) 
for i in range(N):
    A[i] = 0
    print(max(A))
    A[i] = B[i]
"""

Solution (Python):
a=int(input())
b=[int(input()) for i in range(a)]
sr=list(reversed(sorted(b)))
if sr[1]==sr[0]:
  for i in range(a):
    print(sr[0])
else:
  for i in b:
    if i==sr[0]:
      print(sr[1])
    else:
      print(sr[0])

Solution (Python):
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    nums = [int(input()) for _ in range(N)]
    a = deepcopy(nums)
    a.sort(reverse=True)

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


if __name__ == '__main__':
    main()

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

Solution (Python):
import heapq

n = int(input())


arr = [0]*n

pq = []
for i in range(n):
	arr[i] = int(input())
	heapq.heappush(pq, (-arr[i], i))
heapq.heapify(pq)
lg = heapq.heappop(pq)
slg = heapq.heappop(pq)
lg, slg = lg[1], slg[1]

for i in range(n):
	if i==lg:
		print(arr[slg])
	else:
		print(arr[lg])

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

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

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

copy_a = copy.deepcopy(a)
max_num = max(a)
a.remove(max_num)
second_num = max(a)

for i in range(n):
  if copy_a[i] >= max_num:
    print(second_num)
  else:
    print(max_num)

Solution (Python):

n = int(input())

arr = [0]*n

for i in range(n):
	arr[i] = (int(input()), i)

sorted_arr = sorted(arr, reverse=True)
lg, slg = sorted_arr[0][1], sorted_arr[1][1]
for i in range(n):
	if i==lg:
		print(arr[slg][0])
	else:
		print(arr[lg][0])

Solution (Python):

N=int(input())
B=0
b=0
C=0
for i in range(N):
    A=int(input())
    if B<A:
        B=A
        b=i
    elif C<A:
        C=A
for i in range(N):
    if b==i:
        print(C)
    else:
        print(B)

Solution (Python):

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

s_la = sorted(la, reverse=True)

for a in la:
	if a == s_la[0]:
		print(s_la[1])
	else:
		print(s_la[0])

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

mi = li.index(max(li))
m = max(li)

for a, b in enumerate(li):
  if a != mi:
    print(m)
  else:
    print(max(li[a+1:]+li[:a]))