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 = []
for i in range(N):
    A.append(int(input()))
    
MAX1 = max(A)
MAX2 = -1
index = A.index(MAX1)
for i in range(N):
    if i != index:
        MAX2 = max(MAX2,A[i])
        
if MAX1 == MAX2:
    for i in range(N):
        print(MAX1)
else:
    for i in range(N):
        if i == index:
            print(MAX2)
        else:
            print(MAX1)

Solution (Python):
def inpl():
    return list(map(int, input().split()))


N = int(input())
A = [int(input()) for i in range(N)]
A.append(-1)
ma = N
na = N
for i in range(N):
    if A[i] > A[ma]:
        na = ma
        ma = i
    elif A[i] > A[na]:
        na = i

for i in range(N):
    if i == ma:
        print(A[na])
    else:
        print(A[ma])

Solution (Python):


import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

N = int(input())





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



A = sorted(A, key=lambda x : x[1], reverse=True)

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

Solution (Python):

import copy
N = int(input())

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

m = max(A)
c = A.count(m)

for a in A:
    if a != m:
        print(m)
    else:
        if c > 1:
            print(m)
        else:
            l = copy.deepcopy(A)
            l.remove(m)
            print(max(l))

Solution (Python):
n=int(input())
hoge=[]
huga=[]
for i in range(n):
  x=int(input())
  hoge.append(x)
  huga.append(x)
huga.sort(reverse=True)
x=huga[0]
y=huga[1]
if(huga[0]==huga[1]):
  for i in range(n):
    print(x)
else:
  for i in range(n):
    if(hoge[i]==huga[0]):
      print(y)
    else:
      print(x)

Solution (Python):
import heapq

N = int(input())
h = []
ax = []
for _ in range(N):
    a = int(input())
    heapq.heappush(h,a* (-1))
    ax.append(a)

m1 = heapq.heappop(h) * (-1)
m2 = heapq.heappop(h) * (-1)

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

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

max_a = 0
max_i = 0
for i in range(N):
    a = int(input())
    if a > max_a:
        max_a = a
        max_i = i
    A.append(a)

del A[max_i]
max2_a = max(A)

ans_arr = []
for i in range(N):
    if max_i == i:
        ans_arr.append(str(max2_a))
    else:
        ans_arr.append(str(max_a))

ans = '\n'.join(ans_arr)
print(ans)

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

A_list = [0 for i in range(N)]

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

A_sorted = sorted(A_list)

maxA = A_sorted[-1]
second_maxA = A_sorted[-2]

for i in A_list:

    if i == maxA:
        print(second_maxA)
    else:
        print(maxA)

Solution (Python):
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  
  

n = inn()
a = []
for i in range(n):
    a.append(inn())
accl = [0] * (n+1)
accr = [0] * (n+1)
for i in range(n):
    accl[i] = max(accl[i-1], a[i])
for i in range(n-1,-1,-1):
    accr[i] = max(accr[i+1], a[i])
for i in range(n):
    print(max(accl[i-1], accr[i+1]))

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

B = sorted(A, key=lambda x: x[1])
largest_index = B[-1][0]
for i in range(N):
    if A[i][0] == largest_index:
        print(B[-2][1])
    else:
        print(B[-1][1])

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

Asort = sorted(A)
maxA = Asort[-1]
nexA = Asort[-2]

for a in A:
    if a == maxA:
        print(nexA)
    else:
        print(maxA)

Solution (Python):
n=int(input())
list_a=[]
m1=0
m2=0
for i in range(n):
    a=int(input())
    list_a.append(a)
    if a>m1:
        m2=m1
        m1=a
    elif a>=m2:
        m2=a
for i in range(n):
    if list_a[i]==m1:
        print(m2)
    else:
        print(m1)

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

if max_value == sub_max_value:
    for i in range(N):
        print(max_value)
else:
    for Ai in A:
        if Ai == max_value:
            print(sub_max_value)
        else:
            print(max_value)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = [int(input()) for _ in range(N)]

maxA = max(A)
lenA = len(A)
cnt_maxA = A.count(maxA)

if cnt_maxA > 1:
    for _ in range(lenA):
        print(maxA)
    exit()

for i, a in enumerate(A):
    if a == maxA:
        if i == 0:
            print(max(A[1:]))
        elif i == lenA-1:
            print(max(A[:-1]))
        else:
            print(max(max(A[:i]), max(A[i+1:])))
    else:
        print(maxA)

Solution (Python):

N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))
maxvalue=max(A)
i=A.index(maxvalue)
del A[i]
secondvalue=max(A)
for j in range(0,i):
    print(maxvalue)
print(secondvalue)
for j in range(i+1,N):
    print(maxvalue)

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

Solution (Python):
def sol():
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=[]
    d={}
    x=y=0
    for i in range(n):
        t=int(input())
        a.append(t)
        if t in d:
            d[t]+=1
        else:
            d[t]=1
        if t>x:
            y=x
            x=t
        elif t>y:
            y=t
    for i in a:
        if i==x and d[i]==1:
            print(y)
        else:
            print(x)

if __name__=="__main__":
    sol()

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

max_value = max(A)
max_index = A.index(max_value)

A.sort()
sec_max_value = A[-2]

for i in range(N):
    if i != max_index:
        print(max_value)
    else:
        print(sec_max_value)

Solution (Python):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
    
left_max = [0]*(N+1)
right_max = [0]*(N+1)
for i in range(1,N+1):
    left_max[i] = max(left_max[i-1],A[i-1])
    
for i in range(N-1,-1,-1):
    right_max[i] = max(right_max[i+1],A[i])
    
for i in range(N):
    print(max(left_max[i],right_max[i+1]))

Solution (Python):
from sys import stdin
import numpy as np
N = int(stdin.readline().rstrip())
data = []
for _ in range(N):
    data.append(int(input()))
max_val = max(data)
max2_val = sorted(data)[-2]
for i in data:
    if i == max_val:
        print(max2_val)
    else:
        print(max_val)

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

a = []
aa = []

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

aa.sort()
firsta = aa[-1]
seconda = aa[-2]


if firsta == seconda:
    for i in range(n):
        print(firsta)
else:
    for i in range(n):
        if a[i] == firsta:
            print(seconda)
        else:
            print(firsta)

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

Solution (Python):
N = input()
N = int(N)
S = [int(input()) for _ in range(N)]
S2 = sorted(S, reverse=True)
onon = S2[0]

for i in range(N):
    if S[i] != onon:
        print(onon)
    else:
        print(S2[1])

Solution (Python):
n = int(input())
a = []
max_num = 0
max_ind = 0
max_count = 0
for i in range(n):
    inp = int(input())
    a.append(inp)
    if inp > max_num:
        max_num = inp
        max_ind = i
        max_count = 1
    elif inp == max_num:
        max_count += 1
for i in range(n):
    if max_count > 1:
        print(max_num)
    else:
        if i == max_ind:
            a.remove(max_num)
            print(max(a))
        else:
            print(max_num)

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

aa = sorted(a)
a_max = aa[-1]
a_max_ind = [x == a_max for x in a]

if aa[-2] == aa[-1]:
    for i in range(n):
        print(a_max)
else:
    for i in range(n):
        if a_max_ind[i]:
            print(aa[-2])
        else:
            print(aa[-1])

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

re = sorted(c) 

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

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

for i in range(n):
    get_num = int(input())
    if get_num > max_num:
        second_max_num = max_num
        max_num = get_num
    elif get_num > second_max_num:
        second_max_num = get_num
        
    num_list.append(get_num)

for i in num_list:
    if i == max_num:
        print(second_max_num)
    else:
        print(max_num)

Solution (Python):
import sys
n=input()
ls=[]
for _ in xrange(n):
    ls.append(input())
m1= max(ls)
i=ls.index(m1)
del ls[ls.index(m1)]
m2= max(ls)
ls.insert(i,m1)
for i in xrange(n):
    if ls[i]==m1:
        print m2
    else:
        print m1

Solution (Python):
def main():
    n = int(input())
    a = [[i, int(input())] for i in range(n)]
    b = sorted(a, key=lambda x: x[1], reverse=True)
    b0 = b[0]
    b1 = b[1]

    for aa in a:
        if aa[0] == b0[0]:
            print(b1[1])
        else:
            print(b0[1])


main()

Solution (Python):
N = int(input())
Alist = [int(input()) for i in range(N)]
max_first = 0
max_second = 0
for ai in Alist:
    if max_first < ai:
        max_first, max_second = ai, max_first
    elif max_second < ai:
        max_second = ai
for ai in Alist:
    if max_first == ai:
        print(max_second)
    else:
        print(max_first)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True


def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    a_list = []
    for i in range(N):
        a = II()
        a_list.append(a)

    from collections import Counter
    c = Counter(a_list)
    mx = max(a_list)

    k = c.keys()
    second = None
    if len(k) > 1:
        second = sorted(k, reverse=True)[1]

    for i in range(N):
        a = a_list[i]
        if a != mx:
            
            print(mx)
        else:
            if c[a] == 1:
                
                print(second)
            else:
                
                print(mx)


solve()

Solution (Python):
N = int(input())
AN = [int(input()) for i in range(N)]
list = list(reversed(sorted(AN)))

for A in AN:
    if list[0] == A:
        print(list[1])
    else:
        print(list[0])

Solution (Python):
N = int(input())
A = []
B = []
for i in range(N):
    a = int(input())
    A.append(a)
    B.append(a)
B.sort()
maxA = B[-1]
max2A = B[-2]

for j in range(N):
    if A[j] == maxA:
        print(max2A)
    else:
        print(maxA)

Solution (Python):
import math
import copy
import numpy as np

n = int(input())
i = 0
a_list = []

while i < n:
  a_list.append(int(input()))
  i += 1
  
tmp_a_list = copy.deepcopy(a_list)
first_max = max(a_list)
first_idx = np.argmax(a_list)

tmp_a_list[first_idx] = 0
second_max = max(tmp_a_list)
second_idx = np.argmax(tmp_a_list)

i = 0
while i < n:
  if i == first_idx:
    print(second_max)
  else:
    print(first_max)
  i += 1

Solution (Python):
import collections as c
ip = lambda : map(int, input().split())

mod = 1e9+7
N = int(input())
f,s,fi,si = 0,0,0,0
for i in range(N):
    t = int(input())
    if f<t:
        s,si = f,fi
        f,fi = t,i
    elif s<t:
        s,si = t,i
for i in range(fi):
    print(f)
print(s)
for i in range(N-fi-1):
    print(f)

Solution (Python):
import numpy as np

N = int(input())

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

A = np.array(A)
maxval = A.max()
maxindex = A.argmax()

A[maxindex] = -1
secval = A.max()

for i in range(N):
	if i == maxindex:
		print(secval)
	else:
		print(maxval)

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

max_num = max(A)
max_ind = A.index(max(A))
for i in range(N):
  if max_ind == i:
    print(max(A[0:i]+A[i+1:N]))
  else:
    print(max_num)

Solution (Python):
import os, sys, re, math

N = int(input())

a = []
for _ in range(N):
    a.append(int(input()))
sorted_a = sorted(a,reverse=True)[:2]

for ai in a:
    if ai == sorted_a[0]:
        print(sorted_a[1])
    else:
        print(sorted_a[0])

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

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
new_a = sorted(a)
max_a = max(new_a)
cheak = a.index(max_a)
for i in range(n):
    if i != cheak:
        print(max_a)
    else:
        print(new_a[n-2])

Solution (Python):

N = int(input())
A = []
global_max = 1
second_max = 0
for i in range(N):
    new_a = int(input())
    A.append(new_a)
    if new_a > global_max:
        second_max = global_max
        global_max = new_a
    elif new_a > second_max:
        second_max = new_a


for a in A:
    if a < global_max:
        print(global_max)
    else:
        print(second_max)

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

sorted_a = sorted(a_list)

max_a = sorted_a[-1]
semi_max_a = sorted_a[-2]

for a in a_list:
    if a == max_a:
        print(semi_max_a)
    else:
        print(max_a)

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

ma = 0
prem = 0
maxi = -1
for i in range(n):
  x = int(input())
  
  if ma < x:
    prem = ma
    ma = x
    maxi = i
    
  elif prem < x:
    prem = x
    
for i in range(n):
  if maxi == i:
    print(prem)
  else:
    print(ma)

Solution (Python):
import numpy as np

def acinput():
    return list(map(int,input().split(" ")))


N=int(input())

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

idx=np.argsort(a)

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

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

B = A + []
B.sort(reverse=True, key=lambda x:x[0])
ans = [B[0][0]]*N
if B[0][0]!=B[1][0]:
    ans[B[0][1]] = B[1][0]

for a in ans:
    print(a)

Solution (Python):
from collections import Counter

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

c = Counter(A)

mx = max(A)
B = list(set(A))
B.remove(mx)
for i in range(N):
    if A[i] != mx:
        print(mx)
    elif c[mx] == 1:
        print(max(B))
    else:
        print(mx)

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

R = [0] * N
L = [0] * N

for i in range(N):
  L[i] = max(A[i], L[i-1])

for i in range(N-1, 0-1, -1):
  R[i] = max(A[i], R[(i+1)%N])

for i in range(N):
  print(max( 0<i and L[i-1], i<N-1 and R[i+1] ))

Solution (Python):
import copy

N = int(input())

seq = []

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

seq2 = copy.deepcopy(seq)
seq2.sort(reverse=True)

n1 = seq2[0]
n2 = seq2[1]

for a in seq:
    if a == n1:
        print(n2)
    else:
        print(n1)

Solution (Python):
import numpy as np

n = int(input())

A = [int(input()) for i in range(n)]
A = np.array(A)
a_max = np.max(A)
a_max_ind = np.argmax(A)
A[a_max_ind] = 0

for i in range(n):
    if i != a_max_ind:
        print(a_max)
    else:
        print(np.max(A))

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

n = int(input())
a = [int(input()) for i in range(n)]
a_m = a.index(max(a))
am = a[a_m]
del a[a_m]
amm = max(a)
for i in range(n):
    if i != a_m:
        print(am)
    else:
        print(amm)

Solution (Python):
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
2
5
5
'''


def MAIN():
  
  A()


def A():
  n = IN_I()
  l = []
  for i in range(0, n):
    l.append(IN_I())

  l2 = l.copy()
  l.sort()

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

  return None


def B():
  return None


def C():
  return None


MAIN()

Solution (Python):

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

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

aSort = sorted(a, reverse=True, key=itemgetter(1))

for i in range(n):
    j = 0
    while (aSort[j][0] == i):
        j += 1
    print(aSort[j][1])

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

for i in range(N):
    A = int(input())
    if i == 0:
        top_val = A
        top_i = 0
    elif i == 1:
        if top_val < A:
            second_val = top_val
            second_i = top_i
            top_val = A
            top_i = i
        else:
            second_val = A
            second_i = i
    else:
        if top_val < A:
            second_val = top_val
            second_i = top_i
            top_val = A
            top_i = i
        elif second_val < A:
            second_val = A
            second_i = A

for i in range(N):
    if top_i == i:
        print(second_val)
    else:
        print(top_val)

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

d = [0]*N
dd = [0]*N
d[0] = A[0]
dd[-1] = A[-1]

for i in range(1,N):
    d[i] = max(d[i-1], A[i])

for i in range(2,N+1):
    dd[-i] = max(dd[-i+1],A[-i])


print(dd[1])

for i in range(N-2):
    print(max(d[i],dd[i+2]))
print(d[-2])

Solution (Python):
import collections

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

A_c = collections.Counter(A)
A_max = max(A)
A_2 = sorted(list(set(A)), reverse=True)
if len(A_2) >= 2:
    A_2ndmax = A_2[1]

for i in range(N):
    if A_c[A_max] >= 2:
        print(A_max)
    else:
        if A[i] != A_max:
            print(A_max)
        else:  
            print(A_2ndmax)

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

list_a = [int(input()) for _ in range(N)]
sorted_list_a = sorted(list_a)

largest = sorted_list_a[-1]
second_largest = sorted_list_a[-2]

for a in list_a:
    if a == largest:
        print(second_largest)
    else:
        print(largest)

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

Solution (Python):
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

N = int(input())

A = []
for i in range(N):
	A.append(int(input()))
B = copy.deepcopy(A)
A.sort()
a_max = max(A)

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

Solution (Python):
N=int(input())
Amax=0
secoundmax=0
L=[]
for i in range(N):
    A=int(input())
    if Amax>A:
        if A>secoundmax:secoundmax=A
    elif A>Amax:
        secoundmax=Amax
        Amax=A
        L=[i]
    else:
        L.append(i)
if len(L)>=2:
    for _ in range(N):print(Amax)
else:
    for j in range(N):
        if j in L:print(secoundmax)
        else:print(Amax)

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

a_list_sorted = sorted(a_list)
max1 = a_list_sorted[-1]
max2 = a_list_sorted[-2]

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

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
sa = set(a)
max_a = max(sa)
max_c = a.count(max_a)

if max_c > 1:
    for _ in range(n):
        print(max_a)
else:
    sa.discard(max_a)
    sec_max_a = max(sa)
    for v in a:
        if v == max_a:
            print(sec_max_a)
        else:
            print(max_a)

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

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

Solution (Python):

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

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

s=line[:]
s.sort()
M=s[-1]
m=s[-2]

for i in range(n):
    if line[i]==M:
        print(m)
    else:
        print(M)

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

m1=0
m2=0

A=[]

for i in range(N):
    a=int(input())
    if a>m1:
        m1=a
    elif a>m2:
        m2=a
    A.append(a)

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 = int(input())
    A.append(a)

B = sorted(A, reverse=True)
maxA = B[0]
maxB = B[1]
idx = A.index(maxA)
for i in range(N):
    if i == idx:
        print(maxB)
    else:
        print(maxA)

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

tmp = A
A = sorted(A, reverse=True)

idx = tmp.index(A[0])

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

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

ls = l[:]
ls.sort()

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

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)
for Ai in A:
    d[Ai] += 1

sorted_A = sorted(d.keys(), reverse=True)
for Ai in A:
    if Ai < sorted_A[0]:
        ans = sorted_A[0]
    else:
        ans = sorted_A[0] if d[sorted_A[0]] >= 2 else sorted_A[1]
    print(ans)

Solution (Python):
n=int(input())
dekai=[0,0]
onaji=0
alist=[]
for i in range(n):
    ai=int(input())
    if ai>dekai[0]:
        dekai[1]=dekai[0]
        dekai[0]=ai
    elif ai>dekai[1]:
        dekai[1]=ai
    alist.append(ai)

for i in range(n):
    x=alist[i]
    if x==dekai[0]:
        print(dekai[1])
    else:
        print(dekai[0])

Solution (Python):
n = int(input())
lst = []
for i in range(n):
  lst.append(int(input()))
slst = sorted(lst)
m1 = slst[-1]
m2 = slst[-2]
for i in range(n):
  if(lst[i] == m1):
    print(m2)
  else:
    print(m1)

Solution (Python):



def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = sorted(A)
    
    m1 = B[-1]
    m2 = B[-2]

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



if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()

A = IR(N)

left = [0]*N
right = [0]*N

left[0] = A[0]
right[-1] = A[-1]

for i in range(1,N):
    left[i] = max(left[i-1], A[i])
for i in range(0, N-1)[::-1]:
    right[i] = max(right[i+1], A[i])

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

Solution (Python):
import sys
import math
import copy

input = sys.stdin.readline

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

Solution (Python):
n =int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
a.append(0)
a.insert(0,0)
b = [0]*(n+2)
c = [0]*(n+2)
for i in range(1,n+1):
    b[i] = max(a[i],b[i-1])
    c[n+1-i] = max(a[n+1-i],c[n+2-i])
for i in range(1,n+1):
    print(max(b[i-1],c[i+1]))

Solution (Python):
import copy

N = int(input())

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

B = copy.deepcopy(A)
B.pop(maxvi)

max_v1 = max(A)
max_v2 = max(B)

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

Solution (Python):
import copy
from collections import Counter
N = int(input())
num= [int(input()) for i in range(N)]
numcopy = list(set(copy.deepcopy(num)))
numcopy.sort(reverse=True)
numcount = Counter(num)
for i in range(len(num)):
    if num[i]==numcopy[0] and numcount[num[i]]==1:
        print(numcopy[1])
    else:
        print(numcopy[0])

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
second = sorted(a)[-2] if len(a) >= 2 else a[0]
for i in a:
  if i == a_max:
    print(second)
  else:
    print(a_max)

Solution (Python):
from collections import Counter
N = int(input())
A = [int(input()) for _ in range(N)]
Ac = Counter(A)

s = []
for Ai in Ac:
    s.append((Ai, Ac[Ai]))

s = sorted(s, reverse=True)

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

Solution (Python):


import sys
inf = float("inf")













from bisect import bisect_left,bisect_right



def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
Arr=[]
for i in range(n):
    Arr.append(int(input()))
mydict=dict()
for i in Arr:
    mydict[i]=mydict.get(i,0)+1
maxi=max(Arr)
occurence=mydict[maxi]
if occurence>1:
    for i in range(n):
        print(maxi)
    exit()
second_maxi=-1
for i in Arr:
    if i>second_maxi and i<maxi:
        second_maxi=i
for i in range(n):
    if Arr[i]!=maxi:
        print(maxi)
    else:
        print(second_maxi)

Solution (Python):
from collections import Counter


len_arr = int(input())

arr = [int(input()) for _ in range(0, len_arr)]

counter = Counter(arr)
arr_max = max(counter)

if counter[arr_max] == 1:
    max_index = arr.index(arr_max)
    for i in range(0, len_arr):
        if i == max_index:
            del(counter[arr_max])
            print(max(counter))
        else:
            print(arr_max)

else:
    for _ in range(0, len_arr):
        print(arr_max)

exit(0)

Solution (Python):
n=int(input())
a=[int(input()) for _ in [0]*n]
M=max(a)
k=a.index(M)
m=max(a[:k]+a[k+1:])
for i in range(n):
    if i!=k:print(M)
    else:print(m)

Solution (Python):


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l1=[I() for _ in range(n)]

  l2=copy.deepcopy(l1)
  l2.sort(reverse=True)

  a=l2[0]
  b=l2[1]

  for x in l1:
    if x==a:
      print(b)
    else:
      print(a)

main()

Solution (Python):

"""
Created on Sat Jul 20 20:53:37 2019

@author: ctiuser
"""

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

first = 0
second = 0
for c in A:
    if c > first:
        first, second = c, first
    elif c > second:
        second = c

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

Solution (Python):
def main():
    n = int(input())
    a_s = [int(input()) for _ in range(n)]
    maximum = max(a_s)
    idx_max = a_s.index(maximum)
    second = max(a_s[:idx_max] + a_s[idx_max+1:])
    for i in range(n):
        if i == idx_max:
            print(second)
        else:
            print(maximum)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    maxv = 0
    maxv2 = 0
    A = [INT() for i in range(N)]
    A_ = sorted(A, reverse = True)
    maxv = A_[0]
    maxv2 = A_[1]
    for i in range(N):
        if A[i] == maxv:
            print(maxv2)
        else:
            print(maxv)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
a = [int(input()) for _ in range(N)]
b = sorted(a,reverse=True)
one = b[0]
two = b[1]

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

Solution (Python):
import copy
n = int(input())
a = [int(input()) for i in range(n)]
b = copy.deepcopy(a)
b.sort()
amax = b[-1]
amax2 = b[-2]
for i in range(n):
    if a[i] != amax:
        print(amax)
    elif a[i] == amax:
        print(amax2)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    b = int(input())
    a.append(b)
large = max(a)
maxi = a.index(max(a))
a[maxi] = 0
next1 = max(a)
for i in range(n):
    if i == maxi:
        print(next1)
    else:
        print(large)

Solution (Python):
N=int(input())
An=[1 for _ in range(N)]
for i in range(N):
  An[i]=int(input())
Bn=sorted(An)
Max=Bn[-1]
Max2=Bn[-2]

for n in range(len(An)):
  if An[n]!=Max:
    print(Max)
  else:
    print(Max2)