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 numpy as np
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

tmp = copy.deepcopy(A)
tmp = list(sorted(A, reverse=True))

Amax = tmp[0]
Asecond = tmp[1]

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

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [1, 4, 3])
    4
    3
    4
    >>> print_ans(2, [5, 5])
    5
    5
    """
    ar = np.array(ar)
    ar_idx = np.argsort(ar)

    for i in range(N):
        for k in reversed(range(N)):
            if i != ar_idx[k]:
                print(ar[ar_idx[k]])
                break

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = [int(input().rstrip()) for i in range(N)]
    print_ans(N, ar)

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

ans1=max(array)
answer=[ans1]*n

for i in range(n):
  if array[i]==ans1:
    array.pop(i)
    ans2=max(array)
    answer[i]=ans2
    break
for i in range(n):
  print(answer[i])

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

lenA=len(A)
Amax=max(A)
ind=A.index(Amax)
del A[ind]
Amax2=max(A)

AA=np.repeat(Amax,lenA, axis=0)
AA[ind]=Amax2
for x in AA:
  print(x)

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

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

Solution (Python):

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

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

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



if __name__ == '__main__':
    main()

Solution (Python):
import collections
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=collections.Counter(a)
d=list(b.items())
d.sort(key=lambda x:-int(x[0]))
if d[0][1]==1:
  for i in range(n):
    if a[i]==int(d[0][0]):
      print(int(d[1][0]))
    else:
      print(int(d[0][0]))
else:
  for i in range(n):
    print(int(d[0][0]))

Solution (Python):
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
    
    
import copy
U=copy.deepcopy(A)
del U[U.index(max(U))]
X=max(U)
Q=max(A)
Z=A.index(Q)
for i in range(N):
    if i==Z:
        print(X)
    else:
        print(Q)

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

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

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

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

b.sort()

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

Solution (Python):
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
maxa = max(A)
for i in range(n):
    if A[i] == maxa:
        print(tmp[-2])
    else:
        print(maxa)

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

m=max(l)


if l.count(m)>1:
    for i in range(n):
        print(m)

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

Solution (Python):


N = int(input())

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

max=0
a=0
for i in range(N):
  if s[i]>max:
    max=s[i]
    a=i

for i in range(N):
  if i==a:
    s.sort()
    s.reverse()
    print(s[1])
  else:
    print(max)

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

max_val = max(li)
sec_val = sorted(li)[-2]
ans = []

for j in li:
    if j == max_val:
        ans.append(sec_val)
    else:
        ans.append(max_val)

for k in ans:
    print(k)

Solution (Python):
n = int(input())
a = [int(input()) for x in range(n)]
a1 = sorted(a)

amax = a1[n-1]
amax2 = a1[n-2]

for i in a:
    if i == amax:
        print(amax2)
    else:
        print(amax)

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

Solution (Python):
N = int(input())
A = []
B = [0] * N
for i in range(N):
    A.append(int(input()))
max = max(A)
B = sorted(A, reverse = True)
for i in range(N):
    if A[i] != max:
        print(max)
    else:
        print(B[1])

Solution (Python):
N = int(input())
A = []
B = [0] * N
for i in range(N):
    A.append(int(input()))
max = max(A)
B = sorted(A, reverse = True)
count = A.count(max)
if count > 1:
    for i in range(N):
        print(max)
else:
    for i in range(N):
        if A[i] != max:
            print(max)
        else:
            print(B[1])

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

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

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

Solution (Python):
n = int(input())
import copy
list = []
for i in range(n):
    k = int(input())
    list.append(k)
list1 = copy.deepcopy(list)
first = max(list1)
list1.remove(first)
second = max(list1)
for li in list:
    if li == first:
        print(second)
    else:
        print(first)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[int(input()) for _ in range(n)]
    Left=[0]*n
    Left[0]=A[0]
    Right=[0]*n
    Right[-1]=A[-1]

    for i in range(1,n):
        Left[i]=max(A[i],Left[i-1])
    for i in range(n-2,-1,-1):
        Right[i]=max(A[i],Right[i+1])

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

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

A = []

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

A_sorted = sorted(A, reverse=True)
A_max1 = A_sorted[0]
A_max2 = A_sorted[1]

for a in A:
    if a == A_max1:print(A_max2)
    else:print(A_max1)

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() )
c_list = []
for i in range(N):
    c_list.append( int( input() ) )
    
a = c_list[:]
a.sort()
ma = a[ N - 1 ]

for i in range(N):
    t = c_list[i]
    if t == ma:
        print(a[N - 2])
    else:
        print(ma)

Solution (Python):
n = int(input())
num_list = []
max_num = 0
max_num2 = 0

for x in range(n):
    i = int(input())
    if max_num < i:
        max_num2 = max_num
        max_num = i
    elif max_num2 < i:
        max_num2 = i
    num_list.append(i)

for num in num_list:
    if max_num != num:
        print(max_num)
    else:
        print(max_num2)

Solution (Python):
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([1, 4, 3]), [4, 3, 4])

    def test_2(self):
        self.assertEqual(think([5, 5]), [5, 5])


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    a = []
    for _ in range(n):
        a.append(read_int(1)[0])
    return a


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    hist = make_histogram(a)

    list_form_of_hist = []
    for k, v in hist.items():
        list_form_of_hist.append([k, v])
    list_form_of_hist.sort(key=lambda x: -x[0])

    result = []
    for e in a:
        if e == list_form_of_hist[0][0]:
            if list_form_of_hist[0][1] == 1:
                result.append(list_form_of_hist[1][0])
            else:
                result.append(list_form_of_hist[0][0])
        else:
            result.append(list_form_of_hist[0][0])
    return result


def write(result):
    for e in result:
        print(e)


def make_histogram(a):
    hist = {}
    for e in a:
        if e in hist:
            hist[e] += 1
        else:
            hist[e] = 1
    return hist


if __name__ == '__main__':
    
    solve()

Solution (Python):



n = int(input())
max_1 = 0
max_2 = 0
al = []
for _ in range(n):
    a = int(input())
    al.append(a)

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

for a in al:
    if a == max_1:
        print(max_2)
    else:
        print(max_1)

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

L=[]
for i in range(n):
      L.append(int(input()))
L2=sorted(L)
for i in range(n):
      if L[i]==L2[-1]:
            print(L2[-2])
      else:
            print(L2[-1])

Solution (Python):
import heapq
import copy

n = int(input().strip())

a = []

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

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

first = heapq.heappop(b)
second = heapq.heappop(b)

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

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

sorted_A_list = sorted(A_list)
n1 = sorted_A_list[-1]
n2 = sorted_A_list[-2]

for i in range(N):
    if A_list[i] == n1:
        print(n2)
    else:
        print(n1)

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

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

one=sorted(A)[-1]
two=sorted(A)[-2]

for i in A:
    print(one if i!=one else two)

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

for j in range(0,n):
  a.append(int(input()))
  
x=max(a)
y=a.index(x)
del a[y]
z=max(a)

for i in range(0,n):
  if i!=y:
    print(x)
  else:
    print(z)

Solution (Python):
n = int(input())
a = []
for i in range(n):
  dmy = int(input())
  a.append(dmy)
  
a_max = a.index(max(a))
a.sort()
for i in range(n):
  if i==a_max:
    print("{}".format(a[-2]))
  else:
    print("{}".format(a[-1]))

Solution (Python):
n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)

Solution (Python):
n = int(input())
ai = {}
max1 = 0
max2 = 0
for i in range(1, n+1):
    tmp = int(input())
    ai.setdefault(i, tmp)
    if tmp > max1:
        max2 = max1
        max1 = tmp
    elif tmp > max2:
        max2 = tmp

for i in range(1, n+1):
    if ai[i] == max1:
        print(max2)
    else:
        print(max1)

Solution (Python):
n = int(input())
ai = {}
max1 = 0
max2 = 0
for i in range(1, n+1):
    tmp = int(input())
    ai.setdefault(i, tmp)
    if tmp > max1:
        max1 = tmp
    elif tmp > max2:
        max2 = tmp

for i in range(1, n+1):
    if ai[i] == max1:
        print(max2)
    else:
        print(max1)

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


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


a_max = max(A)
a_max_count = A.count(a_max)
a_max_index = A.index(a_max)


if a_max_count == 1:
    
    A.remove(a_max)
    a_second_max = max(A)

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

else:
    for _ in range(N):
        print(a_max)

Solution (Python):
N = int(input())
A = ([int(input()) for n in range(N)])
sorted_A = sorted(A)
max_ = sorted_A[len(A)-1]
semi_max = sorted_A[len(A)-2]


for i in range(N):
    if(A[i]==max_):
        print(semi_max)
    else:
        print(max_)

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

A_max = max(A)
A_max_2 = sorted(A)[-2]
for i in range(n):
    if A[i] == A_max:
        print(A_max_2)
    else:
        print(A_max)

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

max_v1 = max(a)
max_i1 = a.index(max_v1)
a.remove(max_v1)
max_v2 = max(a)

for i in range(n):
    if i == max_i1:
        print(max_v2)
    else:
        print(max_v1)

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

max_num = 1
second_max_num = 1
A = [0]*N
for i in range(N):
    j = int(input())
    A[i] = j
    if j > max_num:
        second_max_num = max_num
        max_num = j
    elif j > second_max_num:
        second_max_num = j

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

Solution (Python):
import heapq

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

for i in range(1, n+1):
  av = -int(input())
  heapq.heappush(a, (av, i))

fst = heapq.heappop(a)
sec = heapq.heappop(a)

for i in range(1,n+1):
  if i == fst[1]:
    print (-sec[0])
  else:
    print (-fst[0])

Solution (Python):
n = int(input())
maxindex = maxvalue = 0
a = []
for i in range(n):
    _a = int(input())
    if maxvalue <= _a:
        maxvalue = _a
        maxindex = i
    a.append(_a)

for i in range(n):
    if i != maxindex:
        print(maxvalue)
        continue
    t = a[:]
    t.pop(i)
    print(max(t))

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

Solution (Python):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
n_max = len(list(filter(lambda x: x==a_max, a)))
if n_max >= 2:
  for i in range(n):
    print(a_max)
else:
  a_exp = max(list(filter(lambda x: x < a_max, a)))
  for i in range(n):
    if a[i] == a_max:
      print(a_exp)
    else:
      print(a_max)

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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)
m = 0
mm = 0
cnt = 0
for i in a:
    if i > m:
        mm = m
        m = i
        cnt = 0
    elif i == m:
        cnt += 1
    elif i > mm:
        mm = i
for i in a:
    if i == m:
        if cnt > 0:
            print(m)
        else:
            print(mm)
    else:
        print(m)

Solution (Python):
n = int(input())
ls = [int(input()) for _ in range(n)]
sls = sorted(ls)

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

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

maxa = max(a)
index_max = a.index(maxa)

for i in range(0, n):
    if i == index_max:
        print(sorted(a)[-2])
    else:
        print(maxa)

Solution (Python):
N=int(input())
D=sorted(dict([(i,int(input())) for i in range(N)]).items(),key=lambda x:x[1])
M=D[-1][1]
m=D[-2][1]
for i in range(N):
  if i==D[-1][0]:
    print(m)
  else:
    print(M)

Solution (Python):

def main():
    N, *A = map(int, open(0))
    m1, m2 = sorted(A, reverse=1)[:2]
    ans = [m1 if i != m1 else m2 for i in A]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, *A = map(int, open(0))
    sorted_A = sorted(A)
    m1, m2 = sorted_A[-1], sorted_A[-2]
    ans = [m1 if i != m1 else m2 for i in A]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

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

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

Solution (Python):

n = int(input())
al = [int(input()) for _ in range(n)]
al2 = sorted(al)

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

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

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

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

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

    A_sorted = sorted(A)

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


if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
a = []
b = []
 
for i in range(n):
    s = int(input())
    a.append(s)
    b.append(s)
    
b.sort()
b.reverse()
 
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):
import copy

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

S = copy.deepcopy(A)
S.sort()

first = S[-1]
second = S[-2]

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

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b_max = sorted(a)[-2]
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)

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

Solution (Python):
import numpy as np

N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
A = np.array(A)
A_max_1 = np.max(A)
A_max_index = np.argmax(A)
A = np.delete(A, A_max_index)
A_max_2 = np.max(A)
answer = []
for i in range(N):
  if not i == A_max_index:
    answer.append(A_max_1)
  else:
    answer.append(A_max_2)
for i in range(N):
  print(answer[i])

Solution (Python):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
x=max(a)
count=0
b=len([a[i] for i in range(len(a)) if a[i]==x])
for j in range(n):
    if b>1:
        print(x)
    else:
        if a[j]==x:
            tmp=a[j]
            a.remove(a[j])
            print(max(a))
            a.insert(j,tmp)
        else:
            print(x)

Solution (Python):
N=int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A2=sorted(A,reverse=True)
M=A2[0]
M2=A2[1]
for i in range(N):
  
  
  if A[i]==M:
    print(M2)
  else:
    print(M)

Solution (Python):
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
max1 = 0
max2 = 0
for i in range(N):
  if max1 < A[i]:
    max2 = max1
    max1 = A[i]
  elif A[i] > max2:
    max2 = A[i]

for j in range(N):
  if A[j] == max1:
    print(max2)
  else:
    print(max1)

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

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

(fst, snd) = (0, 0)
for i in range(N):
    a = int(input())
    if a > fst:
        (fst, snd, argFst) = (a, fst, i)
    elif a > snd:
        snd = a

for i in range(N):
    if i == argFst:
        print(snd)
    else:
        print(fst)

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

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

Solution (Python):
N = int(input())
A_list = []
for i in range(1,N+1):
    A = int(input())
    A_list.append(A)
A_list_sort = sorted(A_list)

max_a = A_list_sort[-1]
max_b = A_list_sort[-2]


for i in range(N):
    if A_list[i] == max_a:
        print(max_b)
    else:
        print(max_a)

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

first = A2[-1]
second = A2[-2]

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)]
m2, m1 = sorted(a)[n-2:n]
for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

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

  a.append(x)

b = a.copy()  
b.sort(reverse=True)
a_max1 = b[0]
a_max2 = b[1] 

for i in a:
  if i == a_max1:
    print(a_max2)
  else:
    print(a_max1)

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 range(len(a)):
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    slove()

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

max = -1
max2 = -1
maxnum = -1
max2num = -1
for index in range(N):
    temp = int(input())
    if max < temp:
        max = temp
        maxnum = index
    elif max2 < temp:
        max2 = temp

for index in range(N):
    if index == maxnum:
        print(max2)
    else:
        print(max)

Solution (Python):
n = int(input())
max_id = 0
cur_max = 0
second_max = 0
for i in range(n):
  ai = int(input())
  if ai > cur_max:
    second_max = cur_max
    cur_max = ai
    max_id = i
  elif ai > second_max:
    second_max = ai

for i in range(n):
  if (i == max_id):
    print(second_max)
  else:
    print(cur_max)

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


max1=-1
max2=-10

max1_ind=-100
max2_ind=-100

for i in range(len(S)):
        if S[i] > max1:
                max2=max1
                max2_ind = max1_ind

                max1=S[i]
                max1_ind=i
        elif S[i] > max2:
                max2=S[i]
                max2_ind=i

for i in range(len(S)):
        if i != max1_ind:
                print(max1)
        else:
                print(max2)

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


max1=-1
max2=-10

max1_ind=-100
max2_ind=-100

for i in range(len(S)):
        if S[i] > max1:
                max2=max1
                max2_ind = max1_ind

                max1=S[i]
                max1_ind=i
        elif S[i] > max2:
                max2=S[i]
                max2_ind=i

for i in range(len(S)):
        if i != max1_ind:
                print(max1)
        else:
                print(max2)

Solution (Python):
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
heapq.heapify(A_heap)
for idx, a in enumerate(A):
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)

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

Solution (Python):
N=int(input())
Numbers=[int(input()) for i in range(N)]
Numbers2=sorted(Numbers)
Amax=Numbers2[-1]
Asecond=Numbers2[-2]
for j in Numbers:
        if j != Amax:
                print(Amax)
        else:
                print(Asecond)

Solution (Python):
N=int(input())
A=[int(input()) for n in range(N)]
m=max(A)
n=sorted(A,reverse=True)[1]
print("\n".join([str(m) if a<m else str(n) for a in A]))

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

Solution (Python):
N = int(input())
A = [0]*N

for r in range(N): A[r] = int(input())
A_max = max(A)
A_sec = sorted(A)[-2]

for r in range(N):
  if A[r] == A_max: print(A_sec)
  elif A[r] == A_sec: print(A_max)
  else: print(A_max)

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
b=max(a)
c=a.count(b)
if c>1:
  for i in range(n):
    print(b)
else:
  d=sorted(a, reverse=True)
  e=d[1]
  f=0
  h=0
  while f!=b:
    g=a[h]
    if f<g:
      f=g
    h=h+1
  for i in range(h-1):
    print(b)
  print(e)
  for i in range(n-h):
    print(b)

Solution (Python):
N = int(input())
M1 = 0
M2 = 0
A = []
for a in range(N):
    a = int(input())
    A.append(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 = [0]*n
for i in range(n):
    a[i] = int(input())
amax = sorted(a)[-2:]
for i in range(n):
    if a[i] == amax[1]:
        print(amax[0])
    else:
        print(amax[1])

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

Solution (Python):
import copy
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = copy.deepcopy(a)
amax = max(a)
b.remove(amax)
amax2 = max(b)
for i in range(n):
    if a[i] == amax:
        print(amax2)
    else:
        print(amax)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
B=sorted(A,reverse=True)
max=B[0]
sec=B[1]

if max==sec:
    for n in range(N):
        print(max)
else:
    for a in A:
        if a==max:
            print(sec)
        else:
            print(max)

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

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

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)

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

import numpy as np

N = int(readline())
A = np.zeros(N+2,np.int32)
A[1:-1] = np.array(read().split(),np.int32)

A

from_left = np.maximum.accumulate(A)
from_right = np.maximum.accumulate(A[::-1])[::-1]

answer = np.maximum(from_left[:-2], from_right[2:])
print('\n'.join(answer.astype(str)))

Solution (Python):
N = int(input())
A = []
afirst = 0
asecond = 0
for _ in range(N):
	a = int(input())
	A.append(a)
	if(afirst < a):
		asecond = afirst
		afirst = a
	elif(asecond<a):
		asecond = a

for a in A:
	if(a == afirst):
		print(asecond)
	else:
		print(afirst)

Solution (Python):
def main(A):
    maxInt = max(A)
    secondInt = sorted(A)[-2]

    for a in A:
        if a == maxInt:
            print(secondInt)
        else:
            print(maxInt)

if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    main(A)

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

max_a = max(al)  
tmp_al = al[:]
tmp_al.remove(max_a)
snd_a = max(tmp_al)
  
for a in al:
  if a == max_a:
    print(snd_a)
  else:
    print(max_a)

Solution (Python):
N = int(input())
arr = [int(input()) for _ in range(N)]
sarr = sorted(arr, reverse=True)

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

Solution (Python):
N = int(input())
A = []
M = 0
p = 0
for i in range(N):
	t = int(input())
	A.append(t)
	if M < t:
		M = t
		p = i

A[p] = 0
sec = max(A)

for i in range(N):
	if i == p:
		print(sec)
	else:
		print(M)

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

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
no1 = max(A)
import sys
if A.count(no1) > 1:
    for i in range(N):
        print(no1)
    sys.exit()
else:
    ind = A.index(no1)
    no2 = max(A[:ind]+A[ind+1:])
    for i in range(N):
        if i == ind:
            print(no2)
        else:
            print(no1)

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
maxa=max(A)
id=A.index(maxa)
for i in range(N):
  if i==id:
    tmp=max(A[:i]+A[i+1:])
    print(tmp)
  else:
    print(maxa)

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

sortA = sorted(a, reverse=True)
maxA = sortA[0]
semiMaxA = sortA[1]

for i in range(n):
  if a[i] == maxA:
    print(semiMaxA)
  else:
    print(maxA)

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
a_max=max(a)
a_second=sorted(a)[-2]

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A = []
    ret = []
    for i in range(N):
        A.append(int(input()))

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

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

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

Solution (Python):
n=int(input())
max1=0
max2=0
max1_i=0

for i in range(n):
    a=int(input())
    if a>max1:
        max2=max1
        max1=a
        max_i=i
    elif a>max2:
        max2=a
    else:
        pass

for i in range(n):
    if i==max_i:
        print(max2)
    else:
        print(max1)