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())
s = input()
ans_arr = [s[:i].count('W')+s[i+1:].count('E') for i in range(len(s))] 
print(min(ans_arr))

Submission status: Wrong Answer

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

for i in range(n):
  tmp = copy.deepcopy(a)
  tmp[i-1] = 0
  print(max(tmp))
  tmp = a

Submission status: Wrong Answer

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

left = [0]
right = [0]

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


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

# print(len(left))
# print(len(right))

right.reverse()

for i in range(N):
    print(max(left[i], right[i+1]))

Submission status: Wrong Answer

Solution code:
3
1
4
3

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(input()) for i in range(N)]
maxL=[0]*(N+1)
maxR=[0]*(N+1)
for j in range(1,N+1):
    maxL[j]=max(maxL[j-1],a[j-1])
    maxR[N-j]=max(maxR[N+1-j],a[N-j])
for k in range(N+1):
    print(max(maxL[k],maxR[k]))

Submission status: Wrong Answer

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

b = sorted(a)

if b[-1]==b[-2]:
    for i in range(n):
        print(b[-1])
else:
    for i in range(n):
        if a[i]==a[-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 = sorted(a)

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

Submission status: Wrong Answer

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

for i in A:
    if (A_s[0] == i) & (A_s[1] == i):
        print(A_s[0])
    elif (A_s[0] == i) & (A_s[0] != A_s[1]):
        print(A_s[1])
    else:
        print(A_s[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
  
  
b=0
c=0
for i in range(n):
  if a[i]>a[b]:
    b=i
  
for i in range(n):
  if i==b:
    continue
  
  if a[i]>a[c]:
    c=i

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
  
  
b=0
c=0
for i in range(n):
  if a[i]>a[b]:
    b=i
  
for i in range(n):
  if i==b:
    continue
  
  if a[i]>a[c]:
    c=i

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
  
  
b=0
c=0
for i in range(n):
  if a[i]>a[b]:
    b=i
  
  if a[i]>=a[c] and i!=b:
    c=i

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
  
  
b=0
c=0
for i in range(n):
  if a[i]>a[b]:
    b=i
  
  if a[i]>a[c] and i!=b:
    c=i
if n ==1:
  print(a[0])
else:
  for i in range(n):
    if i!=b:
      print(a[b])
    else:
      print(a[c])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=a
a.sort()
for i in range(n):
    if b[i]<a[-1]:
        print(a[-1])
    elif b[i]==a[-1]:
        print(a[-2])

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(input()) for i in range(N) ]
maxR=0
maxL=0
for j in range(N):
    for k in range(j):
        maxL=max(maxL,a[k])
    for l in range(j+1,N):
        maxR=max(maxR,a[l])
    print(max(maxL,maxR))

Submission status: Wrong Answer

Solution code:

import sys
N=int(input())
a=[0]*(N)
maxim=[0]*(N)
for i in range(N):
    a[i]=int(input())
maxim=sorted(list(set(a)), reverse=True)
if len(maxim)==1:
    for j in range(N):
        print(maxim[0])
        sys.exit()

for k in range(N):
    if a[k]!=maxim[0]:
        print(maxim[0])
    else:
        print(maxim[1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
N=int(input())
a=[0]*(N)
maxim=[0]*(N)
for i in range(N):
    a[i]=int(input())
maxim=sorted(list(set(a)), reverse=True)
if len(maxim)==1:
    for j in range(N):
        print(maxim[0])
        sys.exit()

for k in range(N):
    if a[k]!=maxim[0]:
        print(maxim[0])
    else:
        print(maxim[1])

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[0]*(N)
maxim=[0]*(N)
maxim1=0
maxim2=0
for i in range(N):
    a[i]=int(input())
    maxim[i]=a[i]
maxim=sorted(a, reverse=True)
maxim1=maxim[0]
for j in range(N):
    if maxim[0]!=maxim[j]:
        maxim2=maxim[j]
        break
for k in range(N):
    if a[k]!=maxim1:
        print(maxim1)
    elif a[k]==maxim1:
        print(maxim2)

Submission status: Wrong Answer

Solution code:

N=int(input())
a=[0]*(N+1)
for i in range(N):
    a[i]=int(input())
maxim=a[0]
for j in range(N):
    for k in range(N):
        if a[j]!=a[k]:
            if a[k]>=maxim:
                maxim=a[k]
    print(maxim)
    maxim=a[j+1]

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
firstMax = max(a)
minVal = min(a)
secondMax = max(map(lambda x:x if x != firstMax else (minVal if len(str(a).split(str(x))) > 1 else firstMax), a))
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)

Submission status: Wrong Answer

Solution code:

N=int(input())
a=[0]*N
maxim=0
for i in range(N):
    a[i]=int(input())
for j in range(N):
    for k in range(N):
        if a[j]!=a[k]:
            if a[k]>maxim:
                maxim=a[k]
    print(maxim)
    maxim=0

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
firstMax = max(a)
minVal = min(a)
secondMax = max(map(lambda x:x if x != firstMax else minVal, a))
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)

Submission status: Wrong Answer

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

sorted_A = sorted(list(set(A)),reverse=True)

max_idx = [x == sorted_A[0] for x in A]

ans = [sorted_A[0]] * N
if max_idx.count(True) == 1: ans[A.index(sorted_A[0])] = sorted_A[1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [int(input()) for i in range(N)]
l_ = sorted(l)
for Ai in l:
  if l_[0] == Ai:
    print(l_[1])
  else:
    print(l_[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [int(input()) for i in range(N)]
for i, Ai in enumerate(l):
  l_ = sorted(l)
  if l_[0] == Ai:
    print(l_[1])
  else:
    print(l_[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a_max = 0
for i in range(n):
  a = int(input())
  if a > a_max:
    print(a)
    a_max = a
  else:
    print(a_max)

Submission status: Wrong Answer

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

for i in range(n-1):
    if i == 1:
        result = a[2:]
        print(max(result))
    elif i == n-1:
        result = a[:n-1]
        print(max(result))
    else:
        result = a[:i] + a[i+1:]
        print(max(result))

Submission status: Wrong Answer

Solution code:
import math
import copy


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


for i in range(N):
  temp=copy.copy(A)
  temp.pop(i)
  print(sorted(temp)[0])

Submission status: Wrong Answer

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

A.sort(reverse=True)
  
max_ = A[0]
max__ = A[1]

for i in range(N):
  if A[i] == max_:
    print(max__)
  else:
    print(max_)

Submission status: Wrong Answer

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

m1 = lis[-1]
m2 = lis[-2]

for a in lis:
    if a == m1:
        print(m2)
    else:
        print(m1)

Submission status: Wrong Answer

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

m = max(Alist)
for i in range(N):
    if Alist[i]==m:
        print(Alist_sorted[1])
    else:
        print(m)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    
    d = {}
    [d.update({i:int(input())}) for i in range(N)]
    
    print(d)
    
    for i in range(N):
        d2 = d.copy()
        d2.pop(i)
        print(max(d2.values()))
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
m, m2, mf = 0, 0, 0
for _ in range(n):
    x = int(input())
    if x > m: m2, m = m, x
    elif x == m: mf += 1
    elif x < m and x > m2: m2 = x
    l.append(x)
for x in l:
    if x == m: print(m if mf else m2)
    else: print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#最大値とのインデックスを取得する
max_a = max(a)
max_a_index = a.index(max(a))


for i in range(n):
    if i == max_a_index:
        out = max(a[:i],a[i+1:])
        out = max(out)
        print(out)
    else:
        print(max_a)

Submission status: Wrong Answer

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

#最大値とのインデックスを取得する
max_a = max(a)
max_a_index = a.index(max(a))


for i in range(n):
    if i == max_a_index:
        out = max(a[:i],a[i+1:])
        print(*out)
    else:
        print(max_a)

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

index_max = np.argmax(A)
A_temp = np.copy(A)
A_temp[index_max] = 0
index_max_second = np.argmax(A_temp)

result = np.full(N, A[index_max])
result[index_max_second] = A[index_max_second]

for i in range(0, N, 1):
    print(result[i])

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

index_max = np.argmax(A)
A_temp = np.copy(A)
A_temp[index_max] = 0
index_max_second = np.argmax(A)

result = np.full(N, A[index_max])
result[index_max_second] = A[index_max_second]

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

index_max = np.argmax(A)

for i in range(0, N, 1):
    A_temp = np.copy(A)
    if index_max != i:
        print(int(A_temp[index_max]))
    else:
        A_temp[i] = 0
        print(A_temp)
        print(int(np.amax(A_temp)))

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

index_max = np.argmax(A)

for i in range(0, N, 1):
    if index_max != i:
        A_temp = np.copy(A)
        A_temp[i] = 0
        print(A_temp)
        print(int(np.amax(A_temp)))
    else:
        print(A_temp[index_max])

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

for i in range(0, N, 1):
    A_temp = np.copy(A)
    A_temp[i] = 0
    print(A_temp)
    print(int(np.amax(A_temp)))

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

for i in range(N):
    A_temp = np.copy(A)
    A_temp[i] = 0
    print(A_temp)
    print(int(np.amax(A_temp)))

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

for i in range(N):
    A_temp = A
    A_temp[i] = 0
    for j in range(N):
        max_temp = A_temp[j]
        if max_temp > max:
            max = max_temp
    print(max)

Submission status: Wrong Answer

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

L = []
R = []

for a in A:
    if len(L) == 0:
        L.append(a)
    L.append(max(L[-1], a))

A.reverse()
for a in A:
    if len(R) == 0:
        R.append(a)
    R.append(max(R[-1], a))

R.reverse()

print(R[0])
for i in range(1, N-1):
    print(max(L[i-1], R[i+1]))
print(L[len(L)-2])

Submission status: Wrong Answer

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

buf = s.copy()
max_ind = s.index(max(s))
max_num = max(s)
s.remove(max_num)
max2_num = max(s)
 
for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)

Submission status: Wrong Answer

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

buf = s.copy()
max_ind = s.index(max(s))
max_num = max(s)
s.remove(max_num)
max2_num = max(s)
 
for i in range(N):
    if buf[i] == max_num:
        print(max2_num)
    else:
        print(max_num)

Submission status: Wrong Answer

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

buf = s.copy()
max_ind = s.index(max(s))
max_num = max(s)
s.pop(max_ind)
max2_num = max(s)
 
for i in range(N):
    if buf[i] == max_num:
        print(max2_num)
    else:
        print(max_num)

Submission status: Wrong Answer

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


# for i in range(N):
#     buf = s.copy()
#     buf.pop(i)
#     ans = max(buf)
#     print(ans)


max_ind = s.index(max(s))
max_num = max(s)
s.pop(max_ind)
max2_num = max(s)

for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)

Submission status: Wrong Answer

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

#a_sort = sorted(set(a))
max_1 = max(a)
for i in range(n):
    if max_1 == a[i]:
        a[i] = int(-1)
        #print("change")

max_2 = max(a)

for i in range(n):
    if a[i] == -1:
        a[i] = max_1
      

#print ("max: " + str(max_1), "max2: " + str(max_2))

for i in range(n):
    if max_1 > a[i]:
        print(max_1)
    
    elif a[i] <= max_1:
        print(max_2)

    else:
        print("err")

Submission status: Wrong Answer

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

#a_sort = sorted(set(a))
max_1 = max(a)
for i in range(n):
    if max_1 == a[i]:
        a[i] = int(-1)
        #print("change")

max_2 = max(a)

for i in range(n):
    if a[i] == -1:
        a[i] = max_1
      

print ("max: " + str(max_1), "max2: " + str(max_2))

for i in range(n):
    if max_1 >= a[i]:
        print(max_1)
    
    elif a[i] < max:
        print(max_2)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_2)
    else:
        print("err")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

#入力ループ
list = []
for i in range(n):
    list.append(int(input()))

#入力リストを降順にソート
new_list = sorted(list,reverse=True)
print(new_list)

#出力ループ
for c in range(n):
    if new_list[0] == list[c]:
        print(new_list[1])
    else:
        print(new_list[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for _ in range(n):
	a.append(int(input()))
max1 = max(a)
max2 = -1
for c in a:
	if(c==max1):
		continue
	max2 = max(max2,c)

if(max2==-1):
	max2 = max1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input());
num_list=[];
for i in range(n):
    num_list.append(int(input()));
    m=max(num_list)
for j in range(n):
    if(num_list[j]==m):
        num_list[j]=0;
        print(max(num_list))
    else:
        print(m);

Submission status: Wrong Answer

Solution code:
n=int(input());
num_list=[];
for i in range(n):
    num_list.append(int(input()));
    m=max(num_list)
for j in range(n):
    if(num_list[j]==m):
        num_list[j]=0;
        print(max(num_list))
    print(m);

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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(max(b))
    exit()
mi,maxi=b[-2:]
for a in A:
    if a==maxi:
        print(mi)
    else:
        print(maxi)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
ma=0
for i in range(n):
    a.append(int(input()))
for j in range(n):
    if(ma==a[j]):
        for h in range(n):
            if(h!=j):
                if(ma<a[h]):
                    ma=a[h]  
    print(str(ma))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
ma=0
for i in range(n):
    a.append(int(input()))
for j in range(n):
    if(ma==a[j]):
        for h in range(n):
            if(h!=j):
                if(ma<a[h]):
                    ma=a[h]
        print(str(ma))

Submission status: Wrong Answer

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

#最大値とそのインデックスを取得する
max_a = max(a)
max_a_index = a.index(max(a))


for i in range(n):
    if i == max_a_index:
        print(max(a[:i],a[i+1:]))
    else:
        print(max_a)

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
	b=copy.copy(a)
	del b[i]
	print(max(b),b,i)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
l=[int(input()) for _ in range(int(input()))]
for i in l:
    g=[j for j in l if j!= i]
    if g ==[]:
        print(*l,sep="\n")
        break
    else:
        print(max(g))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
kore = []
for i in range(0, n):
    b = a.pop(i)
    kore.append(max(a))
    a.insert(i, b)
print(kore)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
tmpa = a 
tmpa.sort()
for x in a:
  if x == tmpa[n-1]:
    print(tmpa[n-2])
  else:
    print(tmpa[n-1])
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

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

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

Submission status: Wrong Answer

Solution code:
def large(arr,n):
	first = second = -1
	for i in range(n):
		if arr[i]>first:
			second = first
			first = arr[i]
		elif arr[i]>second and arr[i]!=first:
			second = arr[i]
	if(second == -1):
		return first,first
	else:
		return second, first


n = int(input())
arr = []
brr = []
for _ in range(n):
	t = int(input())
	arr.append(t)
	# brr.append(t)
m2,m = large(arr,n)
for i in arr:
	if(i!=m):
		print(m)
	else:
		print(m2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
l.sort(reverse=True)
m1 = l[0]
m2 = l[1]
for i in l:
    if i == m1:
        print(m2)
    else:
        print(m1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
 
 
left_max = [-1] * N
right_max = [-1] * N
all = sum(A)
left_max[0] = A[0]
right_max[-1] = A[-1]
for i in range(1, N):
        left_max[i] = max(left_max[i-1], A[i])
for i in reversed(range(0, N-1)):
        right_max[i] = max(right_max[i+1], A[i])
 
print(left_max, right_max)

print(right_max[1])
for i in range(1,N-1):
        print(max(left_max[i-1], right_max[i+1]))
print(left_max[-2])

Submission status: Wrong Answer

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

for i, _ in enumerate(a):
    temp = _
    a[i] = 0
    print(max(a))
    a[i] = temp

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
brr = []
for _ in range(n):
	t = input()
	arr.append(t)
	brr.append(t)
m = max(arr)
brr.sort()
m2 = m
for i in range(n-1,-1,-1):
	if(brr[i]!=m):
		m2 = brr[i]
		break
for i in arr:
	if(i!=m):
		print(m)
	else:
		print(m2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
num = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
        num = []
        num.append(i)
    if a[i] == m:
        num.append(i)
    elif a[i] > prem:
        prem = a[i]
print(num,m,prem)
for i in range(n):
    if j < len(num) and i == num[j]:
        print(prem)
        j += 1
    else:
        print(m)

Submission status: Wrong Answer

Solution code:
t=int(input())
l=[]
b=0
c=0
for j in range(t):
    a=int(input())
    l.append(a)
    if(a>b):
        b=a
    elif(b>a):
        c=a
for i in l:
    if(i!=c):
        print(c)
    else:
        print(b)

Submission status: Wrong Answer

Solution code:
t=int(input())
l=[]
b=0
c=0
for j in range(t):
    a=int(input())
    l.append(a)
    if(a>b):
        b=a
    elif(b>a):
        c=a
for i in l:
    if(i!=b):
        print(b)
    else:
        print(c)

Submission status: Wrong Answer

Solution code:
l=[]
q=[]
t=int(input())
for i in range(t):
    l.append(int(input()))
    if(l[i] not in q):
        q.append(l[i])
q.sort()
y=len(q)
for i in range(0,t):
    if(l[i]!=q[y-1]):
        print(q[y-1])
    else:
        print(q[y-2])

Submission status: Wrong Answer

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


for i in range(N):
    mx = 0
    if A[i] != max(A):
        print(max(A))
    else:
        for j in range(N):
            if (A[j] >= mx) & j != i:
                mx = A[j]
        print(mx)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
B = sorted(A)
B_M = max(B)
B_M_1 = max(B[:n-1])
for i in range(n):
    if B[i] == B_M:
       print(B_M_1)
    else:
        print(B_M)

Submission status: Wrong Answer

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

for s in ls:
    if s==ls_sort[-1]:
        print(ls[-1])
    else:
        print(ls[-2])

Submission status: Wrong Answer

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

for s in ls:
    lst_num=len(ls_sort)-1
    if s==ls_sort[lst_num]:
        print(ls[lst_num])
    else:
        print(ls[lst_num-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = []
f = []
for i in range(n):
	x = int(input())
	v.append(x)
	f.append(x)
f.sort()
print(v)
for i in range(n):
	if v[i] == f[n-1]:
		print(str(f[n-2]) + ' ', end='')
	else:
		print(str(f[n-1]) + ' ', end='')

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N):
	ans = max(A[:1] + A[i+1:])
	print(ans)

Submission status: Wrong Answer

Solution code:
def maximum(n,lista):
    for i in range(len(lista)-1,-1,-1):
        if lista[i]!=n:
            return lista[i]
    return n
casos = int(input())
numeros = []
for i in range(casos):
    numeros.append(int(input()))
ordenados = numeros[:]
ordenados.sort()
for i in range(casos):
    print(maximum(numeros[i],ordenados))

Submission status: Wrong Answer

Solution code:
def maximum(n,lista):
    for i in range(len(lista)):
        if lista[i]!=n:
            return lista[i]
    return n
casos = int(input())
numeros = []
for i in range(casos):
    numeros.append(int(input()))
ordenados = numeros[:]
ordenados.sort()
ordenados.reverse()
for i in range(casos):
    print(maximum(numeros[i],ordenados))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
maxNum = max(a)
secoundMax = sorted(a)[-2]
for i in a:
  if a == maxNum:
    print(secoundMax)
  else:
    print(maxNum)

Submission status: Wrong Answer

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

    A_cp = sorted(A)
    print(id(A_cp), id(A))
    max1_A = A_cp.pop(-1)
    max2_A = max(A_cp)
    for a in A:
        if a == max1_A:
            print(max2_A)
        else:
            print(max1_A)
            
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
s = A.index(max(A))
x = max(A)
A.sort()
y = A[-2]
ans = []
for i in range(N):
  ans.append(x)
  
ans[s] = y

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

A = int(0)

for i in range(n):
    A = max(a)
    if A != a[i]:
        print(A)
        continue
    else:
        print(a[i])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

X = [0]
Y = [0]

for i in range(n):
    x = max(X,a[:i])
    y = max(Y,a[i + 1:])
    print(max(x[0],y[0]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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