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



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for x 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])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
max1=sorted(a)[-1]
if n==2:
    print(a[1])
    print(a[0])
elif sorted(a)[-2]!=max1:
    max=sorted(a)
    max2=0
    for i in range(2,n):
        if max[-i]!=max1:
            max2=max[-i]
            break
    for i in range(n):
        if a[i]==max1:
            print(max2)
        else:
            print(max1)
else:
    for i in range(n):
        print(max1)

Submission status: Accepted

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

max = max(A)
max_idx = A.index(max)

[print(max) for _ in range(max_idx)]
print(sorted(A)[-2])
max_idx += 1
[print(max) for _ in range(max_idx, N)]

Submission status: Accepted

Solution code:
#abc134c
import copy

n=int(raw_input())
a=[]
for i in xrange(n):
 a.append(int(raw_input()))
num1=sorted(a)[-1]
num2=sorted(a)[-2]
if a.count(num1)>1:
 for i in xrange(n):
  print num1
else:
 for i in xrange(n):
  if a[i]==num1:
   print num2
  else:
   print num1

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
max_A = max(A)
B = set(A)
if len(B) == 1 or A.count(max_A) >= 2:
    for i in range(N):
        print(max_A)
else:
    C = list(A)
    for i in range(N):
        if A[i] == max_A:
            C.remove(max_A)
            print(max(C))
        else:
            print(max_A)

Submission status: Accepted

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

b = sorted(a, reverse = True)

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

Submission status: Accepted

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

A_s = sorted(A, reverse=True)
top1 = A_s[0]
top2 = A_s[1]

for i in A:
    if i == top1:
        print(top2)
    else:
        print(top1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
i=0
b=[]
pos=0
maxi=0
while(i<n):
  k=int(input())
  b.append(k)
  if(k>maxi):
    pos=i
    maxi=k
  i+=1
b.sort()
ns=b[n-2]
i=0
while(i<n):
  if(i==pos):
  	print(ns)
  else:
    print(b[n-1])
  i+=1

Submission status: Accepted

Solution code:
def solve(n, a):
    l = [0] * n
    r = [0] * n
    v = 0
    for i in range(n):
        l[i] = v
        v = max(v, a[i])
    v = 0
    for i in range(n-1, -1, -1):
        r[i] = v
        v = max(v, a[i])
    for i in range(n):
        print(max(l[i], r[i]))

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

Submission status: Accepted

Solution code:
n=int(input())
num_list=[]
top1=0
top2=0
for i in range(n):
    num_list.append(int(input()))
    if top1<num_list[i]:
        top1=num_list[i]
    elif top2<num_list[i]:
        top2=num_list[i]
for j in range(n):
    if num_list[j]==top1:
        print(top2)
    else:
        print(top1)

Submission status: Accepted

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

No1 = 0
No2 = 0
for i in range(N):
    if A[i] > No1:
        No2 = No1
        No1 = A[i]
    elif A[i] > No2:
        No2 = A[i]

for i in range(N):
    if A[i] == No1:
        print(No2)
    else:
        print(No1)

Submission status: Accepted

Solution code:
n=int(input())
L=[]
for i in range(n):
    L.append(int(input()))
    
L_sort=sorted(L)
L_sort.reverse()
m_1=L_sort[0]
m_2=L_sort[1]

if m_1==m_2:
    for i in range(n):
        print(m_1)
else:
    for i in range(n):
        if L[i]==m_1:
            print(m_2)
        else:
            print(m_1)

Submission status: Accepted

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import statistics

# qsort(array[])
def qsort(seq):
	if len(seq) < 1:
		return seq
	pivot = seq[0]
	left = []
	right = []
	for x in range(1, len(seq)):
		if seq[x] <= pivot:
			left.append(seq[x])
		else:
			right.append(seq[x])
	left = qsort(left)
	right = qsort(right)
	foo = [pivot]
	return (left + foo + right)

# , = map(int, input.split())
n = int(input())
#  = raw_input().split()
#  = list(int(i) for i in input().split())  
a = []

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

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

Submission status: Accepted

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

m = max(a)
s = sorted(a)

for i in range(n):
  if m is a[i]:
    print(s[-2])
  else:
    print(m)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input().strip())
an = [int(input().strip()) for i in range(n)]
san = sorted(an)
m_a = san[-1]
m_b = san[-2]

for i in range(n):
  if an[i] == m_a:
    print(m_b)
  else:
    print(m_a)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N = int_raw()
    As = [int_raw() for _ in range(N)]
    As2 = sorted(As)
    m1 = As2[-1]
    m2 = As2[-2]
    for a in As:
        if a ==m1:
            print(m2)
        else:
            print (m1)

main()

Submission status: Accepted

Solution code:
n=int(input())
a = [int(input()) for _ 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])

Submission status: Accepted

Solution code:
N =int(input())
A = [0]*N
a = 0
b = 0
for i in range(N):
    x = int(input())
    if x > a:
        b = a
        a = x
    elif x > b:
        b = x
    A[i] = x

for c in A:
    if c == a:
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
s, f = sorted(a)[-2:]

for ai in a:
    print(f if ai != f else s)

Submission status: Accepted

Solution code:
n=int(input())
m1=0
s1=0
m2=0
l=[]
for i in range(n):
  n1=int(input())
  l.append(n1)
  if n1>m1:
    m2=m1
    m1=n1    
    s1=0
  elif n1==m1:
    s1+=1
  elif n1>m2:
    m2=n1
if s1>0:
  for i in range(n):
    print(m1)
else:
  for i in range(n):
    if m1==l[i]:
      print(m2)
    else:
      print(m1)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
x,y = sorted(A)[-2:]
for a in A :
    print(y if a != y else x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
sorted_A = list(set(A))
max_A = sorted_A[-1]
max_nums = set(i for i, v in enumerate(A) if v == max_A)
if len(max_nums) > 1:
    for i in range(N):
        print(max_A)
else:
    max2_A = sorted_A[-2]
    for i in range(N):
        if i in max_nums:
            print(max2_A)
        else:
            print(max_A)

Submission status: Accepted

Solution code:
N = int(input())

A = []

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

max_value = max(A)           

max_index = A.index(max_value)

B = A[:]

del B[max_index]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0 for n in range(n)]
for i in range(n):
  a[i] = int(input())
a_max = max(a)
b = sorted(a)
a_second = b[n-2]
for j in range(n):
  if a[j] != a_max:
    print(a_max)
  else:
    print(a_second)

Submission status: Accepted

Solution code:
N=int(input())
A=[[i,int(input())] for i in range(N)]
A.sort(key=lambda x:x[1],reverse=True)
j=A[0][0]
b1=A[0][1]
b2=A[1][1]
for i in range(N):
  print(b2 if i==j else b1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main12():
    n = int(input())
    nlist = []
    for i in range(n):
        nlist.append(int(input()))
    maxnum = max(nlist)
    c = nlist.count(maxnum)
    if c > 1:
        for i in range(n):
            print(maxnum)
    else:
        l = nlist.index(maxnum)
        nlist[l] = 0
        maxnum2 = max(nlist)
        for i in range(n):
            if i != l:
                print(maxnum)
            else:
                print(maxnum2)

if __name__ == "__main__":
    main12()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)
mi = a.index(m)
for i in range(n):
    if i == mi:
        ma = max(a[: i] + a[i + 1: ])
        print(ma)
    else:
        print(m)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a)
m,M=b[-2:]
for i in range(n): print(m if a[i]==M else M)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)

if a.count(m) > 1:
    for _ in range(n):
        print(m)
else:
    mi = a.index(m)
    for i in range(n):
        if i == mi:
            ma = max(a[: i] + a[i + 1: ])
            print(ma)
        else:
            print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
m = max(a)

if a.count(m) > 1:
    for _ in range(n):
        print(m)
else:
    for i in range(n):
        if a[i] == m:
            a[i] = 0
            ma = max(a)
            print(ma)
        else:
            print(m)

Submission status: Accepted

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

first = -1
second = -1
for i in ai:
    if first < i:
        second = first
        first = i
    elif second < i:
        second = i

for x in ai:
    if x == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
N = int(input())
ai = []
for i in range(N):
    ai.append(int(input()))
first = max(ai)
ai_ = ai[:]
ai_.remove(first)
second = max(ai_)

for x in ai:
    if x == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
n = int(input())
arr = []
fst = 0
scd = 0
for i in range(n):
  t = int(input())
  fst, scd = sorted([fst, scd, t], reverse=True)[:2]
  arr.append(t)

for i in range(n):
  print(fst if arr[i]!=fst else scd)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if(2<=n<=200000):
        break
a=[]
for i in range(n):
        a.append(int(input()))
ma=a[0]
b=0
for j in range(1,n):
    if(ma==a[j]):
        b=a[j]
    if(ma<a[j]):
        ma=a[j]
        continue
    if(b<a[j]):
        b=a[j]
for l in range(n):
    if(a[l]!=ma):
        print(str(ma))
    else:
        print(str(b))

Submission status: Accepted

Solution code:
l=[]
a=int(input())
for i in range(a):
  b=int(input())
  l.append(b)
c=l.copy()
c.sort()
max1=c[-1]
max2=c[-2]

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
 
for _ in range(N):
    A.append(int(input()))
    
a = b = 0
    
for i in range(N):
    if A[i] >= a:
        b = a
        a = A[i]
    elif A[i] > b:
        b = A[i]
 
for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
  
def solve():
  n = int(input())
  maxi = -10
  maxi2 = -10
  place = -1
  for i in range(n):
    a = int(input())
    if a>maxi:
      maxi2 = maxi
      maxi = a
      place = i
    else:
      maxi2 = max(maxi2,a)
  for j in range(n):
    if place == j:
      print(maxi2)
    else:
      print(maxi)
  
solve()

Submission status: Accepted

Solution code:

def solve():
  n = int(input())
  maxi = -10
  maxi2 = -10
  place = -1
  for i in range(n):
    a = int(input())
    if a>maxi:
      maxi2 = maxi
      maxi = a
      place = i
    else:
      maxi2 = max(maxi2,a)
  for j in range(n):
    if place == j:
      print(maxi2)
    else:
      print(maxi)
  
solve()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
x = A.index(m)
m2 = max(A[:x] + A[x + 1:])
ans = [m for _ in range(N)]
ans[x] = m2
for i in range(N):
    print(ans[i])

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
from operator import itemgetter

N = int(stdin.readline().rstrip().split()[0])
A = []
for i in range(N):
    A.append(int(stdin.readline().rstrip().split()[0]))

L_max = [0]
R_max = [0]

for i in range(N-1):
    L_max.append(max(L_max[-1], A[i]))

for i in range(N-1,0,-1):
    R_max.append(max(R_max[-1], A[i]))

R_max=R_max[::-1]
noi_max = []
for i in range(N):
    noi_max.append(max(L_max[i], R_max[i]))

for i in range(N):
    print(noi_max[i])

Submission status: Accepted

Solution code:
n=int(input())
A=[int(input()) for i in range(n)]
b=list(set(A))
if A.count(max(A))>1:
    ans=max(b)
    for i in range(n):
        print(ans)
    exit()

mi,maxi=b[-2:]
for a in A:
    if a==maxi:
        print(mi)
    else:
        print(maxi)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

biggest = 0
secandBiggest = 0
A = [0 for i in range(N)]
for i in range(N):
  A[i] = int(input())
  if(biggest <= A[i]):
    secandBiggest = biggest
    biggest = A[i]
  elif(secandBiggest <= A[i]):
    secandBiggest = A[i]
    
for i in range(N):
  if(A[i] == biggest):
    print(secandBiggest)
  else:
    print(biggest)

Submission status: Accepted

Solution code:
import math
import fractions
import copy
import numpy as np

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
n = ip()
a = []
ma = 1
mnum = -1
for i in range(n):
  a.append(ip())
  if mnum < a[i]:
    ma = 1
    mnum = a[i]
  elif mnum == a[i]:
    ma+=1
for i in range(n):
  if a[i] != mnum or ma>1:
    print(mnum)
  elif a[i] == mnum:
    b = copy.copy(a)
    b.pop(i)
    print(max(b))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a,reverse=True)
x,y=b[0],b[1]
z=a.index(x)
for i in range(n):
	if i==z:
		print(y)
	else:
		print(x)

Submission status: Accepted

Solution code:
num = int(input())
box = [int(input()) for _ in range(num)]
box_dash = sorted(box, reverse=True)
for b in box:
  if b == box_dash[0]:
    print(box_dash[1])
  else:
    print(box_dash[0])

Submission status: Accepted

Solution code:
N = int(input())
A = [ int(input()) for _ in range(N) ]
B = A[:]
B.sort()
for a in A:
  if a == B[N-1]:
    print(B[N-2])
  else:
    print(B[N-1])

Submission status: Accepted

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

maxa = max(a[0],a[1])
mina = min(a[0],a[1])

for i in range(2,n):
    if a[i] >= maxa:
        mina = maxa
        maxa = a[i]
    elif a[i] >mina:
        mina = a[i]

for i in range(n):
    if a[i] == maxa:
        print(mina)
    else:
        print(maxa)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input())for _ in range(n)]
left=[0]
for i in a:
  left.append(max(left[-1],i))
right=[0]
for i in reversed(a):
  right.append(max(right[-1],i))
right.reverse()
for i in range(n):
  print(max(left[i],right[i+1]))

Submission status: Accepted

Solution code:
N, *l = map(int, open(0).read().split())

l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]

for j in range(N):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)

Submission status: Accepted

Solution code:
import numpy as np

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

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

B = np.array(A)
C = B.argsort()[::-1]

fuji_i = C[0]
kita_i = C[1]
fuji = A[C[0]]
kita = A[C[1]]

for i in range(N):
    if i != fuji_i:
        print(fuji)
    else:
        print(kita)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

import numpy as np

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

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

from_left, from_right

from_left = [0] + from_left.tolist()[:-1]
from_right = from_right[1:].tolist() + [0]

for x,y in zip(from_left, from_right):
    print(x if x > y else y)

Submission status: Accepted

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

l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]

for j in range(len(l)):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)

Submission status: Accepted

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

max1 = max(A[0], A[1])
max2 = min(A[1], A[0])
if A[0] > A[1]:
    maxi1 = 0
    maxi2 = 1
else:
    maxi1 = 1
    maxi2 = 0


for i, a in enumerate(A[2:], 2):
    if max1 < a:
        max2 = max1
        maxi2 = maxi1
        max1 = a
        maxi1 = i
    elif max2 < a:
        max2 = a
        maxi2 = i

for i in range(N):
    if i != maxi1:
        print(max1)
    else:
        print(max2)

Submission status: Accepted

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

mx = max(n)
m = n.index(mx)
b = sorted(n)
my = b[N-2]

for i in range(N):
	if i == m:
		print(my)
	else:
		print(mx)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = []
for i, a in enumerate(A):
    B.append((i, a))
B.sort(key=lambda x: x[1], reverse=True)
for i in range(N):
    if i==B[0][0]:
        print(B[1][1])
    else:
        print(B[0][1])

Submission status: Accepted

Solution code:
n = int(input())
a = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
    elif a[i] > prem:
        prem = a[i]
for i in range(n):
    if a[i] == m:
        print(prem)
    else:
        print(m)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
first = max(A)
second = sorted(A)[:: -1][1]
for ai in A:
	if ai == first:
		print(second)
	else:
		print(first)

Submission status: Accepted

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

a = max(A)
A_max = []
A_ = A[:]

for i in range(N):
  if A[i] == a:
    A_[i] = 0
    break
    
a_ = max(A_)    
    
for i in range(N):
  if A[i] != a:
    A_max.append(a)
  else:
    A_max.append(a_)
    
for i in A_max:
  print(i)

Submission status: Accepted

Solution code:
N = int(input())

A = []

for i in range(0, N):
    A.append(int(input()))

max1 = sorted(A)[-1]
max2 = sorted(A)[-2]


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
aa = sorted(a,reverse=True)
a1 = aa[0]
a2 = aa[1]
for i in a:
    if i == a1:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
first = max(a)
second_1 = sorted(a)
second = second_1[-2]
for i in range(0, n):
    if a[i] == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for _ in range(n)]
_l = l.copy()
_l.sort(reverse=True)
lmax = _l[0]
lsec = _l[1]

for i in range(n):
    if l[i] == lmax:
        print(lsec)
    else:
        print(lmax)

Submission status: Accepted

Solution code:
N = int(input())
a_list = [int(input()) for i in range(N)]
_a_list = a_list[::]
_a_list.sort(reverse=True)
first =  _a_list[0]
second = _a_list[1]

for i in range(N):
    if a_list[i] == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for i in range(0,n):
  lst.append(int(input()))
  
sort_lst = lst[:]
sort_lst.sort(reverse=True)
m = sort_lst[0]
m_s = max = sort_lst[1]
for i in range(0,len(lst)):
  if not lst[i] == m:
    print(m)
  else:
    print(m_s)

Submission status: Accepted

Solution code:
N = int(input())
A = []
Copy = []
for i in range(N):
    tmp = int(input())
    A.append(tmp)
    Copy.append(tmp)
Copy.sort()

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = int(input())

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

max1 = 0
max2 = 0

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a) # sortする降順に

for a in a:print(b[(a<b[-1])-2])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
sA = sorted(A)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sorted_a = sorted(a)
    a_max = max(a)
    a_second = sorted_a[-2]

    for ai in a:
        if ai == a_max:
            print(a_second)
        else:
            print(a_max)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

    for ai in a:
        if ai == a_max:
            print(sorted_a[-2])
        else:
            print(sorted_a[-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
list=[]
for i in range(N):
  list.append(int(input()))
M=max(list)
L=[i for i, v in enumerate(list) if v == M]
n=len(L)
if n>1:
  for i in range(N):
    print(M)
else:
  del list[L[0]]
  M2=max(list)
  for i in range(N):
    if i == L[0]:
      print(M2)
    else:
      print(M)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
L = [None] * N

for i in range(N):
    L[i] = (int(input()), i)
    
L.sort(key = lambda x:-x[0])

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
for a in a:print(b[(a<b[-1])-2])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
tmpa = a[:] 
tmpa.sort()

for x in a:
  if x == tmpa[n-1]:
    print(tmpa[n-2])
  else:
    print(tmpa[n-1])
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

for x in a[2:]:
  if x > m2:
    if x>m:
      m2,m = 

"""
"""
for i in range(n):
  if i == 0:
    p
    rint(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
a = [[i+1, II()] for i in range(n)]
a = sorted(a, key=lambda x: x[1])
maxi = a[-1][1]
for i in range(1, n+1):
    print(maxi if i != a[-1][0] else a[-2][1])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
L = sorted(A)

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

Submission status: Accepted

Solution code:
n = int(input())
lister = [int(input()) for i in range(n)]
ordered=sorted(lister,reverse=True)

for element in lister:
  if ordered[0]!=element:
    print(ordered[0])
  else:
    print(ordered[1])

Submission status: Accepted

Solution code:
import copy
n = int(input())
 
columns = [int(input()) for i in range(n)]

sorted_columns = sorted(columns, reverse = True)

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
  
sorted_a = sorted(a, reverse=True)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


N = int(input())
lst_A = [int(input()) for _ in range(N)]
srt_A = sorted(lst_A, reverse=True)
m1 = srt_A[0]
m2 = srt_A[1]


for v in lst_A:
    print(m2 if v == m1 else m1)

Submission status: Accepted

Solution code:
N = int(input())
lst_A = [int(input()) for _ in range(N)]
srt_A = sorted(lst_A, reverse=True)
m1 = srt_A[0]
m2 = srt_A[1]


for v in lst_A:
    print(m2 if v == m1 else m1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

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

b = sorted(a)

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

Submission status: Accepted

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

B = sorted(A, reverse=True)

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

Submission status: Accepted

Solution code:
import heapq


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


hq = []
for val in lst_A:
    val *= -1
    heapq.heappush(hq, val)
m1 = -(heapq.heappop(hq))
m2 = -(heapq.heappop(hq))


for v in lst_A:
    print(m2 if v == m1 else m1)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
b_max = b[-1]
b.pop(-1)
b_2max = b[-1]

for i in a:
    if i == b_max:
        print(b_2max)
    else:
        print(b_max)

Submission status: Accepted

Solution code:
import sys
import heapq


input = sys.stdin.readline
N = int(input())
lst_A = [int(input()) for _ in range(N)]


hq = []
for val in lst_A:
    val *= -1
    heapq.heappush(hq, val)
m1 = -(heapq.heappop(hq))
m2 = -(heapq.heappop(hq))


for v in lst_A:
    print(m2 if v == m1 else m1)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(0, n):
    a.append(int(input()))
b = a.copy()
f = max(b)
b.remove(f)
s = max(b)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
for a in a:print(b[(a<b[-1])-2])