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())
L=[]
i = 0
s = 0
M2 = 0
for i in range (0,N):
    L.append(int(input()))
M = L[0]
for s in range(1,N):
    if  L[s] > M:
        M = L[s]
for s in range(1,N):
    if L[s] == M:
        continue
    else:
        if L[s] > M2:
            M2 = L[s]
for i in range(0,N):
    if L[i] == M:
        print(M2)
    else:
        print(M)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
num_line = [stdin.readline().rstrip() for _ in range(N)]
sort_line = sorted(num_line)
for i in num_line:
    if i == sort_line[N-1]:
        print(sort_line[N-2])
    else:
        print(sort_line[N-1])

Submission status: Wrong Answer

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

B=copy.copy(S)
B.sort()
if N>2:
	C=int(B[N-1])
	D=int(B[N-2])
	for i in S:
		if int(i)>=C:
			print(D)
		else:
			print(C)

else:
	print(S[1])
	print(S[0])

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
num_line = [stdin.readline().rstrip() for _ in range(N)]
sort_line = sorted(num_line)
for i in num_line:
    if i == sort_line[-1]:
        print(sort_line[-2])
    else:
        print(sort_line[-1])

Submission status: Wrong Answer

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

L_max=[0]*N
R_max=[0]*N

L=0
for i in range(N):
    L=max(L,a[i])
    L_max[i]=L

R=0
for i in range(N):
    R=max(R,a[-i-1])
    R_max[i]=R

for j in range(N):
    print(max(L_max[j-1],R_max[N-j-2]))

Submission status: Wrong Answer

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

B=copy.copy(S)
B.sort()
if N!=2:
	C=int(B[N-1])
	D=int(B[N-2])
	for i in S:
		if int(i)>=C:
			print(D)
		else:
			print(C)

else:
	print(S[1])
	print(S[0])

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a =  [int(input()) for i in range(n)]
max_a_num = a.count(max(a))
b = sorted(a)
m1, m2 = b[0], b[1]
for i in range(n):
  if max_a_num == 1:
    if a[i] == m1:
      print(m2)
    else:
      print(m1)
  else:
    print(m2)

Submission status: Wrong Answer

Solution code:
sequence = []

N = int(input())

curr_el = max_el = second_el = int(input())
sequence.append(curr_el)
for i in range(1, N):
    curr_el = int(input())
    sequence.append(curr_el)
    if (curr_el > max_el):
        second_el = max_el
        max_el = curr_el
    elif (curr_el > second_el):
        second_el = curr_el

# print('sequence', sequence)

for curr_el in sequence:
    answer = second_el if (max_el != second_el and curr_el == max_el) else max_el
    print(answer)

Submission status: Wrong Answer

Solution code:
sequence = []

N = int(input())

curr_el = max_el = second_el = int(input())
sequence.append(curr_el)
for i in range(1, N):
    curr_el = int(input())
    sequence.append(curr_el)
    if (curr_el > max_el):
        max_el = curr_el
    elif (curr_el > second_el):
        second_el = curr_el

# print('sequence', sequence)

for curr_el in sequence:
    answer = second_el if (max_el != second_el and curr_el == max_el) else max_el
    print(answer)

Submission status: Wrong Answer

Solution code:
sequence = []

N = int(input())

curr_el = max_el = second_el = int(input())
sequence.append(curr_el)
for i in range(1, N):
    curr_el = int(input())
    sequence.append(curr_el)
    if (curr_el > max_el):
        max_el = curr_el
    elif (curr_el > second_el):
        second_el = curr_el

print('sequence', sequence)

for curr_el in sequence:
    answer = second_el if (max_el != second_el and curr_el == max_el) else max_el
    print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


num = int(N // 2 + 1)
cnt = {}
for i in range(1, N + 1):
    cnt[i] = 0
A.reverse()
B = []

for i, a in enumerate(A):
    i = N - i
    if i >= num:
        if a == 1:
            for p in make_divisors(i):
                cnt[p] = (cnt[p] + 1) % 2
            B.append(i)
    else:
        if cnt[i] != a:
            for p in make_divisors(i):
                cnt[p] = (cnt[p] + 1) % 2
            B.append(i)

print(len(B))
B = list(map(str, B))
print(' '.join(B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(input()) for _ in range(n)]
ma=max(A)
ma_i=A.index(ma)
for i,_ in enumerate(A):
    if i==ma_i:
        print(max(A[:i-1]+A[i-1:]))
    else:
        print(ma)

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
a_copy=copy.deepcopy(a)
max_num=max(a)
sec_num=0
answer=[]
a_copy=sorted(a_copy)
for i in range(len(a_copy)):
  if max_num>a_copy[-(i+1)]:
    sec_num=a_copy[-(i+1)]
    break
for j in range(len(a)):
  if a[j]==max_num and sec_num!=0:
    answer.append(sec_num)
  else:
    answer.append(max_num)
for k in range(len(answer)):
  print(answer[k])

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
a_copy=copy.deepcopy(a)
max_num=max(a)
sec_num=0
answer=[]
a_copy=sorted(a_copy)
for i in range(len(a_copy)):
  if max_num>a_copy[-(i+1)]:
    sec_num=a_copy[-(i+1)]
    break
for j in range(len(a)):
  if a[j]==max_num:
    if sec_num==0:
      answer.append(max_num)
    else:
      answer.append(sec_num)
  else:
    answer.append(max_num)
for k in range(len(answer)):
  print(answer[k])

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
a_copy=copy.deepcopy(a)
max_num=max(a)
sec_num=0
answer=[]
a_copy=sorted(a_copy)
for i in range(len(a_copy)):
  if max_num>a[-(i+1)]:
    sec_num=a[-(i+1)]
    break
for j in range(len(a)):
  if a[j]==max_num:
    answer.append(sec_num)
  else:
    answer.append(max_num)
for k in range(len(answer)):
  print(answer[k])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

m1, m2 = sorted(A)[N-2:]

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

Submission status: Wrong Answer

Solution code:
N = int(input())
 
A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    if max1 < ai:
        max1 = ai
    elif max2 < ai:
        max2 = ai
 
    if max2 == 0:
        max2 = ai
 
    A.append((ai, max2, max1))

for i in range(N):
    ai, _, _ = A[i]


    if max1 == ai:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    if max1 < ai:
        max1 = ai
    elif max2 < ai:
        max2 = ai
 
    if max2 == 0:
        max2 = ai
 
    A.append((ai, max2, max1))

_, max2, max1 = A[N-1]
for i in range(N):
    ai, _, _ = A[i]


    if max1 == ai:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    if max1 < ai:
        max1 = ai
    elif max2 < ai:
        max2 = ai
 
    if max2 == 0:
        max2 = ai
 
    A.append((ai, max2, max1))
  
for i in range(N):
    ai, _, _ = A[i]
    _, max2, max1 = A[N-1]

    if max1 == ai:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
n = int(input())
numList  = [input() for _ in range(n)]
maxVal = max(numList)
workList = numList[:]
workList.remove(maxVal)
secondVal = max(workList)
for num in numList:
  if num != maxVal:
    print(maxVal)
  else:
    print(secondVal)

Submission status: Wrong Answer

Solution code:
N = input()
a = []
for i in range(N):
        a.append(input())
B = max(a)
for i in range(N):
        if a[i]!=B :
                print(B)
        else:
                a.sort()
                print(a[-2])

Submission status: Wrong Answer

Solution code:
n = int(input())
numList  = [input() for i in range(n)]
maxVal = max(numList)
workList = numList[:]
workList.remove(maxVal)
secondVal = max(workList)
for num in numList:
  if num != maxVal:
    print(maxVal)
  else:
    print(secondVal)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input()) 
num = [input() for _ in range(n)] 
#ma=max(num)
#ind=num.index(ma)
sorted_num=sorted(num)
ma=sorted_num[-1]
ma2=sorted_num[-2]
for i in range(n):
    if ma==num[i]:
        print(str(ma2).strip())
    else:
        print(str(ma).strip())

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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

A_set = set(A)
if len(A_set)==1:
  val = max(A_set)
  for i in range(N):
    print(val)
  sys.exit()

second_max = sorted(A_set)[-2]
#print(A_set)
#print(second_max)
#print('--')

tmp_max = max(set(A))
#tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]
#print(tmp_max_list)

#tmp_list = [tmp_max] * N
#[式 for 任意の変数名 in イテラブルオブジェクト if 条件式]
#l_odd = [i for i in l if not i % 2 == 0]
for i in range(N):
  if A[i] == tmp_max:
    print(second_max)
  else:
    print(tmp_max)

Submission status: Wrong Answer

Solution code:
A = sorted([int(input()) for i in range(int(input()))])
max_A = max(A)
for i in A:
    if i == max_A:
        print(A[-2])
    else:
        print(max_A)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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

A_set = set(A)
if len(A_set)==1:
  val = A[0]
  for i in range(N):
    print(val)
  sys.exit()

second_max = sorted(A_set)[-2]
print(A_set)
print(second_max)
print('--')

tmp_max = max(set(A))
tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]
#print(tmp_max_list)

#tmp_list = [tmp_max] * N
#[式 for 任意の変数名 in イテラブルオブジェクト if 条件式]
#l_odd = [i for i in l if not i % 2 == 0]
for i in range(N):
  if A[i] == tmp_max:
    print(second_max)
  else:
    print(tmp_max)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input()) 
num = [input() for _ in range(n)] 
ma=max(num)
ind=num.index(ma)
ma2=sorted(num)[-2]
for i in range(n):
    if ind==i:
        print(str(ma2).strip())
    else:
        print(str(ma).strip())

Submission status: Wrong Answer

Solution code:
A = [int(input()) for i in range(int(input()))]
if len(set(A)) == 1:
    first,second = A[0],A[0]
else:
    first,second = (sorted(set(A),reverse=True))[0],(sorted(set(A),reverse=True))[1]
for i in A:
    if i == first:
        print(second)
    else:
        print(first)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input()) 
num = [input() for _ in range(n)] 
ma=max(num)
ind=num.index(ma)
ma2=sorted(num)[-2]
for i in range(n):
    if num[i]==ma:
        print(ma2)
    else:
        print(ma)

Submission status: Wrong Answer

Solution code:
n=input()
n=int(n)
a=[]
for i in range(n):
  s=input()
  a.append(s)
if int(max(a))>0:
  m=max(a)
else:
  m=min(a)
k=a.index(m)
a.remove(m)
for j in range(k):
  print(m)
if int(max(a))>0:
  print(max(a))
else:
  print(min(a))
for t in range(n-k-1):
  print(m)

Submission status: Wrong Answer

Solution code:
#C
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
#print("\n".join(map(str, out_list)))
for j in out_list:
    print(j)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    A.append(ai)


A2 = sorted(A)

max1 = A2[len(A2)-1]
max2 = A2[len(A2)-2]
print(max1, max2)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

normal = max(A)
hoge=sorted(A)
exception = hoge[-2]

for i in range(N):
    if A[i] == normal:
        print(exception)
    else:
        print(normal)

Submission status: Wrong Answer

Solution code:
n=input()
n=int(n)
a=[]
for i in range(n):
  s=input()
  a.append(s)
if int(max(a))>=0:
  m=max(a)
else:
  m=min(a)
k=a.index(m)
a.remove(m)
for j in range(k):
  print(m)
if int(max(a))>=0:
  print(max(a))
else:
  print(min(a))
for t in range(n-k-1):
  print(m)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    if A.count(Am)>1:
        print([Am for j in range(N)])
        return
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    for i in range(N):
        if  A[i] != Am:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(int(input()) for i in range(n))
if a.count(max(a))==1:
  for y in range(n):
  	if a[y]==max(a):
  		a[y]=min(a)
  		print(max(a))
  	else:
  		print(max(a))
else:
  for i in range(n):
    print(max(a))

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
max1 = 0
max2 = 0
for _ in range(N):
    ai = int(input())
    A.append(ai)


A2 = sorted(A)

max1 = A2[len(A2)-1]
max2 = A2[len(A2)-2]

for i in range(N):
    if max1 == A2[i]:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
#C

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

for i in range(n):
    a.append(int(input()))
    
a_copy = list(a)
a.sort(reverse=True)

max_1 = a[0]
max_count = a.count(max_1)

for i in a:
    if i < max_1:
        max_2 = i
        
for a in a_copy:
    if a == max_1 and max_count == 1:
        print(max_2)
    else:
        print(max_1)

Submission status: Wrong Answer

Solution code:
A = [int(input()) for i in range(int(input()))]
first,second = sorted(A,reverse=True)[0],sorted(A,reverse=True)[1]
for i in A:
    if i == first:
        print(first)
    else:
        print(second)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(int(input()) for i in range(n))
if a.count(max(a))==1:
  for y in range(n):
  	if a[y]==max(a):
  		a[y]=max(a)-1
  		print(max(a))
  	else:
  		print(max(a))
else:
  for i in range(n):
    print(max(a))

Submission status: Wrong Answer

Solution code:
A = [int(input()) for i in range(int(input()))]
first,second = sorted(A,reverse=True)[0],sorted(A,reverse=True)[1]
for i in A:
    if i == first:
        print(first)
    else:
        print(second)

Submission status: Wrong Answer

Solution code:
N = int(input())
data = []
max1 = 0
max2 = 0
for i in range(N):
    x = int(input())
    if x >= max1:
        max1 = x
        max_i = i
    elif x >= max2:
        max2 = x
for i in range(N):
    if max_i == i:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(int(input()) for i in range(n))
if a.count(max(a))==0:
  for y in range(n):
  	if a[y]==max(a):
  		a[y]=max(a)-1
  		print(max(a))
  	else:
  		print(max(a))
else:
  for i in range(n):
    print(max(a))

Submission status: Wrong Answer

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

n = int(input()) 
num = [input() for _ in range(n)] 
ma=max(num)
ind=num.index(ma)
ma2=sorted(num)[-2]
for i in range(n):
    if ind==i:
        print(ma2)
    else:
        print(ma)

Submission status: Wrong Answer

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

maximum = max(a)
a.sort()

for i in a:
    if i == maximum:
        b = a.copy()
        b.remove(i)
        print( max(b) )
    else:
        print(maximum)

Submission status: Wrong Answer

Solution code:

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

# S = sorted(A)
# MAXS = max(A)
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)

index = A.index(max(A))
MAXS = max(A)
A.sort()
two = A[-2]

for i in range(N):
    if i == index:
        print(two)
    else:
        print(MAXS)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import copy

a = int(input())
nums = [0]*a

for i in range(a):
    nums[i] = int(input())
    
maxnum = max(nums)
maxquant = len([i for i, x in enumerate(nums) if x == maxnum])


if maxquant != 1:
    for j in range(a):
        print(maxnum)
else:
    for j in range(a):
        if nums[j] != maxnum:
            print(maxnum)
        else:
            copylist = copy.deepcopy(nums)
            copylist[maxquant] = 0
            print(max(copylist))

Submission status: Wrong Answer

Solution code:
N = int(input())
if 2 <= N <= 200000:
    Input = [int(input()) for i in range(N)]

result = []
n = N
s = 1
m = 2

for i in range(N):

    if n <= m:
        m = 0
    if n <= s:
        s = 0

    if Input[s] < Input[m]:
        result.append(Input[m])
        m  += 1
        s  += 1
    else:
        result.append(Input[s])
        m  += 1
        s  += 1


for i in  range(len(result)):
    print(result[i])

Submission status: Wrong Answer

Solution code:
d = []
b = 1
N = int(input())
A = [input() for i in range(N)]
A = [int(x) for x in A]
for m in range(N):
    e = A[m]
    A.pop(m)

    for n in range(N-1):
        if m == n:
            continue
        c = A[n] // b
        if c >= 1:
            b = A[n]
        else:
            b = b

    d.append(b)
    A.insert(m , e)
for o in range(N):
    print(d[o])

Submission status: Wrong Answer

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

n = int(input()) 
num = [input() for _ in range(n)] 
ma=max(num)
ind=num.index(ma)
ma2=sorted(num)[-2]
for i in range(n):
    if ind==i and not ma==ma2:
        print(ma2)
    else:
        print(ma)

Submission status: Wrong Answer

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

la=sorted(a)
re=la[-1]
check=max(a)

x=a.count(check)

for i in range(n):
    if a[i]==check:
        if x>1:
            print(check)
        if x==1:
            print(re)
    else:
        print(check)

Submission status: Wrong Answer

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

normal = max(A)
hoge = A.copy()
exception = sorted(hoge)[-2]

for i in range(N):
    if A[i] == normal:
        print(exception)
    else:
        print(normal)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(int(input()) for i in range(n))
if a.count(max(a))==0:
  for y in range(n):
  	if a[y]==max(a):
  		a.remove(a[y])
  		print(max(a))
  	else:
  		print(max(a))
else:
  for i in range(n):
    print(max(a))

Submission status: Wrong Answer

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

# S = sorted(A)
# MAXS = max(A)
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)


S = sorted(A)
MAXS = max(A)

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

Submission status: Wrong Answer

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

v_max = max(v)
flag = 0
for i in range(n):
    if v[i] == v_max:
        flag = 1
    elif flag == 1:
        print(v_max)
        flag = 1
    elif flag == 0:
        v_i = v[:]
        del v_i[i]
        print(max(v))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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

A_set = set(A)
if len(A_set)==1:
  val = A[0]
  for i in range(N):
    print(val)
  sys.exit()

else:
  second_max = sorted(A_set)[-2]

tmp_max = max(set(A))
tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]
#print(tmp_max_list)

tmp_list = [tmp_max] * N
#[式 for 任意の変数名 in イテラブルオブジェクト if 条件式]
#l_odd = [i for i in l if not i % 2 == 0]
for i in range(len(tmp_max_list)):
  tmp_list[tmp_max_list[i]]=second_max

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

Submission status: Wrong Answer

Solution code:

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

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

for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Wrong Answer

Solution code:
N = int(input())
Input = []
if 2 <= N <= 200000:
    for i in range(N):
        A =  int(input())
        if 1<= A <= 200000:
            Input.append(A)

result = []
n = N
s = 1
m = 2

 
for i in range(N):
    if n <= m:
        m = 0
    if n <= s:
        s = 0

    if Input[s] < Input[m]:
        result.append(Input[m])
        m  += 1
        s  += 1
    else:
        result.append(Input[s])
        m  += 1
        s  += 1


for i in  range(len(result)):
    print(result[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[]
T=[]
for _ in range(N):
  x=int(input())
  L.append(x)
  if x not in T:
    T.append(x)

T.sort()
if not L.count(T[len(T)-1])<N//3:
  T.reverse()

for i in range(N):
  for j in range(len(T)):
    if T[j]!=L[i]:
      print(T[j])
      break
    elif len(T)==1:
      print(T[j])

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  print(max(a[:n]+a[n+1:]))

Submission status: Wrong Answer

Solution code:
import math

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

B = list(set(sorted(A)))

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

Submission status: Wrong Answer

Solution code:
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
#print("\n".join(map(str, out_list)))
for j in out_list:
    print(j)

Submission status: Wrong Answer

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

left_max=0
right_max=max(Arr)

for i in range(N):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=0
            else:
                right_max = max(Arr[i+1:])

        print(right_max)

    if i == N-1:
        break
    left_max=max(n,left_max)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Wrong Answer

Solution code:
#C
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
print("\n".join(map(str, out_list)))

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[]
T=[]
for _ in range(N):
  x=int(input())
  L.append(x)
  if x not in T:
    T.append(x)

T.sort()
if not L.count(T[len(T)-1])<N//75:
  T.reverse()

for i in range(N):
  for j in range(len(T)):
    if T[j]!=L[i]:
      print(T[j])
      break
    elif len(T)==1:
      print(T[j])

Submission status: Wrong Answer

Solution code:
def returnsecond(numbers, N):
    first = 0
    firc = 0;
    second = 0
    for j in range(N):
        if first < numbers[j]:
            first = numbers[j]
            firc = j
    for j in range(N):
        if(j != firc and second < numbers[i]):
            second = numbers[i]

    return first, second;


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

for i in range(N):
    numbers.append(int(input()))
first, second = returnsecond(numbers, N)

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

Submission status: Wrong Answer

Solution code:
import math

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

B = list(set(sorted(A)))

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

Submission status: Wrong Answer

Solution code:
import math

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

B = list(set(sorted(A)))
print(B)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list()
for i in range(N) :
	A.append(int(input()))

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

Submission status: Wrong Answer

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

v_max = max(v)
for i in range(n):
    if v[i] == v_max:
        v_i = v[:]
        del v_i[i]
        print(max(v))
    else:
        print(v_max)

Submission status: Wrong Answer

Solution code:
import math

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

B = list(set(sorted(A)))

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

Submission status: Wrong Answer

Solution code:
n = int(input())
max_1 = None
max_2 = None

for i in range(n):
    a = int(input())
    
    if max_2 is None:
        if max_1 is None:
            max_1 = a
            max_i = [i]
            
        elif a < max_1:
            max_2 = a

        elif max_1 == a:
            max_i.append(i)

       
    else:    
        if max_2 < a:
            if max_1 < a:
                max_2 = max_1
                max_i = [i]
                max_1 = a
            else:
                max_2 = a
    
if len(max_i) >= 2:
    out_list = [max_1 for i in range(n)]
else:
    out_list = [max_1 for i in range(n)]
    out_list[max_i[0]] = max_2
    
print("\n".join(map(str, out_list)))

Submission status: Wrong Answer

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

num = max(a)
tmp = [k for k in a if k != num]
if not tmp:
    num2 = num
else:
    num2 = max(tmp)

       

for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)

Submission status: Wrong Answer

Solution code:
import copy


n=int(input())
a = [0] * n
c = [0] * n

cnt = 0

for i in range(n):
  a[i]=int(input())
  
b = copy.deepcopy(a)
  
b = list(set(b))
list.sort(b, reverse=True)

for i in range(len(b)):
  c[i] = b.count(a)

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

  
else:
  for i in range(n):
    for j in range(len(b)):
      if a[i] < b[j]:
        print(b[j])
        break
      elif a[i] == b[j] and c[j] == 0 and j < len(b)-1:
        print(b[j+1])
        break
      elif j == len(b)-1:
        print(a[0])
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0 for n in range(n)]
print(a)
for i in range(n):
  a[i] = int(input())
a_max = max(a)
for j in range(n):
  if a[j] != a_max:
    print(a_max)
  else:
    a.sort()
    a.reverse()
    print(a[1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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



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

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

for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Submission status: Wrong Answer

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

v_max = max(v)
for i in range(n):
    if v[i] == v_max:
        v_i = v[:]
        v_i = v_i.pop(i)
        print(max(v))
    else:
        print(v_max)