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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

sorted_A = sorted(A, reverse=True)

for a in A:
    if a == sorted_A[0]:
        print(sorted_A[1])
    else:
        print(sorted_A[0])

Submission status: Accepted

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

max_num = max(a)
max_pos = a.index(max(a))
a[max_pos] = -1
second_max = max(a)

for i in range(n):
    if i == max_pos:
        print(second_max)
    else:
        print(max_num)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
first = max(a)
second = 0
flag = a.count(first) > 1

if a.count(first) > 1:
    for i in a:
        print(first)
else:
    for i in a:
        if i != first and second < i:
            second = i
    for i in a:
        print(first if i != first else second)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
    
num_list = zip(A[:], range(N))
num_list = sorted(num_list, reverse=True)

max_n = num_list[0][0]
max_i = num_list[0][1]
sec_n = num_list[1][0]

for i in range(N):
    if i == max_i:
        print(sec_n)
    else:
        print(max_n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import heapq

def solve(N: int, A: "List[int]"):
    A1 = max(A)
    A2 = heapq.nlargest(2, A)[-1]
    
    for i in range(0, N):
        if A[i] == A1:
            print(A2)
        else:
            print(A1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# from sys import exit, stderr
# from inspect import currentframe
# def debug(*args):
#     names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
#     print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=stderr)
#     return
N = int(input())
a = [0 for _ in range(N)]
for i in range(N):
    a[i] = (i,int(input()))
a = sorted(a, key=lambda x: -x[1])
for i in range(N):
    for j in range(N):
        if a[j][0] == i:
            continue
        print(a[j][1])
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python
N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())
A_sort = sorted(A, reverse=True)
for i in range(N):
        if A[i] == A_sort[0]:
            print(A_sort[1])
        else:
            print(A_sort[0])

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)

hoge = sorted(A,reverse=True)
if c[hoge[0]] == 1:
    for _ in range(N):
        if A[_] == hoge[0]:
            print(hoge[1])
        else:
            print(hoge[0])
else:
    for _ in range(N):
        print(hoge[0])

Submission status: Accepted

Solution code:
N=int(input())
listA=[]
for i in range(N):
  listA+=[int(input())]
MAX=max(listA)
listB=sorted(listA)
for i in range(N):
  if listB[-1]==listA[i]:
    print(listB[-2])
  else:
    print(MAX)

Submission status: Accepted

Solution code:

N = int(input())

A = []

maxi = 0
sec = 0

for i in range(N):

    a = int(input())
    A.append(a)


    if A[maxi] <= a:
        maxi = i

B = A.copy()

del B[maxi]

sec = max(B)




for i in range(N):

    if i == maxi:
        print (sec)

    else:
        print (A[maxi])

Submission status: Accepted

Solution code:
n = int(input())
m = mi = 0
a = []
for i in range(n):
    x = int(input())
    a.append(x)
    if x == m:
        mi += 1
    if x > m:
        m = x
        mi = 1
if mi == 1:
    m2 = 0
    for i in range(n):
        if a[i] == m:
            continue
        if a[i] > m2:
            m2 = a[i]
    for i in range(n):
        if a[i] == m:
            print(m2)
        else:
            print(m)
else:
    for i in range(n):
        print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = a[:]
b.sort(reverse=True)
for i in range(n):
    if a[i] == b[0]:
        print(b[1])
    else:
        print(b[0])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for x in range(N)]
M = sorted(A,reverse=True)
M1 = M[0]
M2 = M[1]
for i in range(N):
    if A[i] <= M2:
        print(M1)
    else:
        print(M2)

Submission status: Accepted

Solution code:
import numpy as np
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = [I() for i in range(N)]

num = max(a)
cnt = a.count(num)
if cnt == 1:
  b = sorted(a)
  bb = b[-2]
  for i in a:
    if i == num:
      print(bb)
    else:
      print(num)
else:
  for i in range(N):
    print(num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    B = sorted(A)
    m1 = B.pop()
    m2 = B.pop()
    for i in range(N):
        if A[i] == m1:
            print(m2)
        else:
            print(m1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
ma = A.index(max(A))
maxA = max(A)
ma2 = sorted(A)[-2]
for i in range(N):
  if i == ma:
    print(ma2)
  else:
    print(maxA)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B = sorted(A)
M, M2 = B[-1], B[-2]

for a in A:
    print(M) if a != M else print(M2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    la = []
    n_best = 0
    best = 0
    best2 = 0
    for i in range(n):
        a = ri()
        la.append(a)
        if best < a:
            best2 = best
            best = a
            n_best = 1
        elif best == a:
            n_best += 1
        else:
            best2 = max(best2, a)
    for a in la:
        if a < best:
            print(best)
        else:
            if n_best > 1:
                print(best)
            else:
                print(best2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

S = []

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

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

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

for i in range(1,N):
    r = max(r, S[N-i])
    R[N-i-1] = r

for i in range(N):
    print(max(L[i], R[i]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# いっこ入力
n =int(input())
# n行の数をリストへ
a = [int(input()) for i in range(n)] 

max_val = 0
max_num = -1
max_next = 0

for i in range(n):
    if a[i] > max_val:
        max_next = max_val
        max_val = a[i]
        max_num = i
    elif a[i] == max_val:
        max_next = max_val
    elif a[i] > max_next:
        max_next = a[i]

for i in range(n):
    if i == max_num:
        print(max_next)
    else:
        print(max_val)

Submission status: Accepted

Solution code:
n = int(input())

a = []
maxA = 0
secondA = 0

for i in range(n):
    a.append(int(input()))
    if a[i] > maxA:
        secondA = maxA
        maxA = a[i]
    elif a[i] > secondA:
        secondA = a[i]

for i in range(n):
    if a[i] == maxA:
        print("{}".format(secondA))
    else:
        print("{}".format(maxA))

Submission status: Accepted

Solution code:
N=int(input())
A=[0]*N
maxN=0
secondN=0
for i in range(N):
  A[i]=int(input())
  if A[i]>=maxN:
    secondN=maxN
    maxN=A[i]
  elif A[i] > secondN:
    secondN=A[i]
for i in range(N):
  if A[i]==maxN:
    print(secondN)
  else:
    print(maxN)

Submission status: Accepted

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

c = sorted(a, reverse = True)

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

Submission status: Accepted

Solution code:
n = int(input())
a = list()
for i in range(n):
    a.append(int(input()))
c = a.index(max(a))
m = max(a)
a.sort()
d = a[-2]
for i in range(n):
    if i == c:
        print(d)
    else:
        print(m)

Submission status: Accepted

Solution code:
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Modified: <20/Jul/2019 05:43:16 PM>


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    arr = [0] * n
    for i in range(n):
        arr[i] = int(input())
    tmp = sorted(arr)
    mx = tmp[-1]
    mx1 = tmp[-2]
    for i in range(n):
        if arr[i] == mx:
            print(mx1)
        else:
            print(mx)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


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


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

m = max(a)

if a.count(m) > 1:
    for i in range(n):
        print(m)
else:
    b = sorted(set(a))
    m2 = b[-2]
    for i in range(n):
        if a[i] != m:
            print(m)
        else:
            print(m2)

Submission status: Accepted

Solution code:
def solve(n, xs):
	ys = sorted(xs, reverse=True)
	m1, m2 = ys[0], ys[1]
	for x in xs:
		if x == m1:
			yield m2
		else:
			yield m1


def main():
	n = int(input())
	xs = [int(input()) for _ in range(n)]
	for a in solve(n, xs):
		print(a)


if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = sorted(a, reverse=True)
mx_a = max(a)
for i in range(n):
    print(b[1] if a[i] == mx_a else mx_a)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=list(map(int, input().split()))
A=[0]*N[0]
L=0
M=0
for i in range(N[0]):
    A[i]=int(input())
    if A[i]>M:
        if A[i]>L:
            M=L
            L=A[i]
        else:
            M=A[i]
for i in range(N[0]):
    if A[i]==L:
        print(M)
    else:
        print(L)

Submission status: Accepted

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

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    max_val = max(A)
    AA = A[:]
    AA.remove(max_val)
    second_max_val = max(AA)
    for a in A:
        if a != max_val:
            print(max_val)
        else:
            print(second_max_val)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
in_list = []
for i in range(N):
    in_list.append(int(input()))
in_max = max(in_list)
in_max2 = sorted(in_list)[-2]
for i in in_list:
    if i!=in_max:
        print(in_max)
    else:
        print(in_max2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import heapq

def solve(N: int, A: "List[int]"):
    max_A = max(A)
    next_max_A = heapq.nlargest(2, A)[-1]
    for i in range(N):
        if A[i] == max_A:
            print(next_max_A)
        else:
            print(max_A)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# C
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
A_sort = sorted(A, reverse=True)


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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
m = -1
m2 = -1
for a in A:
    if a >= m:
        m2 = m
        m = a
    elif a < m and a >= m2:
        m2 = a
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(m2)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A = np.array(A)
s = np.argsort(A)
l = s[-1]
L = A[l]
for i in range(N):
    if i != l:
        print(L)
    else:
        print(A[s[-2]])

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for _ in range(n):
  a+=[int(input())]
max_a=0
max_2=0
max_i=[]
for i in range(n):
  if a[i]>=max_a:
    max_2=max_a
    max_a=a[i]
    max_i=[i]
  elif a[i]>max_2:
      max_2=a[i]
for i in range(n):
  if i==max_i[0]:
    print(max_2)
  else:
    print(max_a)

Submission status: Accepted

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

mx = max(A)
mx2 = sorted(A)[-2]
for a in A:
    print(mx) if a != mx else print(mx2)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for n in range(N):
    a=int(input())
    A.append(a)
dai=max(A)
basyo=A.index(max(A))
A.pop(basyo)
for n in range(N):
    if n==basyo:
        print(max(A))
    else:
        print(dai)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
    
sorted_A = sorted(A, reverse=True)
first = sorted_A[0]
second = sorted_A[1]

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

Submission status: Accepted

Solution code:
# Setup
import sys
import heapq
sys.setrecursionlimit(4100000)
n = int(input())
a = [int(input()) for i in range(n)]
heap = []
for i in range(n):
    heapq.heappush(heap,-a[i])
for i in range(n):
    temp = heapq.heappop(heap)
    if -a[i] == temp:
        temp2 = heapq.heappop(heap)
        print(-temp2)
        heapq.heappush(heap,temp)
        heapq.heappush(heap,temp2)
    else:
        print(-temp)
        heapq.heappush(heap,temp)

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

max_num = max(num_list)
max_count = num_list.count(max_num)

if max_count > 1:
    for i in num_list:
        print(max_num)
else:
    max_index = num_list.index(max_num)
    num_list[max_index] = -1
    second_num = max(num_list)
    num_list[max_index] = max_num

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

Submission status: Accepted

Solution code:
N = int(input())

#val, i
max_1 = [0, 0]
max_2 = [0, 0]

for i in range(N):
	a_i = int(input())
	if a_i > max_2[0]:
		max_2[0] = a_i
		max_2[1] = i
	if max_1[0] < max_2[0]:
		tmp = max_1
		max_1 = max_2
		max_2 = tmp
	# print(max_1, max_2)
		
for i in range(N):
	if i == max_1[1]:
		print(max_2[0])
	else:
		print(max_1[0])

Submission status: Accepted

Solution code:
import copy
n = int(input())
a = [int(input()) for i in range(n)]
ans = max(a)
n_a = copy.deepcopy(a)
n_a.remove(ans)
s_ans = max(n_a)
if s_ans == ans:
    for i in a:
        print(ans)
else:
    for i in a:
        if i == ans:
            print(s_ans)
        else:
            print(ans)

Submission status: Accepted

Solution code:
import copy

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

argmax_A = A.index(max(A))
B = copy.copy(A)
del(B[argmax_A])
ans = max(B)

for i in range(N):
    if i == argmax_A:
        print(ans)
    else:
        print(A[argmax_A])

Submission status: Accepted

Solution code:
n = int(input())
l = [[int(input()),i] for i in range(n)]
l.sort(key=lambda x:x[0])
#print(n,l)

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

Submission status: Accepted

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

B = copy.copy(A)
maxx = max(A)
A.pop(A.index(maxx))
second_max = max(A)

for i in range(N):
    if(B[i] == maxx):
        print(second_max)
    else:
        print(maxx)

Submission status: Accepted

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

left = [-1 for _ in range(N)]
right = [-1 for _ in range(N)]

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

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

for i in range(N):
    if i == 0:
        print(right[1])
    elif i == N-1:
        print(left[-2])
    else:
        print(max(left[i-1], right[i+1]))

Submission status: Accepted

Solution code:
n = int(input())
seq = []
maxi = 0
secondmax = 0
double = 0
for i in range(n):
    num = int(input())
    seq.append(num)
    if num > maxi:
        secondmax = maxi
        maxi = num
        double = 0
    elif num == maxi:
        double += 1
    elif secondmax < num < maxi:
        secondmax = num

for i in range(n):
    if seq[i] == maxi and double != 0:
        print(maxi)
    elif seq[i] == maxi and double == 0:
        print(secondmax)
    else:
        print(maxi)

Submission status: Accepted

Solution code:
n=int(input())
li=[]
for i in range(n):
    li.append(int(input()))
    
a=[max(li),li.index(max(li))]
li2=li[:]
v=sorted(li2)[-2]
b=[v,li.index(v)]

for i in li:
    if i==a[0]:
        print(b[0])
    else:
        print(a[0])

Submission status: Accepted

Solution code:

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

    maxs = sorted(As, reverse=True)[:2]

    for a in As:
        if a in maxs:
            print(maxs[0] if a != maxs[0] else maxs[1])
        else:
            print(maxs[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

B = sorted(A)
# print(B)
max_index = B[N-1][1] + 1
max_2_index = B[N-2][1]+1
for j in range(N):
    if j + 1 == max_index:
        print(B[N-2][0])
    else:
        print(B[N-1][0])

Submission status: Accepted

Solution code:
n = int(input())
a=[]
for i in range(n):
  a.append(int(input()))
#print(a)
aa = sorted(a, reverse=True) 
#print(aa)
m = aa[0]
for i in range(n):
  if a[i] == m:
    print(aa[1])
  else:
    print(m)

Submission status: Accepted

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

m = max(a)
idx = a.index(max(a))

for i in range(n):
    if i == idx:
        b = copy.copy(a)
        b.pop(idx)
        print(max(b))
    else:
        print(m)

Submission status: Accepted

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

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

buff = A.copy()
buff.sort()
buff = buff[::-1]

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

Submission status: Accepted

Solution code:
import numpy as np

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

maxA = max(A)
A_array = np.array(A)
maxi = np.argmax(A_array)


B = A.copy()
B.pop(maxi)

for i in range(N):
  if i != maxi :
    print(maxA)
  else :
    print(max(B))

Submission status: Accepted

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

maxim = max(As)
counter = As.count(maxim)

if counter > 1:
    for a in As:
        print(maxim)
else:
    for a in As:
        if a == maxim:
            print(max([i for i in As if i != a]))
        else:
            print(maxim)

Submission status: Accepted

Solution code:
N = int(input())
big = 0
big2 = 0
for i in range(N):
    A = int(input())
    if A > big:
        memo = i
        big = A
    elif A >= big2:
        big2 = A
for i in range(N):
    if i == memo:
        print(big2)
    else:
        print(big)

Submission status: Accepted

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

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

sorted_a = sorted(A)
max_a, max2_a = sorted_a[-1], sorted_a[-2]

for i in range(N):
    if A[i] == max_a:
        print(max2_a)
    else:
        print(max_a)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
As = sorted(a, reverse=True)
n1 = As[0]
n2 = As[1]
for ai in a:
    if ai == n1:
        print(n2)
    else:
        print(n1)

Submission status: Accepted

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

no1 = max(a)
place_ma = a.index(no1)

a.pop(place_ma)

no2 = max(a)

for i in range(n):
    if i == place_ma:
        print(no2)
    else:
        print(no1)

Submission status: Accepted

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

max_A = max(A)
B = copy.deepcopy(A)
B.remove(max_A)
max_B = max(B)
#print(max_A, max_B)

for i in range(N):
    if A[i] == max_A:
        print(max_B)
    else:
        print(max_A)

Submission status: Accepted

Solution code:
N = int(input())

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

a_max = max(A)

a_max_count = 0

a_second = 0

for n in A:
    if n != a_max:
        a_second = max(n, a_second)
    else:
        a_max_count += 1

if a_max_count >= 2:
    for _ in A:
        print(a_max)
else:
    for n in A:
        if n == a_max:
            print(a_second)
        else:
            print(a_max)

Submission status: Accepted

Solution code:

n = int(input())

highest = 0
higher = 0
multiple = False


an = [0]*n

for i in range(n):
    t = an[i] = int(input())

    if  highest < t :
        higher = highest
        highest = t
        multiple = False

    elif highest == t:
        multiple = True

    elif higher < t:
        higher = t


if multiple:
    for _ in range(n):
        print(highest)

else:
    for a in an:
        print( highest if a != highest else higher )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
fir=0
sec=0
a=[]
for _ in range(n):
    ak=int(input())
    a.append(ak)
    if ak>fir:
        fir=ak
    elif ak>sec:
        sec=ak
for ak in a:
    if ak==fir:
        print(sec)
    else:
        print(fir)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
ma=max(a)
ma_index=a.index(ma)
for i in range(n):
    if i==ma_index:
        print(max(a[:i]+a[i+1:]))
    else:
        print(ma)

Submission status: Accepted

Solution code:
n = int(input())
s = [int(input()) for _ in range(n)]
new_s = sorted(s, reverse=True)

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

Submission status: Accepted

Solution code:
n = int(input())
k, m=0, 0
p = []
for i in range(n):
    l = int(input())
    if l > m:
        m = l
        k = i
    p.append(l)
p.remove(p[k])
j = 0
for i in p:
    if i > j:
        j = i
for i in range(n):
    if i == k:
        print(j)
    else:
        print(m)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = [int(input()) for _ in range(n)]
mx = max(a)
b = sorted([x for x in a], reverse=True)
for x in a:
    print(b[x == b[0]])

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
SA = sorted(A)
max_1 = SA[-1]
max_2 = SA[-2]
for i in range(N):
  print(max_2 if A[i] == max_1 else max_1)

Submission status: Accepted

Solution code:
n = int(input())
L = [int(input()) for _ in range(n)]
sortedL = sorted(L)
max1 = sortedL[-1]
max2 = sortedL[-2]

count = L.count(max1)

if count == 1:
    for i in range(n):
        print(max2 if L[i] == max1 else max1)
else:
    for i in range(n):
        print(max1)

Submission status: Accepted

Solution code:
n = int(input())
arr = []
max_index = 0
max_num = 0
for i in range(n):
  tmp = int(input())
  arr.append(tmp)
  if tmp > max_num:
    max_num = tmp
    max_index = i

list.sort(arr, reverse=True)
if arr[0] == arr[1]:
  for i in range(n):
    print(max_num)

else:
  for i in range(n):
    if max_index == i:
      print(arr[1])
    else:
      print(max_num)

Submission status: Accepted

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

MAX = max(A)
cnt = 0
for i in range(N):
    if MAX == A[i]:
        cnt += 1

if cnt >= 2:
    for i in range(N):
        print(MAX)
    exit()
    
B = sorted(A)
nMAX = B[-2]
for i in range(N):
    if A[i] == MAX:
        print(nMAX)
    else:
        print(MAX)

Submission status: Accepted

Solution code:
N = int(input())
Second = 0
MaxA = 0

for x in range(N):
    A = int(input())
    if MaxA <= A:
        Second = MaxA
        MaxA = A
        i = x
        continue
    if Second < A:
        Second = A

for x in range(N):
    if x == i:
        print(Second)
    else:
        print(MaxA)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
max_a=max(a)
max_a_index=a.index(max_a)
a.pop(max_a_index)
semimax_a=max(a)
for i in range(n):
  if i!=max_a_index:
    print(max_a)
  else:
    print(semimax_a)

Submission status: Accepted

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

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

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

B.sort()
A0 = B[-1]
A1 = B[-2]

for i in A:
  if i == A0:
    print(A1)
  else:
    print(A0)

Submission status: Accepted

Solution code:
import bisect
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
INL=[]
for i in range(N):
    INL.append(II())
INL2=list(sorted(INL))
M = INL2[-1]

for i in INL:
    if i == M:
        if INL2[-2] == M:
            print(M)
        else:
            print(INL2[-2])
    else:
        print(M)

Submission status: Accepted

Solution code:
N = int(input())
A = [0] * N
f = s = 1
fi = si = 0
for i in range(N):
    A[i] = int(input())
    if A[i] > f:
        s = f
        si = fi
        f = A[i]
        fi = i
    elif A[i] > s:
        s = A[i]
        si = i
for i in range(N):
    if i != fi:
        print(f)
    else:
        print(s)

Submission status: Accepted

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

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

ma = max(A)
B = A.copy()
B.pop(A.index(ma))
sa = max(B)

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

Submission status: Accepted

Solution code:
N=int(input())
A=[]
max=0
count=0
point=0
for i in range(N):
    x=int(input())
    A.append(x)
    if x>max:
        max=x
        count=0

    if x==max:
        count+=1
        point=i

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