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

Solution (Python):
n = int(input())
a = list(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):
import heapq

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

r, s = heapq.nlargest(2, lis)

for x in lis:
    if x == r:
        print(s)
    else:
        print(r)

Solution (Python):
import heapq

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

r, s = heapq.nlargest(2, lis)

if lis.count(r) == 1:
    for x in lis:
        if x == r:
            print(s)
        else:
            print(r)

else:
    for _ in range(n):
        print(r)

Solution (Python):
N = int(raw_input())
A = []
for i in range(0,N):
  A.append(int(raw_input()))
A = list(enumerate(A))
A = sorted(A, key=lambda x: x[1])
max_A = A[N-1][1]
second_max_A = A[N-2][1]
A = sorted(A,key=lambda x: x[0])
for i in range(0,N):
  if A[i][1] == max_A:
    print second_max_A
  else:
    print max_A

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

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

Solution (Python):
import copy
N = int(input())
A = [int(input()) for _ in range(N)]
AA = sorted(copy.deepcopy(A))
MAX = A.index(AA[-1])
for i in range(N):
  if i == MAX:
    print(AA[-2])
  else:
    print(AA[-1])

Solution (Python):
n,*a=map(int,open(0))
b=sorted(a)
for i in range(n):
    print([b[-2],b[-1]][a[i]<b[-1]])

Solution (Python):
n,*a=map(int,open(0))
b=sorted(a)
for i in range(n):
    print([b[-1],b[-2]][a[i]==b[-1]])

Solution (Python):
n,*a=map(int,open(0))
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 = []
for i in range(n):
  a.append(int(input()))
b = sorted(a,reverse=True)
first = b[0]
second = b[1]
for i in range(n):
  if a[i]==first:
    print(second)
  else:
    print(first)

Solution (Python):
def main():

    A = [int(i) for i in open(0).read().split()[1:]]
    tmp = A[:]
    tmp.sort()
    first = tmp[-1]
    second = tmp[-2]
    print("\n".join(str(first) if a != first else str(second) for a in A))
    return


main()

Solution (Python):
def main():

    A = [int(i) for i in open(0).read().split()[1:]]
    tmp = sorted(A[:])
    print("\n".join(str(tmp[-1]) if a != tmp[-1] else str(tmp[-2]) for a in A))
    return


main()

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

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








sorted_A = sorted(A, reverse=True)
max_val = sorted_A[0]
second_val = sorted_A[1]

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

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

tmp = a[:]
max1_val = max(tmp)
max1_idx = tmp.index(max1_val)
del tmp[max1_idx]
max2_val = max(tmp)

for i in range(n):
    if i != max1_idx:
        print(max1_val)
    else:
        print(max2_val)

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

sort_A = list(set(A))
A_max = sort_A[-1]
n_A_max = A.count(A_max)

if n_A_max == 1:
    A_second_max = sort_A[-2]

if n_A_max >= 2:
    for idx in range(N):
        print(A_max)
else:
    for idx in range(N):
        print(A_second_max if A[idx] == A_max else A_max)

Solution (Python):
from copy import deepcopy
n,*a=map(int,open(0).read().split())
b=deepcopy(a)
b.sort()
c=b[-1]
for i in a:
    if i==b[-1]:
        print(b[-2])
    else:
        print(c)

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

max_A = max(A)
next_A = sorted(A, reverse=True)[1]
for i in range(N):
    if A[i] != max_A:
        print(max_A)
    else:
        print(next_A)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a,reverse=1)
for i in a:
    if 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)

m1=B[0]
m2=B[1]

for j in A:
    if j == B[0]:
        print(B[1])
    else:
        print(B[0])

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())

max_num = 0
max_index = 0
second_num = 0
for i in range(N):
    num = int(input())
    if num >= max_num:
        if second_num < 1:
            max_num = num
            second_num = 1
        else:
            second_num, max_num = max_num, num
        max_index = i
    elif num > second_num:
        second_num = num
for i in range(N):
    if max_index == i:
        print(second_num)
    else:
        print(max_num)

Solution (Python):
N = int(input())
A = []
largest = -1
second_largest = -1
more_than_one_largetst = False

for i in range(N):
  a = int(input())
  A.append(a)
  if largest == a:
    more_than_one_largest = True
  else:
    if largest < a:
      second_largest = largest
      largest = a
      more_than_one_largest = False
    else:
      if second_largest < a:
        second_largest = a
      else:
        pass

for a in A:
  if a != largest:
    print(largest)
  else:
    if more_than_one_largest:
      print(largest)
    else:
      print(second_largest)

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

a_sorted = sorted(a, reverse=True)
for x in a:
  if x == a_sorted[0]:
    print(a_sorted[1])
  else:
    print(a_sorted[0])

Solution (Python):
def main():

    A = [int(i) for i in open(0).read().split()[1:]]
    tmp = A[:]
    tmp.sort()
    first = tmp[-1]
    second = tmp[-2]
    print("\n".join(str(first) if not a == first else str(second) for a in A))
    return


main()

Solution (Python):
from heapq import *

N=int(input())
A=[int(input()) for i in range(N)]
h=[]
for i in A:
    heappush(h, -i)
maxh = -heappop(h)
secondh = -heappop(h)
for i in A:
    print(maxh if i != maxh else secondh)

Solution (Python):



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

l_s = sorted(l)

for i in l:
    if i != l_s[-1]:
        print(l_s[-1])
    else:
        print(l_s[-2])

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


def main():
    n = int(input())
    A = [[int(input()), i] for i in range(n)]
    B = list(reversed(sorted(A)))
    a_1 = B[0][0]
    m = B[0][1]
    a_2 = B[1][0]

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [(int(input()), i) for i in range(N)]
A.sort()
x1, i1 = A[-1]
x2, i2 = A[-2]

for i in range(N):
    if i == i1:
        print(x2)
    else:
        print(x1)

Solution (Python):
n=int(input())
l=[int(input()) for _ in range(n)]
l2=list()
l2=sorted(l,reverse=True)
m1=l2[0]
m2=l2[1]
ansl=[m1 for i in range(n)]
if m1!=m2:
    for i in range(n):
        if l[i]==m1:
            ansl[i]=m2
            break
for j in range(n):
    print(ansl[j])

Solution (Python):
n = input()
a = [input() for _ in xrange(n)]
ans = max(a)
i = a.index(ans)
ans2 = max(a[:i] + a[i + 1:])
for i in xrange(n):
  if a[i] != ans:
    print ans
  else:
    print ans2

Solution (Python):
N = int(input())
A = list(int(input()) for _ in range(N))
m = max(A)

A_sorted = sorted(A)
for x in A:
  if x < m:
    print(m)
  else:
    print(A_sorted[-2])

Solution (Python):
n = int(input())
mv1 = 0
mi1 = 0
mv2 = 0
for i in range(n):
    tmp = int(input())
    if tmp > mv1:
        mv1 = tmp
        mi1 = i
    elif tmp > mv2:
        mv2 = tmp

for i in range(n):
    if i != mi1:
        print(mv1)
    else:
        print(mv2)

Solution (Python):
n = int(input())
mv = 0
mi = 0
d = []
for i in range(n):
    tmp = int(input())
    if tmp > mv:
        mv = tmp
        mi = i
    else:
        d.append(tmp)

for i in range(n):
    if i == mi:
        print(max(d))
    else:
        print(mv)

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

Solution (Python):
N = int(input())
max = [0, 0] 
maxIndex = -1

for i in range(N):
  cur = int(input())
  if(max[0] <= cur):
    max[0] = cur
    if(max[1] < max[0]):
      max[1], max[0] = max[0], max[1]
      maxIndex = i

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

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

Solution (Python):
N = int(input())
A = list(int(input()) for _ in range(N))
m = max(A)

A_sorted = sorted(A)

for i in range(N):
    v = A[i]
    if v < m:
        print(m)
    else:
        print(A_sorted[-2])

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

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

Solution (Python):


import heapq

N=int(input())
l=[]

for i in range(N):
    l.append(int(input()))

ll=sorted(l)

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

Solution (Python):
def main():

    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    prefix = [0]
    suffix = [0]
    for i in range(N):
        prefix.append(max(prefix[-1], A[i]))
        suffix.append(max(suffix[-1], A[N-i-1]))
    suffix.sort(reverse = True)

    for i in range(N):
        ans = max(prefix[i], suffix[i+1])
        print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
m = sorted(l)
max = m[-1][0]
sub_max = m[-2][0]
for i in range(n):
    if l[i][0] == max:
        print(sub_max)
    else:
        print(max)

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

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

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

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

A = sorted(A, key=lambda x:x[0], reverse=True)
for i in range(N):
    if A[0][1] == i:
        print(A[1][0])
    else:
        print(A[0][0])

Solution (Python):
def main():

    n,*a = map(int,open(0).read().split())
    b = sorted(a)
    max = b[-1]
    maxs= b[-2]

    for i in range(n):
        if a[i] == max:
            print(maxs)
        else:
            print(max)
    return()

if __name__=='__main__':
    main()

Solution (Python):
n,*a = map(int,open(0).read().split())
b = sorted(a)
max = b[-1]
maxs= b[-2]

for i in range(n):
    if a[i] == max:
        print(maxs)
    else:
        print(max)

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

max_A = max(A)
max_A_count = A.count(max_A)

set_A = set(A)
len_set_A = len(set_A)

if(len_set_A > 1):
    set_A.remove(max_A)

max_set_A = max(set_A)

for i in range(N):
    if(A[i] < max_A):
        print(max_A)
    elif A[i] == max_A and max_A_count > 1:
        print(max_A)
    else:
        print(max_set_A)

Solution (Python):
def main():
    n, *a = map(int, open(0).read().split())

    sorted_a  = sorted(a)
    max_a = sorted_a[-1]
    next_max_a = sorted_a[-2]
    for cur_a in a:
        if cur_a == max_a:
            print(next_max_a)
        else:
            print(max_a)
    return()

if __name__ == '__main__':
    main()

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

m = heapq.nlargest(2,a)

if m[0]==m[1]:
    for i in range(n):
        print(m[0])

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

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


m1 = max(a)


m2 = sorted(a)[n-2]

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

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

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

_A = sorted(A)

list_max = _A[N-1]
list_second_max = _A[N-2]

import copy

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

Solution (Python):

n=int(input())
s=[int(input()) for i in range(n)]
a=sorted(s)
max_=a[-1]
max_2=a[-2]

for i in range(n):
    if s[i]==max_:
        print(max_2)
    else:
        print(max_)

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

Solution (Python):



nn = int(input())
n = []
for i in range(nn):
    n.append(int(input()))
a = ia = b = ib = c = 0
for i in n:
    if a<i: a = i; ia = c
    elif b<i: b = i; ib = c
    c += 1
for i in range(len(n)):
    if i == ia: print(b)
    else: print(a)

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

for i in A:
		if i != f:
				print(f)
		else:
				print(s)

Solution (Python):
N = int(input())
max_val_1 = 0
max_val_2 = 0
for i in range(N):
    A = int(input())
    if max_val_1 < A:
        max_val_2 = max_val_1
        max_val_1 = A
        max_num = i
    elif max_val_2 < A:
        max_val_2 = A
        
for i in range(N):
    if i == max_num:
        print(max_val_2)
    else:
        print(max_val_1)

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

Solution (Python):
import copy
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)]
A_sort = sorted(A)
for i in range(N) :
    if A[i] == A_sort[-1] :
        print(A_sort[-2])
    else :
        print(A_sort[-1])

Solution (Python):
n = int(input())
a = [0 for _ in range(n)]
max_a = 0
second_a = 0
for i in range(n):
    a[i] = int(input())
    if a[i] > max_a:
        max_a = a[i]
    elif a[i] > second_a:
        second_a = a[i]
for i in range(n):
    if a[i] == max_a:
        print(second_a)
    else:
        print(max_a)

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

Solution (Python):
n = int(input())
a = []
for i in range(n):
    value = int(input())
    a.append(value)
temp = sorted(a)
max_a = temp[-1]
if len(a)>=2:
    second_a = temp[-2]
for i in range(n):
    if a[i] == max_a:
        check = i
        break
for i in range(n):
    if i == check:
        print(second_a)
    else:
        print(max_a)

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

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

m1, m2 = 0, 0
A = [0] * N

for i in range(N):
  a = int(input())
  A[i] = a
  if a >= m2:
    if a >= m1:
      m2 = m1
      m1 = a
    
    else:
      m2 = a

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

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

if N == 2:
    print("\n".join(map(str, A[::-1])))
else:
    a = sorted(A)
    maxv1 = a[-1]
    maxi1 = A.index(maxv1)
    maxv2 = a[-2]

    print("\n".join(map(str, [maxv1 if i != maxi1 else maxv2 for i in range(N)])))

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

if N == 2:
    print("\n".join(map(str, A[::-1])))
else:
    a = sorted(A)
    maxv1 = a[-1]
    maxi1 = A.index(maxv1)
    maxv2 = a[-2]

    for i in range(N):
        if i == maxi1:
            print(maxv2)        
        else:
            print(maxv1)

Solution (Python):
import copy
N = int(input())
A = [int(input()) for _ in range(N)]
a_copy = copy.deepcopy(A)
a_max = max(a_copy)
a_copy.remove(a_max)
b_max = max(a_copy)

for i in A:
    if i == a_max:
        print(b_max)
    else:
        print(a_max)

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

Solution (Python):
N  = int(input())
max = 1
max2nd = 0
max_index = 0

for index in range(N):
    a = int(input())
    if a >= max:
        max2nd = max
        max = a
        max_index = index
    elif a >= max2nd:
        max2nd = a

for index in range(N):
    if not index == max_index:
        print(max)
    else:
        print(max2nd)

Solution (Python):

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


max1 = sorted(A, reverse=True)
max2 = max1[0]

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

    else:
        print(max2)

Solution (Python):
n = int(input())
li_a = list()
d_a = dict()

for _ in range(n):
    wk = int(input())
    li_a.append(wk)

    get = d_a.get(wk, 0)
    d_a[wk] = get + 1

li_top2 = sorted(d_a.keys(), reverse=True)[:2]

for i in range(n):
    val = li_a[i]

    if val not in li_top2:
        print(li_top2[0])
    else:
        if val == li_top2[0] and d_a.get(val, 0) == 1:
            print(li_top2[1])
        else:
            print(li_top2[0])

Solution (Python):
SEQUENCE_LEN_MIN = 2
SEQUENCE_LEN_MAX = 200000
NUMERIC_MIN = 1
NUMERIC_MAX = 200000
 
 
class NumericInfo:
    def __init__(self):
        self.index = - 1
        self.value = NUMERIC_MIN - 1
 
    def update(self, idx, val):
        self.index = idx
        self.value = val
 
    def copy(self, info):
        self.update(info.index, info.value)
 
 
class SequenceProcessor:
    def __init__(self, sequence):
        self.sequence_length = len(sequence)
        self.first_largest_num_info = NumericInfo()
        self.second_largest_num_info = NumericInfo()
        self._process(sequence)
 
    def _process(self, sequence):
        for i, num in enumerate(sequence):
            if self.first_largest_num_info.value < num:
                self.second_largest_num_info.copy(self.first_largest_num_info)
                self.first_largest_num_info.update(i, num)
            elif self.second_largest_num_info.value < num:
                self.second_largest_num_info.update(i, num)
 
    def _max_value(self, idx):
        if idx == self.first_largest_num_info.index:
            return self.second_largest_num_info.value
        else:
            return self.first_largest_num_info.value
 
    def all_max_value(self):
        for i in range(self.sequence_length):
            yield self._max_value(i)
 
 
def _validate_sequence_length(s):
    r = int(s)
 
 
def get_sequence_length_from_stdin():
    s = input()
    s = s.strip()
    return int(s)
 
 
def _validate_numeric(s):
    r = int(s)
 
 
def get_sequence_from_stdin(length):
    result = []
    for i in range(1, length+1):
        while True:
            n = input()
            try:
                result.append(int(n))
                break
            except ValueError:
                continue
    return result
 
 
def main():
    seq_len = get_sequence_length_from_stdin()
    sequence = get_sequence_from_stdin(seq_len)
    seq_processor = SequenceProcessor(sequence)
    for num in seq_processor.all_max_value():
        print(num)
 
 
if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
a = [int(input()) for _ in range(N)]
lcm = a[:]
rcm = a[:]
for i in range(1, N):
  lcm[i] = max(lcm[i], lcm[i - 1])
for i in range(N - 2, -1, -1):
  rcm[i] = max(rcm[i], rcm[i + 1])
print(rcm[1])
for i in range(1, N - 1):
  print(max(lcm[i - 1], rcm[i + 1]))
print(lcm[N - 2])

Solution (Python):

N = int(input())
a = [int(input()) for _ in range(N)]
lam = a[:]
ram = a[:]
for i in range(1, N):
  lam[i] = max(lam[i], lam[i - 1])
for i in range(N - 2, -1, -1):
  ram[i] = max(ram[i], ram[i + 1])
print(ram[1])
for i in range(1, N - 1):
  print(max(lam[i - 1], ram[i + 1]))
print(lam[N - 2])

Solution (Python):
N = int(input())
a = [int(input()) for _ in range(N)]
lam = [0] * N
ram = [0] * N
lam[0] = a[0]
ram[N - 1] = a[N - 1]
for i in range(1, N):
  lam[i] = max(lam[i - 1], a[i])
  ram[N - 1 - i] = max(ram[N - 1 - i + 1], a[N - 1 - i])
print(ram[1])
for i in range(1, N - 1):
  print(max(lam[i - 1], ram[i + 1]))
print(lam[N - 2])

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

for i in range(n):
  value = int(input())  
  max_value = max(max_value, value)
  a.append(value)
  
for i in range(n):
  if a[i] == max_value:
    max_count += 1
  
if max_count > 1:
  for i in range(n):
    print(max_value)
else:
  max_index = a.index(max_value)
  a.pop(max_index)
  second_max = max(a)
  
  for i in range(n):
    if i != max_index:
      print(max_value)
    else:
      print(second_max)

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

for i in range(N):
 a = int(input())
 if(i == 0):
    A_max,A_max_index = a,i
 else: 
    if(A_max <= a):
      A_max,A_max_index = a,i
 A.append(a)

for i in range(N):
  if(i != A_max_index): 
    print(A_max)
  else:
    A[i] = 0
    A =  list(map(lambda x: x*(-1), A))
    heapq.heapify(A)
    ans = -heapq.heappop(A)
    print(ans)

Solution (Python):
import copy
n = int(input())
alist = [int(input()) for i in range(n)]
blist = copy.deepcopy(alist)

alistmax = max(alist)
blist.remove(alistmax)
alist2max = max(blist)

for i in range(n):
    if alist[i] == alistmax:
        print(alist2max)
    else:
        print(alistmax)

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

a = list(int(input()) for _ in range(n))
b = sorted(a)

max = b[n-1]
sec_max = b[n-2]

for i in range(n):
  if a[i] == max:
    print(sec_max)
  else:
    print(max)

Solution (Python):
import heapq
import copy

N = int(input())
A_l = [int(input()) * -1 for _ in range(N)] 
A = copy.deepcopy(A_l)
heapq.heapify(A_l)

m = heapq.heappop(A_l) * -1
n = heapq.heappop(A_l) * -1

for a in A:
  if a * -1 == m:
    print(n)
  else:
    print(m)

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

s_A_l = sorted(A_l)

m = s_A_l[-1]
n = s_A_l[-2]


for a in A_l:
  if a == m:
    print(n)
  else:
    print(m)

Solution (Python):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
list = A
list = sorted(list)
max = list[-1]
second_max = list[-2]
cnt = A.count(max)
for i in range(N):
    if A[i] == max and  cnt == 1:
        print(second_max)
    else:
        print(max)

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

B = sorted(A, reverse = True)
max_val = B[0]
second_max_val = B[1]

for val in A:
    if val == max_val:
        print(second_max_val)
    else:
        print(max_val)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
max_n = a.count(max_a)
if len(set_a) == 1:
    s_set_a = max_a
else:
    if max_n > 1:
        s_set_a = max_a
    else:
        s_set_a = sorted(set_a)[-2]

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

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

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

max_item = max(A)
count = 0
second_item = 0
for i in range(N):
    if A[i] == max_item:
        count += 1
    elif second_item < A[i]:
        second_item = A[i]
    if count > 1:
        break
X = [0] * N
judge = False
for i in range(N):
    if count > 1:
        judge = True
        break
    if A[i] == max_item:
        X[i] = second_item
    else:
        X[i] = max_item

if judge:
    for i in range(N):
        X[i] = max_item
for i in range(N):
    print(X[i])

Solution (Python):
from sys import stdin
import numpy as np
n = int(stdin.readline().rstrip())
ary = np.array([int(stdin.readline().rstrip()) for _ in range(n)])
m = ary.argmax()
mv = ary.max()
for i in range(n):
    if i == m:
        if i == 0:
            print(np.amax(ary[i + 1:]))
        elif i == n - 1:
            print(np.amax(ary[:i]))
        else:
            print(max(np.amax(ary[:i]), np.amax(ary[i + 1:])))
    else:
        print(mv)

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

maxL = max(L)
subL = L
num = ["n"] * N

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:	
	for i in range(N):
		if L[i] == maxL:
			L[i] = 0
			print(max(L))
		else:
			print(maxL)

Solution (Python):
n = int(input())
nums = [int(input()) for i in range(n)]
n_max = max(nums)
ex_nums = [i for i in nums]
ex_nums.remove(n_max)
n_semi_max = max(ex_nums)
for i in nums:
    if i == n_max:
        print(n_semi_max)
    else:
        print(n_max)

Solution (Python):
import copy
N = int(input())
A = [int(input()) for i in range(N)]
tmp = copy.copy(A)
tmp.sort()
MAX = tmp[-1]
MAXsub = tmp[-2]
place = A.index(MAX)
for i in range(N):
    if i != place:
        print(MAX)
    else:
        print(MAXsub)

Solution (Python):
import sys
import heapq
import copy

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

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

b = copy.deepcopy(a)
heapq.heapify(b)

for i in range(n):
	maximum = heapq.heappop(b)
	if maximum == a[i]:
		tmp = maximum
		maximum = heapq.heappop(b)
		print(maximum * (-1))
		heapq.heappush(b,tmp)
	else:
		print(maximum * (-1))
	heapq.heappush(b,maximum)

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

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

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

cs = sorted(A)

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

Solution (Python):
n=int(input())
a = [int(input()) for _ in range(n)]
b=sorted(a)
c=[0]*n

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

Solution (Python):
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
b = max(a)
maxid = a.index(b)
for i in range(N):
    if i != maxid:
        print(b)
    elif i == maxid:
        del a[i]
        print(max(a))

Solution (Python):
N = int(input())
An = list()
for i in range(N):
    An.append(int(input()))
MaxIndex = An.index(max(An))
SecondIndex = An.index(sorted(An)[-2])
for i in range(0,N):
    if i == MaxIndex:
        print(An[SecondIndex])
    else:
        print(An[MaxIndex])

Solution (Python):
n = int(input())
f_max = s_max = 0
arr = []
for _ in range(n):
    a = int(input())
    arr.append(a)
    if a >= f_max:
        s_max = f_max
        f_max = a
    elif a >= s_max:
        s_max = a

for integer in arr:
    if integer == f_max:
        print(s_max)
    else:
        print(f_max)

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

MAX = max(A)
SECONDMAX = sorted(A)[N-2]

for i in range(N):
    if A[i] ==MAX:
        print(SECONDMAX)
    else:
        print(MAX)

Solution (Python):

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


max_1st_value_in_list_A = max(list_A)
max_1st_index_in_list_A = list_A.index(max(list_A))

list_A.pop(max_1st_index_in_list_A)

max_2nd_value_in_list_A = max(list_A)








for i in range(N):
    if i!=max_1st_index_in_list_A:
        print(max_1st_value_in_list_A)
    else:
        print(max_2nd_value_in_list_A)

Solution (Python):

n=int(input())
a=[int(input()) for i in range(n)]
ma = max(a)
fut_max = a.index(ma)
for i in range(n):
    if(i!=fut_max):
        print(ma)
    else:
        a.pop(fut_max)
        print(max(a))

Solution (Python):
N = int(input())
A = [int(input()) for i in range(0, N)]
ans1 = max(A)
s = A.index(ans1)

if A.count(ans1) >= 2:
    for i in range(N):
        print(ans1)
else:
    for i in range(N):
        if i == s:
            A.remove(ans1)
            print(max(A))
        else:
            print(ans1)

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)]
maxa = max(a)
seconda = a[:]
seconda.remove(maxa)
secondmaxa = max(seconda)
for i in range(0,n):
    if a[i] == maxa:
        print(secondmaxa)
    else:
        print(maxa)

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

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


max_val = max(list_A)


for i in range(len(list_A)):
    if list_A[i] == max_val:
        max_val_position = i
        break


max_val_2 = max(list_A[:max_val_position] + list_A[max_val_position+1:])

for i in range(len(list_A)):
    
    
    if i == max_val_position:
        print(max_val_2)
    else:
        print(max_val)

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





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

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

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

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

lstA = sorted(lst,reverse=True)

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

Solution (Python):
import numpy as np
N = int(input())
nList = [int(input()) for _ in range(N)]
maxN = max(nList)
lenMaxN = np.argmax(nList)
ansList = [maxN for _ in range(N)]
if nList.count(maxN) >= 2:
    for i in range(N):
        print(ansList[i])

else:
    second = sorted(set(nList))[-2]
    ansList[lenMaxN] = second
    for i in range(N):
        print(ansList[i])

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

def main():
    n=int(input())
    a=[0 for _ in range(n)]
    for i in range(n):
        a[i]=int(input())
    M=max(a)
    cnt=0
    ans=0
    S=0
    for i in range(n):
        if(a[i]!=M and a[i]>S):
            S=a[i]
        elif(a[i]==M):
            cnt+=1
    
    for i in range(n):
        if(a[i]!=M or cnt>1):
            ans=M
        else:
            ans=S
        print(ans)        
main()