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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for _ in range(N)]

A_sort = sorted(A)

index = 0
for i in range(N - 1):
	if A[i] < A[i + 1]:
		index = i + 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(int(input()) for _ in range(n))

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

Submission status: Wrong Answer

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

first = 0
second = 0
for i in range(1, n):
    if A[first] < A[i]:
        second = first
        first = i
    elif A[second] < A[i]:
        second = i

print(*[A[first] if i != first else A[second] for i in range(n)], sep='\n')

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    A=[0 for i in range(0,N)]
    for i in range(0,N):
        A[i]=int(input())
    L=[0 for i in range(0,N)]
    R=[0 for i in range(0,N)]
    L[0]=A[0]
    R[0]=A[N-1]
    for i in range(0,N-1):
        L[i+1]=max(A[i+1],L[i])
        R[i+1]=max(A[N-i-2],R[i])
    for i in range(0,N):
        if i==0:
            print(R[N-2])
        elif i==N-1:
            print(L[N-2])
        else:
            print(max(L[i-1],R[i-1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    A=[0 for i in range(0,N)]
    for i in range(0,N):
        A[i]=int(input())
    L=[0 for i in range(0,N)]
    R=[0 for i in range(0,N)]
    L[0]=A[0]
    R[0]=A[N-1]
    for i in range(0,N-1):
        L[i+1]=max(A[i+1],L[i])
        R[i+1]=max(A[N-i-2],R[i])
    print(L,R)
    for i in range(0,N):
        if i==0:
            print(R[N-2])
        elif i==N-1:
            print(L[N-2])
        else:
            print(max(L[i-1],R[i-1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = [input() for i in range(n)]
a_max = max(a_list)
a_max2 = sorted(a_list)[-2]
for i in a_list:
    if i == a_max:
        print(a_max2)
    else:
        print(a_max)

Submission status: Wrong Answer

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

max_A = max(A)
sorted_A = list(sorted(list(set(A))))
for i in range(N):
    if A[i] == max_A:
        print(sorted_A[len(sorted_A)-2])
    else:
        print(max_A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
AL = [0] * (N+1)
AR = [0] * (N+1) 
for i in range(N):
    AL[i+1] = max(AL[i], A[i])
for i in range(N):
    AR[i] = max(AR[i+1], A[i])
for i in range(N):
    print(max(AL[i], AR[i+1]))

Submission status: Wrong Answer

Solution code:
# import itertools
# import math

import copy
import sys
input = sys.stdin.readline


def solve(N, A):
    for i in range(N - 1):
        tmp = copy.copy(A)
        tmp.pop(i)
        print(max(tmp))


N = int(input())
# S = input()
# A, B = map(int, input().split())
# A = list(map(int, input().split()))


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


solve(N, A)

Submission status: Wrong Answer

Solution code:
# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, A):
    for i in range(N - 1):
        tmp = A
        tmp.pop(i)
        print(max(tmp))


N = int(input())
# S = input()
# A, B = map(int, input().split())
# A = list(map(int, input().split()))


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


solve(N, A)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
max1 = 0
max2 = -1
for i in range(N):
  a = int(input())
  A.append(a)
  if max1 <= a:
    max1 = a
  else:
    if max2 <= a:
      max2 = a
if A.count(max1) >= 2:
  for i in range(N):
    print(max1)
else:
  for a in A:
    if a == max1:
      print(max2)
    else:
      print(max1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
a = int(input())
M1 = a
M2 = a
A.append(a)
for i in range(N-1):
    a = int(input())
    A.append(a)
    M1 = max(M1,a)
    if M2 < a < M1:
        M2 = a

if A.count(M1) >= 2:
    for i in range(N):
        print(M1)
else:
    for i in range(N):
        if A[i] == M1:
            print(M2)
        else:
            print(M1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
M1 = 0
M2 = 0
for i in range(N):
    a = int(input())
    A.append(a)
    M1 = max(M1,a)
    if M2 < a < M1:
        M2 = a

if A.count(M1) >= 2:
    for i in range(N):
        print(M1)
else:
    for i in range(N):
        if A[i] == M1:
            print(M2)
        else:
            print(M1)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = []
max1 = 0
max2 = 0
for i in range(N):
  s = int(input())
  li.append(s)
  
  if s > max1:
    max1 = s
    
  if max1 >= s > max2:
    max2 = s

for index, i in enumerate(li):
  if max1 == li[index]:
    print(max2)
  else:
    print(max1)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = []
max1 = 0
max2 = 0
for i in range(N):
  s = int(input())
  li.append(s)
  
  if s > max1:
    max1 = s
    
  if max1 > s > max2:
    max2 = s

for index, i in enumerate(li):
  s = max(li)
  
  if s == li[index]:
    print(max2)
  else:
    print(max1)

Submission status: Wrong Answer

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

for index, i in enumerate(li):
  new = sorted(li)
  
  s = max(li)
  
  if s == li[index]:
    print(new[1])
  else:
    print(s)

Submission status: Wrong Answer

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

for i in range(N):

    if (l[i] != l_sort[-1]):
        print(l_sort[-2])
    else:
        print(l_sort[-1])

Submission status: Wrong Answer

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

def remove_one(num, A):
    
    B = []
    N = len(A)

    if (num == 0):
        B = A[1:]
    elif (num == N):
        B = A[:N-1]
    else:
        B = A[:i-1] + A[i+1:]
    
    return(B)


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

for i in range(N):
    B = remove_one(i+1,A)
    print(max(B))

Submission status: Wrong Answer

Solution code:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[1]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
            continue
        print(max_first)
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[1]

    print(max_first,max_second)
    
    for num in num_list:
        if num == max_first:
            print(max_second)
            continue
        print(max_first)
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

def main():
    n = int(input())
    num_list = [int(input()) for _ in range(n)]

    tmp = copy.deepcopy(num_list)
    tmp.sort()

    max_first = max(num_list)
    max_second = tmp[1]
    
    for num in num_list:
        if num == max_first:
            print(max_second)
        else:
            print(max_first)
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list()
for i in range (n):
    a.append(int(input()))
new_a=sorted(a)
max=new_a[0]
max2=new_a[1]
for i in a:
    if(i==max):
        print(max2)
    else:
        print(max)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
new_a=sorted(a)
max=new_a[0]
max2=new_a[1]
for i in a:
    if(i==max):
        print(max2)
    else:
        print(max)

Submission status: Wrong Answer

Solution code:
n=int(input())
imax=0
amax=int(input())
amax2=amax
for i in range(1,n):
    ai=int(input())
    if amax<ai:
        adummy=amax
        amax=ai
        imax=i
        amax2=adummy
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
        print(amax)

Submission status: Wrong Answer

Solution code:
n=int(input())
imax=0
amax=int(input())
amax2=amax
for i in range(1,n):
    ai=int(input())
    if amax<ai:
        amax=ai
        imax=i
        if amax2<ai:
          amax2=ai
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
        print(amax)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=int(input())
f,v,w=0,a,a
for i in range(1,n):
    a=int(input())
    if a>=v:
        w,v,f=v,a,i
    elif a>=w:
        w=a
for i in range(n):
    if i==f:
        print(w)
    else:
        print(v)

Submission status: Wrong Answer

Solution code:
import copy
def test(a_,n_):
    return abs(int(0.1/(n_-(a_+0.1))))

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_max = sum(x == a_max for x in a)
if n_max > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    #a_max_2=sorted(set(a))[-2]
    b = copy.copy(a)
    b.remove(a_max)
    a_max_2 = max(b)
    for i in a:
        x = test(i, a_max)
        print((1-x)*a_max + x*a_max_2)

Submission status: Wrong Answer

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



m1=max(A)
l1=A.index(m1)
A.pop(l1)
m2=max(A)
l2=A.index(m2)

for i in range(0,N):
    if i==l1:
        print(m2)
    else:
        print(m1)

Submission status: Wrong Answer

Solution code:
n = int(input())
H = list(map(int,input().split()))

tmp = H[0]
for k in H:
    if tmp - k > 1:
        print('No')
        exit()
    if k > tmp:
        tmp = k
print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    
    max_A = max(A)
    B = sorted(A)
    max2_A = B[N-2]
    
    if max_A == max2_A:
        for i in range(N):
            print(max_A)
            exit()
    
    for i in range(N):
        tmp=A[i]
        if tmp == max_A:
            print(max2_A)
        else:
            print(max_A)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
cache = sorted(nums)
maximum = nums[0]
second = nums[1]
if maximum == second:
  flag = True
else:
  flag = False
for i in nums:
  if i == maximum and not flag:
    print(second)
  else:
    print(maximum)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
cache = sorted(nums)
maximum = nums[0]
second = nums[1]
for i in nums:
  if i == maximum:
    print(second)
  else:
    print(maximum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
  
maxA = sorted(set(A), reverse=True)
maxA1 = maxA[0]
maxA2 = -1 if len(maxA) == 1 else maxA[1]

for i in range(N):
  if A[i] == maxA1 and maxA2 != -1:
    print(maxA2)
  else:
    print(maxA1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
  
maxA = sorted(set(A), reverse=True)
maxA1 = maxA[0]
maxA2 = 0 if len(maxA) == 1 else maxA[1]

for i in range(N):
  if A[i] == maxA1 and maxA2 != 0:
    print(maxA2)
  else:
    print(maxA1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
  
maxA = max(A)
for i in range(N):
  if A[i] == maxA:
    print(max(A[:i], A[i+1:])[0])
  else:
    print(max(A[i], maxA))

Submission status: Wrong Answer

Solution code:
N = int(input())
list_A = []
for _ in range(N):
    A = int(input())
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)
for i in range(N):
    if list_A[i] == A:
      list_B = sorted(list_A, reverse=True)
      B = list_B[1]
    else:
      print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
for i in range(N):
    if A[0] != max(A):
        print(max(A))
    else:
        B = A.copy()
        del B[i]
        print(max(B))

Submission status: Wrong Answer

Solution code:
n=int(input())

a=[]
sub=[]
first=-1

for i in range(n):
    inp = int(input())
    a.append(inp)
    if inp >= first:
        first = inp

b=sorted(list(set(a)))

if len(b)==1:
    second=first
else:
    second=b[-2]

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

Submission status: Wrong Answer

Solution code:
n=int(input())

a=[]
sub=[]
first=-1

for i in range(n):
    inp = int(input())
    a.append(inp)
    if inp > first:
        first = inp

b=list(set(sorted(a)))
if len(b)==1:
    second=first
else:
    second=b[-2]

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
if B.count(max(B))==1:
    B.remove(max(B))
    b=max(B)
else:
    b=max(B)
print(A)
for j in range(N):
    if A[j]==max(A):
        print(b)
    else:
        print(max(A))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
f=max(a)
b=sorted(a)
s=b[1]
for i in range(n):
    if a[i]==f:
        print(s)
    else:
        print(f)

Submission status: Wrong Answer

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

for _ in range(N):
    A = int(input())
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
SA = list(reversed(sorted(set(A))))
l = len(SA)
if l == 1:
    for n in range(N):
        print(SA[0])
else:
    for a in A:
        for sa in SA:
            if a == sa:
                continue
            print(sa)
            break

Submission status: Wrong Answer

Solution code:
import sys

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

    print(A)

    for j in range(N):
        if j == 0:
            print(max(A[1:]))

        elif j == N-1:
            print(max(A[:N-1]))

        else:
            print(max(max(A[:j]), max(A[j+1:])))


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input() for i in range(n))
M = max(a)

if a.count(M) > 1:
  for i in range(n):
    print(M)
elif n == 1:
  print(M)
else:
  M2 = sorted(set(a))[-2]
  for i in range(n):
    if a[i] == M:
      print(M2)
    else:
      print(M)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input() for i in range(n))
M = max(a)

if a.count(M) > 1:
  for i in range(n):
    print(M)
else:
  M2 = sorted(set(a))[-2]
  for i in range(n):
    if a[i] == M:
      print(M2)
    else:
      print(M)

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
l.sort()
setl=list(set(l))
setl.sort()
m=max(l)

for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=l[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
setl=list(set(l))
setl.sort()
m=max(l)

for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=setl[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
setl=list(set(l))
setl.sort()
m=max(l)
print(m)
print(setl)
print(l)
for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=setl[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
setl=list(set(l))
m=max(l)

for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=setl[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
setl=list(set(l))
m=max(l)
if len(setl)==1:
    print(m)
    exit()
else:
    second=setl[-2]
for i in range(n):
    if l[i]==m:
        print(second)
    else:
        print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
l=[int(input()) for x in range(n)]
sub=copy.copy(l)
sub.sort()
sub=list(set(sub))
for i in range(n):
    if len(sub)==1:
        print(max(l))
    else:
        if l[i]==max(l):
            print(sub[-2])
        else:
            print(max(l))

Submission status: Wrong Answer

Solution code:
N = int(input())

one = (0, 0)
two = (0, 0)
for i in range(N):
    A = int(input())
    if A > one[0]:
        two = one
        one = (A, i)
    elif A > two[0]:
        two = (A, i)

print(one)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
f = 0
s = 0
c = 0
A = []

for i in range(N):
    A.append(int(input().strip()))
    if f < A[i]:
        f = A[i]
    
    if s < A[i] and A[i] < f:
        s = A[i]
        c += 1
        if c >= 2:
            s = f

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

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
f = 0
s = 0
A = []
for i in range(N):
    A.append(int(input().strip()))
    if f < A[i]:
        f = A[i]
    
    if s < A[i] and A[i] < f:
        s = A[i]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
alist=[int(input()) for i in range(n)]
b=sorted(alist, reverse=True)
for a in alist:
    if a < b[0]:
        print(b[1])
    elif b[0] <= a:
        print(b[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a = [int(input()) for i in range(n)]
b=sorted(a)
x=a[-1]
y=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()))

max_a = max(A)

if len(set(A)) == 1:
    sub_max_a = max_a
else:
    sub_max_a = sorted(list(set(A)))[-2]

for i in A:
    if i == max_a:
        print(sub_max_a)
    else:
        print(max_a)

Submission status: Wrong Answer

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

def main():
    n = int(input())
    a = [input() for _ in range(n)]
    max_a2, max_a = sorted(a)[-2:]
    print('\n'.join([max_a if i != max_a else max_a2 for i in a]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
    a=int(input())
    l.append(a)
for i in range(n):
    l[i]= -1
    print(max(l))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = sorted(A)
for i in range(N):
    if A[i] != A_sorted[-1]:
        print(A_sorted[-1])
    else:
        j = len(A_sorted) - 1
        count = 0
        while A[i] == A_sorted[j] and count < 0:
            j -= 1
            count += 1
        print(A_sorted[j])

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())

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

Submission status: Wrong Answer

Solution code:
import sys
a = int(input())
a_list = []
for i in range(a):
    a_list.append(int(input()))
max_num = max(a_list)
if a_list.count(max_num) != 1:
    for i in range(a):
        print(max_num)
        sys.exit()
else:
    sec_num = sorted(a_list)[-2]
for i in a_list:
    if i == max_num:
        print(sec_num)
    else:
        print(max_num)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
max1=0
ind1=0
max2=0
ind2=0
for i in range(N):
	A.append(int(input()))
	if max1 <= A[i]:	
		max2=max1
		ind2=ind1
		max1=A[i]
		ind1=i
for i in range(N):
	if max1 == A[i]:
		print(max2)
	else:
		print(max1)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]
    a_count = a_list.count(a_first)

    if a_count >= 2:
        for a in a_list:
            print(a)
    else:
        for a in a_list:
            if a == a_first:
                print(a_second)
            else:
                print(a_first)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def exception_handling(N: int, A: list)->list:
    max_num_1, max_num_2 = 0, 0
    max_1, max_2 = 0, 0

    for a in A:
        if a > max_1:
            max_1 = a
            max_num_1 = 1
        elif a == max_1:
            max_num_1 += 1
        elif a > max_2:
            max_2 = a
            max_num_2 = 1
        elif a == max_2:
            max_num_2 += 1

    if max_num_1 > 1:
        return [max_1] * N
    return [max_2 if a == max_1 else max_1 for a in A]


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = exception_handling(N, A)
    for a in ans:
        print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import copy
 
N = int(input())
 
A = []
for n in range(N):
    A.append(int(input()))
A_copy = copy.copy(A)
max_A = max(A)
max_c = A.count(max_A)

for i in range(n):
    if A[i] != max_A :
        print(max_A)
    else:
        if max_c == 1:
            A[i] = 0
            print(max(A))
        else:
            print(max_A)

Submission status: Wrong Answer

Solution code:
N = int(input())
max_1st = -1
max_1st_index = -1
max_2nd = -1
for i in range(0, N):
  if i == 0:
    max_1st = int(input())
    max_1st_index = 0
  elif i == 1:
    tmp = int(input())
    if (tmp >= max_1st):
      max_1st, max_2nd = tmp, max_1st
      max_1st_index = 1
    else:
      max_2nd = tmp
  else:
    tmp = int(input())
    if (max_2nd < tmp) and (tmp < max_1st):
      max_2nd = tmp
    elif (max_1st < tmp):
      max_1st, max_1st_index = tmp, i

for j in range(0, N):
  if j == max_1st_index:
    print(max_2nd)
  else:
    print(max_1st)

Submission status: Wrong Answer

Solution code:
N = int(input())
max_1st = -1
max_1st_index = -1
max_2nd = -1
for i in range(0, N):
  if i == 0:
    max_1st = int(input())
    max_1st_index = 0
  elif i == 1:
    tmp = int(input())
    if (tmp > max_1st):
      max_1st, max_2nd = tmp, max_1st
      max_1st_index = 1
    else:
      max_2nd = tmp
  else:
    tmp = int(input())
    if (max_2nd < tmp) and (tmp < max_1st):
      max_2nd = tmp
    elif (max_1st < tmp):
      max_1st, max_1st_index = tmp, i

for j in range(0, N):
  if j == max_1st_index:
    print(max_2nd)
  else:
    print(max_1st)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

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

max_1 = 0
max_2 = 0
max_index = -1
for i in range(N):
    if A[i] > max_1:
        max_1 = A[i]
        max_index = i
    elif a > max_2:
        max_2 = A[i]

for i in range(N):
    if max_1 == max_2:
        print(max_1)
    else:
        if i == max_index:
            print(max_2)
        else:
            print(max_1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=[a[i] for i in range(n)]
sorted(b)
m=b[n-1]
m2=b[n-2]
for i in range(n):
  if a[i]!=m:
    print(m)
  else:
    print(m2)

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
a=[-int(input()) for i in range(n)]
heapq.heapify(a)
for i in range(n):
  x=a[:i]+a[i+1:]
  print(-heapq.heappop(x))

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
a=[-int(input()) for i in range(n)]
for i in range(n):
  x=a[:i]+a[i+1:]
  print(-heapq.heappop(x))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    List = [int(input()) for x in range(N)]
    List_pre = []
    for i in range(N-1):
        List_pre = List
        List_pre.pop(i)
        print(max(List_pre))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = [int(input()) for _ in range(n)]
a_max_1 = max(a)
a_max_2 = a_max_1
b = sorted(a, reverse=True)
for i in b:
    if i != a_max_1:
        a_max_2 = i
        break

for i in range(n):
    if a[i] == a_max_1:
        print(a_max_2)
    else:
        print(a_max_1)

Submission status: Wrong Answer

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

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

ma = max(a)
max_i = a.index(ma)
b = []

for j in range(n):
    if j != max_i:
        b.append(a[i])

mb = max(b)

for i in range(n):
    if i != max_i:
        print(ma)
    else:
        print(mb)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
amax=max(a)
a.remove(amax)
bmax=max(a)
a.append(amax)
for i in range(n):
  if max(a)==a[i]:
    print(bmax)
  else:
    print(amax)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
amax=max(a)
for i in range(n):
  if max(a)==a[i]:
    a[i]=0
    print(max(a))
  else:
    print(amax)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())
for i in range(n):
  print(max(a[(i+1)%n], a[(i+2)%n]))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

m = max(a)

aa = []
for i in range(n):
	if a[i] == m:
		aa.append(min(a))
	else:
		aa.append(a[i])
ma = max(aa)

for i in range(n):
	if a[i] == m:
		print(ma)
	else:
		print(m)

Submission status: Wrong Answer

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

left_i = [0] * N
right_i = [0] * N

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

for i in range(N):
    print(max(left_i[i], right_i[N-1-i]))

Submission status: Wrong Answer

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

R = sorted(L)
a = R[-2]
b = R[-1]

for i in L:
  if i == b:
    print(b)
  else:
    print(a)

Submission status: Wrong Answer

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

mx = max(lst)
lst = sorted(lst)
mx2 = lst[-2]

for j in range(N):
    if mx != lst[j]:
        print(mx)
    else:
        print(mx2)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[int(input()) for i in range(a)] 
for i in range(len(b)-1):
    c=b
    c[i]=0
    c.sort
    print (c[len(c)-1])

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
max1=0
max2=0
a=[int(input()) for i in range(n)]
for i in a:
    if i>=max1:
        max1=i
    elif i>=max2:
        max2=i
if max2==0:
    for i in range(n):
        print(max1)
    exit()
for i in a:
    if i==max1:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
max1=0
max2=0
a=[int(input()) for i in range(n)]
for i in a:
    if i>=max1:
        max1=i
    elif i>=max2:
        max2=i

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

Submission status: Wrong Answer

Solution code:
n = int(input()) #1行目のNを取得する
s = [input() for i in range(n)] #複数行の数値の入力を取得

for i in range (n):
    a = s.pop(i-1)
    ans = max(s)
    print(ans)
    s.append(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
A = np.array([inp() for _ in range(n)])
mA = max(A)
smA = np.sort(A)[1]
for i in range(n):
    if A[i] == mA: print(smA)
    else: print(mA)