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: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
if len(set(a)) == 1:
    for i in range(n):
        print(sorted(set(a))[-1])
    exit()
x = sorted(set(a))[-1]
y = sorted(set(a))[-2]
for i in range(n):
    if a[i] != x:
        print(x)
    else:
        print(y)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
a_max = max(a)
a_second = sorted(a)[1]
for i in range(n):
	print(a_max if a[i] != a_max else a_second)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
a_max = max(a)
a_copy = a[:]
while a_max in a_copy:
	a_copy.remove(a_max)
if a_copy:
	for i in range(n):
		print(a_max if a[i] != a_max else max(a_copy))
else:
	for i in range(n):
		print(a_max)

Submission status: Wrong Answer

Solution code:
#ABC134 C

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
A.sort()
print(sum(A) - A[0])

Submission status: Wrong Answer

Solution code:
N = int(input())

l = []
for _ in range(N):
    l.append(input())

max_n = max(l)

for i in range(len(l)):
    tmp  = []
    if l[i] != max_n:
        print(max_n)
    else:
        for j in range(len(l)):
            if i == j:
                continue
            else:
                tmp.append(l[j])
        print(max(tmp))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = [int(input()) for i in range(n)]
m = list(set(a))
c =collections.Counter(a)

t = [max(a)]*n

if c[max(a)] == 1:
    t[a.index(max(a))] = m[-2]

[print(i) for i in t]

Submission status: Wrong Answer

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

for i in range(N):
    if i != A.index(max(A)):
        print(max(A))
    else:
        A.sort()
        print(A[N-2])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
B = sorted(set(A), key = A.index)
B = sorted(B, reverse = True)
max_A = B[0]
try:
  second_max = B[1]
except:
  second_max = B[0]
for i in range(N):
  if A[i] == max_A:
    print(second_max)
  else:
    print(max_A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import heapq

def main():
    numbers=[]
    n = int(input())
    [numbers.append(int(input().rstrip())) for _ in range(n)]
    heapq.heapify(numbers)

    for i in numbers:
        if i == max(numbers):
            print(min(heapq.nlargest(2,numbers)))
        else:
            print(max(heapq.nlargest(1,numbers)))
    

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
 
# max(A_2,A_3,...,A_N)
# max(A_1,A_3,...,A_N)
# max(A_1,A_2,...,A_(N-1))
 
M_1 = max(A)
M_2 = 0
for i in range(N):
  if A[i] != M_1:
    M_2 = max(M_2, A[i])

for i in range(N):
  if A[i] == M_1: print(M_2)
  else: print(M_1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
 
# max(A_2,A_3,...,A_N)
# max(A_1,A_3,...,A_N)
# max(A_1,A_2,...,A_(N-1))
 
M_1 = max(A)
M_2 = 0
for i in range(N):
  if A[i] != M_1:
    M_2 = max(M_2, A[i])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
max1 = [0,[]]
max2 = 0
for i in range(N):
  a = int(input())
  if a > max1[0]:
    max1[0] = a
    max1[1] = [i]
  elif a == max1[0]:
    max1[1].append(i)
  elif a > max2:
    max2 = a

if len(max1[1]) == 1:
  max1_idx = max1[1][0]
  for i in range(0,max1_idx):
    print(max1[0])
  print(max2)
  for i in range(max1_idx + 1 , N):
    print(max1[0])
else:
  for i in range(N):
    print(max1[0])

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(input()) for i in range(N)]
sw=True
b=sorted(a,reverse=True)

for j in range(N-1):
    if b[j]>b[j+1]:
        max2=b[j+1]
        max1=b[j]
        sw=False
        break

if sw==True:
    max1=b[0]
    for k in range(N):
        print(max1)
else:
    for k in range(N):
        if a[k]==max1:
            print(max2)
        else:
            print(max1)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=max(b)
if b.count(c)>1:
    for i in range(a):
        print(c)
elif b.count(c)==1:
    d=sorted(b)
    d=d[1]
    e=b.index(c)
    for i in range(a):
        if i==e:
            print(d)
        else:
            print(c)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=max(b)
if b.count(c)>1:
    for i in range(a):
        print(c)
else:
    d=sorted(b)
    d=d[1]
    for i in range(a):
        if i==b.index(c):
            print(d)
        else:
            print(c)

Submission status: Wrong Answer

Solution code:

N=int(input())
A=sorted([int(input()) for _ in range(N)])
B=A[:N-1]
for i in range(N):
    if  i==N-1:
        print(max(B))
    else:
        print(max(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_sort = sorted(a)
m1 = a[0]
m2 = a[1]
for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Submission status: Wrong Answer

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

m = max(a)
try:
    b = sorted(list(set(a)))[-2]
except:
    b = m

for i in range(t):
    if a[i] != m:
        print(m)
    else:
        print(b)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))
s=sorted(A)
for i in range(N):
  if A[i]!=s[0]:
    print(s[0])
  else:
    print(s[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [input() for _ in range(n)]
m1 = max(lis)
sort_lis = sorted(lis)
m2 = sort_lis[n-2]

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

Submission status: Wrong Answer

Solution code:
from heapq import nlargest
import sys
n = int(input())
a = [int(input()) for i in range(n)]
l1, l2 = nlargest(2, a)

if l1 == l2:
  for i in range(n):
    print(l1)
  sys.exit()

for i in a:
  if a == l1:
    print(l2)
  else:
    print(l1)

Submission status: Wrong Answer

Solution code:
from heapq import nlargest
n = int(input())
a = [int(input()) for i in range(n)]
l1, l2 = nlargest(2, a)

for i in a:
  if a == l1:
    print(l2)
  else:
    print(l1)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 134
# C - Exception Handling

N=int(input())
ls = []
lsmax=0
lsmaxnum=0
lsmax2=0
for i in range (N):
    a=int(input())
    ls.append(a)
    if a==lsmax:
        lsmaxnum+=1
    if a>lsmax:
        lsmax=a
if lsmaxnum==1:
    ls2=sorted(ls)
    lsmax2=ls2[-2]

# print(lsmax,lsmax2,lsmaxnum)

for j in range (N):
    if ls[j]==lsmax:
        if lsmaxnum>1:
            print(lsmax)
        else:
            print(lsmax2)
    else:
        print(lsmax)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 134
# C - Exception Handling

N=int(input())
ls = []
lsmax=1
lsmaxnum=1
lsmax2=1
for i in range (N):
    a=int(input())
    ls.append(a)
    if a==lsmax:
        lsmaxnum+=1
    if a>lsmax:
        lsmax=a
if lsmaxnum==1:
    ls2=sorted(ls)
    lsmax2=ls2[-2]

# print(lsmax,lsmax2,lsmaxnum)

for j in range (N):
    if ls[j]==lsmax:
        if lsmaxnum>1:
            print(lsmax)
        else:
            print(lsmax2)
    else:
        print(lsmax)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 134
# C - Exception Handling

N=int(input())
ls = []
lsmax=0
lsmaxnum=1
lsmax2=0
for i in range (N):
    a=int(input())
    ls.append(a)
    if a==lsmax:
        lsmaxnum+=1
    if a>lsmax:
        lsmax=a
if lsmaxnum==1:
    ls2=sorted(ls)
    lsmax2=ls2[-2]

# print(lsmax,lsmax2,lsmaxnum)

for j in range (N):
    if ls[j]==lsmax:
        if lsmaxnum>1:
            print(lsmax)
        else:
            print(lsmax2)
    else:
        print(lsmax)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
m = []

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

x = 0
y = 0
count = 0

for i in l:
    for j in l:
        if i == j:
            count += 1

for i in l:
    if i > x:
        x = i
        
if count > 2:
    for i in range(n):
        print(x)

else:
    for i in l:
        if i != x:
            m.append(i)

    for i in m:
        if i > y:
            y = i
    
    for i in l:
        if i != x:
            print(x)
        else:
            print(y)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [int(input()) for _ in range(N)]
arr2 = sorted(arr)
for i in range(N):
    print(arr2[-2] if arr[i] == arr[-1] else arr2[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [int(input()) for _ in range(N)]
arr2 = sorted(arr)
for i in range(N):
    print(arr2[-2] if arr[i] == arr[-1] else arr[-1])

Submission status: Wrong Answer

Solution code:
# C - Exception Handling
N = int(input())
A = list(int(input()) for _ in range(N))
A_sorted = list((sorted(set(A), reverse = True)))
A_sorted = A_sorted[0:2]

ans = []
if len(A_sorted) == 1:
    for i in A:
        ans.append(A_sorted[0])
else:
    for i in A:
        if i == A_sorted[0]:
            ans.append(A_sorted[1])
        else:
            ans.append(A_sorted[0])

for j in ans:
    print(j)

Submission status: Wrong Answer

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

mls = [-1 for _ in range(N+1)]
for i, a in enumerate(A, 1):
    mls[i] = max(mls[i-1], a)

mrs = [-1 for _ in range(N+1)]
for i, a in enumerate(A[::-1], 1):
    mrs[i] = max(mls[i-1], a)
mrs = mrs[::-1]

for i in range(N):
    print(max(mls[i], mrs[i+1]))

Submission status: Wrong Answer

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    m = max(a)
    s = sorted(a)[1]
    for i in a:
        if i == m:
            print(s)
        else:
            print(m)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
'''ABC134 C'''
import numpy as np
n = int(input())
a = np.array([int(input()) for _ in range(n)])
a1n = a.argmax()
a_s = sorted(a)
a1 = a_s[-1]
a2 = a_s[-2]
for i in range(n):
    if i == a1n:
        print(a1)
    else:
        print(a2)

Submission status: Wrong Answer

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

if n == 2:
    print(a[1])
    print(a[0])
    exit()

first, second = 0, 0
for i in range(1, n):
    if a[i] >= second:
        if a[0] >= first:
            second = first
            first = a[i]
        else:
            second = a[i]

print(first)

if a[0] >= second:
    if a[0] >= first:
        second = first
        first = a[0]
    else:
        second = a[0]

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

Submission status: Wrong Answer

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

if n == 2:
    print(a[1])
    print(a[0])
    exit()

first, second = 0, 0
for i in range(1, n):
    if a[i] > second and a[i] != first:
        if a[0] > first:
            second = first
            first = a[i]
        else:
            second = a[i]

print(first)

if a[0] > second:
    if a[0] > first and a[i] != first:
        second = first
        first = a[0]
    else:
        second = a[0]

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

Submission status: Wrong Answer

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

if n == 2:
    print(a[1])
    print(a[0])
    exit()

first, second = 0, 0
for i in range(1, n):
    if a[i] > second:
        if a[0] > first:
            second = first
            first = a[i]
        else:
            second = a[i]

print(first)

if a[0] > second:
    if a[0] > first:
        second = first
        first = a[0]
    else:
        second = a[0]

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

Submission status: Wrong Answer

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

if n == 2:
    print(a[0])
    print(a[1])
    exit()

first, second = 0, 0
for i in range(1, n):
    if a[i] > second:
        if a[0] > first:
            second = first
            first = a[i]
        else:
            second = a[i]

print(first)

if a[0] > second:
    if a[0] > first:
        second = first
        first = a[0]
    else:
        second = a[0]

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

Submission status: Wrong Answer

Solution code:
import sys
from copy import copy

input = sys.stdin.readline
max_a = 0
big_a = 0
max_index = set()
big_index = set()
n = int(input())
for i in range(n):
    a = int(input())
    if max_a < a:
        big_index = max_index.copy()
        max_index.clear()
        max_index.add(i)
        big_a = max_a
        max_a = a
    elif max_a == a:
        max_index.add(i)
    elif big_a < a:
        big_index.clear()
        big_index.add(i)
        big_a = a
    elif big_a == a:
        big_index.add(i)
    else:
        continue

if big_a == 0:
    big_a = max_a

for i in range(n):
    if i in max_index:
        print(big_a)
    else:
        print(max_a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

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

for i in a:
    print(max(a[:i]+a[i+1:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
sa = a.sort()
am, asl = a[-1], a[-2]
for i in range(n):
    print(asl if a[i] == am else am)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
l = [int(input()) for _ in range(n)] #複数行1文字をintでリストに
a=max(l)
l1=list(dict.fromkeys(l))
l1.remove(a)
if l1==[]:
  for i in l:
    print(i)
  sys.exit()
b=max(l1)
for i in l:
  if i==a:
    print(b)
  else:
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for a in range(N)]
maxnum = max(A)
maxcount = A.count(maxnum)
s = sorted(A)
if maxcount == 1:
  index = A.index(maxnum)
  ans = [maxnum] * N
  ans[index] = s[1]
else:
  ans = [maxnum] * N
for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for i in range(N)]
m1, m2 = max(A[0], A[1]), min(A[0], A[1])
for i in range(2,N):
    if m1 < A[i]:
        m1, m2 = A[i], m1
    elif m2 < A[i]:
        m2 = A[i]
print("\n".join(map(str, [m1 if i != m1 else m2 for i in A])))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
f = 0
s = 0
for _ in range(n):
  a = int(input())
  if f >= a:
    s = f
    f = a

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

Submission status: Wrong Answer

Solution code:
N = int(input())
number = []
for i in range(N):
    number.append(int(input()))
    
if N == 2:
    print(number[0])
    print(number[1])
    exit()
    
if N == 3:
    print(max(number[1:]))
    print(max(number[2:]))
    print(max(number[:2]))    
    exit()
    
print(max(number[1:]))
for i in range(1,N-1):
    max_low = max(number[:i])
    max_upp = max(number[i+1:])
    print(max(max_low,max_upp))
print(max(number[:-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = set(a)
b = sorted(b,reverse = True)
max1 = b[0]
max2 = b[1] if len(b) > 1 else b[0]
for i in a:
    print(max2 if i == max1 else max1)

Submission status: Wrong Answer

Solution code:
import math
import collections
def main():
    n = int(input())
    s = []
    dd = collections.defaultdict(int)
    for i in range(n):
        a  = int(input())
        dd[a]+=1
        s.append(a)
    k = max(dd.keys())
    lis = sorted(list(dd.keys()),reverse = True)

    for i in range(n):
        if(s[i]==k and dd[i]==1):
            print(lis[1])
        else:
            print(k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[0]*n
for i in range(n):
  arr[i]=int(input())
tmp=sorted(arr,reverse=True)
arrMax=tmp[0]

for i in range(n):
  if arr[i]==arrMax:
    if tmp[0]==tmp[1]:
      print(tmp[1])
    else:
      print(tmp[0])
  else:
    print(tmp[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
for i in range(n):
    num=max(a)
    if a.index(num)==i:
        aa=sorted(a)
        print(a[-2])
    else:
        print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(input())
B = sorted(A)
a = B[-1]
b = B[-2]
c = A.index(a)
for j in range(N):
    if j == c:
        print(b)
        continue
    print(a)

Submission status: Wrong Answer

Solution code:

def solve():
    for i in range(N):
#        print("----------")
        if i == 0:
            print(max(A[i:N]))
        elif i == N-1:
            print(max(A[:N]))
        else:
            a = max(A[:i])
            b = max(A[i+1:N])
            print(max(a,b))
#        print(A[:i], A[i+1:N])

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

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = [I() for _ in range(N)]
    
    A_first = max(A)
    A_second = 0
    if len(set(A)) == 1:
        A_second = A_first
    else:
        for i in A:
            if i != A_first:
                A_second = max(i, A_second)

    for i in A:
        if i == A_first:
            print(A_second)
        else:
            print(A_first)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = [I() for _ in range(N)]
    
    A_first = max(A)
    A_second = 0
    for i in A:
        if i != A_first:
            A_second = max(i, A_second)

    for i in A:
        if i == A_first:
            if A_second == 0:
                print(A_first)
            else:
                print(A_second)
        else:
            print(A_first)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = [I() for _ in range(N)]
    
    A_first = max(A)
    A_second = 0
    for i in A:
        if i != A_first:
            A_second = min(i, A_second)

    for i in A:
        if i == A_first:
            print(A_second)
        else:
            print(A_first)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

new_l = sorted(l)

fmax = new_l[N-1]
smax = fmax

for j in reversed(range(N)):
    if not new_l[j] == fmax:
        smax = new_l[j]
        break

for k in range(N):
    if not l[k] == fmax:
        print(fmax)
    else:
        print(smax)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array([int(input()) for i in range(n)])

amax_i = np.argmax(a)
if amax_i == n-1:
    b = a[:amax_i]
else:
    b = np.hstack([a[:amax_i], a[amax_i+1]])
bmax = np.max(b)

for i in range(n):
    if i == amax_i:
        print(bmax)
    else:
        print(a[amax_i])

Submission status: Wrong Answer

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

A_sort = sorted(A)
A_max = A_sort[-1]
A_max2 = A_sort[-2]

for i in range(N):
    if A[i]==A_max:
        print(A_max2)
    else:
        print(A_max)

Submission status: Wrong Answer

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

A_sort = sorted(A)
A_max = A_sort[-1]

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

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
M = sorted(A)
if M[-1] == M[-2]:
    for i in range(N):
        print(M[-1])
    sys.exit()
high_num = M[-1]
print(high_num)
print(A)
for i in range(N):
    if A[i] == high_num:
        print(M[-2])
    else:
        print(M[-1])

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
for i in range(n):
    a_copy = copy.deepcopy(a)
    a_copy.pop()
    print(max(a_copy))

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
a = [int(input()) for _ in range(n)]
a_down = sorted(a, reverse=True)
for i in range(n):
    a_down_copy = copy.deepcopy(a_down)
    while a[i] == max(a_down_copy):
        if max(a_down_copy) == min(a_down_copy):
            break
        a_down_copy.pop(0)
    print(max(a_down_copy))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    j = int(input())
    a.append(j)
for i in range(n):
    s = a.pop()
    m = max(a)
    print(m)
    a.appendleft(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
print(A)
M=max(A)
sort_A=sorted(A, reverse=True)

for j in range(N):
    if A[j]==M:
        if A.count(M)==1:
            print(sort_A[1])
        else:
            print(M)
    else:
        print(M)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
B = A
A.sort(reverse=True)


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

Submission status: Wrong Answer

Solution code:
import heapq

num = int(input())
a = [int(input()) for i in range(num)]
b = [max(a) for f in range(num)]
if sorted(a)[0] == sorted(a)[1]:
  for j in b:
    print(j)
else:
  b[a.index(max(a))] = sorted(a)[1]
  for j in b:
    print(j)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

copy_a = sorted(a, reverse=True)

A_Max = a[0]
A_Second = a[1]

for x in range(n):
    if copy_a[x] == A_Max:
        print(A_Second)
    else:
        print(A_Max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

copy_a = sorted(a)

a.sort(reverse=True)
A_Max = a[0]
A_Second = a[1]

for x in range(n):
    if copy_a[x] == A_Max:
        print(A_Second)
    else:
        print(A_Max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

sumNum = sum(a)

for x in range(n):
    print(sumNum-a[x])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

sumNum = sum(a)

for x in range(n):
    print(sumNum-x)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [int(input()) for i in range(n)]
a_max = max(a)
a2 = a[:]
a2.remove(a_max)
a_second_max = max(a2)

for i in range(n):
    if i == max:
        print(a_second_max)
    else:
        print(a_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
B = list(set(A))
B.sort()
B.reverse()
if len(B) == 1:
  for i in range(N):
    print(B[0])
else:
  for i in range(N):
    if A[i] == B[0]:
      print(B[1])
    else:
      print(B[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=list(set(a))
if len(b)==1:
  for i in range(n):
    print(b[0])
elif a.count(b[-1])>=2:
  for i in a:
    print(i)
else:
  for i in a:
    if i==b[-1]:
      print(b[-2])
    else:
      print(b[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=list(set(a))
if len(b)==1:
  for i in range(n):
    print(b[0])
else:
  for i in a:
    if i==b[-1]:
      print(b[-2])
    else:
      print(b[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
a = [int(input()) for _ in range(n)]
m1, m2 = heapq.nlargest(2, a)
for ai in a:
  print(ai if ai != m1 else m2)

Submission status: Wrong Answer

Solution code:
def solve():
    n=int(input())
    num=[]
    def append(num1):
        num.append(num1)
    def count1(num2):
        return num.count(num2)
    for i in range(n):
        a=int(input())
        append(a)
    max1=max(num)
    count=count1(max1)
    if count>1:
        for i in range(n):
            print(num[i])
    else:
        for i in range(n):
            if num[i]==max1:
                if i==0:
                    print(max(num[1:]))
                elif i==n-1:
                    print(max(num[:n-1]))
                else:
                    print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n=int(input())
    num=[]
    def append(num1):
        num.append(num1)
    def count1(num2):
        return num.count(num2)
    for i in range(n):
        a=int(input())
        append(a)
    max1=max(num)
    count=count1(max1)
    if count!=1:
        for i in range(n):
            print(num[i])
    else:
        for i in range(n):
            if num[i]==max1:
                if i==0:
                    print(max(num[1:]))
                elif i==n-1:
                    print(max(num[:n-1]))
                else:
                    print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()

Submission status: Wrong Answer

Solution code:
def solve():
    n=int(input())
    max1=0
    max2=0
    count=0
    num=[]
    def append(num1):
        num.append(num1)
    for i in range(n):
        a=int(input())
        if max1<a:
            count=1
            max2=max(max2,max1)
            max1=a
        elif max1==a:
            count+=1
        elif max2<a:
            max2=a
        append(a)
    if count!=1:
        for i in range(n):
            print(num[i])
    else:
        for i in range(n):
            if num[i]==max1:
                print(max2)
            else:
                print(max1)
solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_sorted = sorted(A, reverse=True)
    A_max = A_sorted[0]
    found_semi_max = False
    for i in range(N):
        if A_max != A_sorted[i]:
            A_semi_max = A_sorted[i]
            found_semi_max = True
            break
    
    for i in range(N):
        if found_semi_max:
            if A[i] != A_max:
                print(A_max)
            else:
                print(A_semi_max)
        else:
            print(A_max)
main()