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 collections
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
b=collections.Counter(a)
d=list(b.items())
d.sort(key=lambda x:-x[1])
if d[0][1]==1:
  for i in range(n):
    if a[i]==int(d[0][0]):
      print(int(d[1][0]))
    else:
      print(int(d[0][0]))
else:
  for i in range(n):
    print(int(d[0][0]))

Submission status: Wrong Answer

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

amax = max(a)
x = 1
if a.count(amax) >= 2:
    x = 0

for i in a:
    if i == amax:
        print(amax-x)
    else:
        print(amax)

Submission status: Wrong Answer

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

for i in a:
    if i == n:
        print(n-1)
    else:
        print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
import copy
list = []
for i in range(n):
    k = int(input())
    list.append(k)
list1 = copy.deepcopy(list)
first = max(list1)
list1.remove(first)
second = max(list1)
print("----------------")
for li in list:
    if li == first:
        print(second)
    else:
        print(first)

Submission status: Wrong Answer

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

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

B = sorted(A,reverse=True)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
import copy
list = []
for i in range(n):
    k = int(input())
    list.append(k)
list1 = copy.deepcopy(list)
first = max(list1)
list1.remove(first)
second = max(list1)
print("----------------")
for li in list:
    if li == first:
        print(second)
    else:
        print(first)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=a.index(x)

for i in range(0,n):
  print(x)

Submission status: Wrong Answer

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

for i in range(0,n):
  x=a[i]
  a[i]=0
  print(max(a))
  a.insert(i,x)

Submission status: Wrong Answer

Solution code:
n = int(input())
an = []
max_1 = 0
max_2 = 0
count = 0
for i in range(n):
    a = int(input())
    if a > max_1:
        max_1 = a
        count = 1
        max1_index = [i]
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 > a and a > max_2:
        max_2 = a
        max2_index = i
    an.append(a)
    
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)

Submission status: Wrong Answer

Solution code:
n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(input())
    if a > max_1:
        max_1 = a
        count = 1
        max1_index = [i]
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 > a > max_2:
        max_2 = a
        max2_index = i
    an.append(a)
    
    
    
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    print(max_1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = ([int(input()) for n in range(N)])
sorted_A = sorted(A)
max_ = A[len(A)-1]
semi_max = A[len(A)-2]


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

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
ll=sorted(set(l))
for i in range(n):
    if l[i]<max(l):
        print(max(l))
    elif l[i]==max(l):
        if len(ll)==1:
            print(ll[0])
        else:
            print(ll[-2])

Submission status: Wrong Answer

Solution code:
n = int(input())
l=[int(input()) for x in range(n)]
ll=sorted(set(l))


for i in range(n):
    if l[i]<max(l):
        print(max(l))
    elif l[i]==max(l):
        if len(ll)==1:
            print(ll[0])
        else:
            print(ll[-2])

Submission status: Wrong Answer

Solution code:
n = int(input())
l=sorted(int(input()) for x in range(n))
for i in range(len(l)):
    if l[i]<max(l):
        print(max(l))
    elif l[i]==max(l):
        set(l)
        if len(l)==1:
            print(l[i])
        else:
            print(l[-2])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(A)
for i in range(N):
  b=A.pop(i)
  print(max(A))
  A.insert(i,b)

Submission status: Wrong Answer

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

print(A)
for i in range(N):
  b=A.pop(i)
  print(A)
  print(max(A))
  A.insert(i,b)

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[]
for j in range(N):
    l+=list(map(int,input().split()))
if N==1:
    print(l[0])
else:
    for i in range(N):
        m=l
        m[i]=0
        print(max(m))

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[]
for j in range(N):
    l+=list(map(int,input().split()))
for i in range(N):
    m=l
    m[i]=0
    print(max(m))

Submission status: Wrong Answer

Solution code:
N=int(input())
l=[]
for j in range(N):
  l+=list(map(int,input().split()))
for i in range(N):
  print(sum(l)-l[i])

Submission status: Wrong Answer

Solution code:
import copy

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

all_max=max(A)  #O(N)
all_max_index=A.index(all_max)

copy_A.remove(all_max)
next_max=max(copy_A)

for i in range(N):
    if i!=all_max_index:
        print(all_max)
    else:
        print(next_max)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(input()) for _ in range(N)])
tf_list = [True] * N
for i in range(N):
    if i != 0:
        tf_list[i-1] = True
    tf_list[i] = False
    print(np.max(A[tf_list]))

Submission status: Wrong Answer

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
Elias_A = copy.copy(A)
A.sort()
Sorted_A = copy.copy(A)
  
for r in range(N):
  if A[r] == Sorted_A[N-1]: print(A[r])
  elif A[r] == Sorted_A[N-2]: print(A[r])
  else:
    A.remove(Elias_A[r])
    print(A[N-2])
    A = copy.copy(Sorted_A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
d=[]
for i in range(n):
  heapq.heappush(d,int(input()))
for j in range(n):
  if d[j]==d[n-1]:
    print(d[n-2])
  else:
    print(d[n-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
Numbers=sorted([int(input()) for i in range(N)])
Amax=Numbers[-1]
Asecond=Numbers[-2]
for j in Numbers:
        if j != Amax:
                print(Amax)
        else:
                print(Asecond)

Submission status: Wrong Answer

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

for i in range(n):
    s = int(input())
    a.append(s)
    b.append(s)
    
b.sort()
b.reverse()

for i in range(n):
    if not b[0] == b[i]:
        c = b[i]
        break
    else:
        c = b[0]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
b=max(a)
c=a.count(b)
if c>1:
  for i in range(n):
    print(b)
else:
  d=sorted(a, reverse=True)
  e=d[1]
  f=0
  h=0
  while f!=b:
    g=a[h]
    if f<g:
      f=g
    h=h+1
  print(h)
  for i in range(h-1):
    print(b)
  print(e)
  for i in range(n-h):
    print(b)

Submission status: Wrong Answer

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
Elias_A = copy.copy(A)
A.sort()
Sorted_A = copy.copy(A)
  
for r in range(N):
  if A[r] == Sorted_A[N-1]: print(A[r])
  elif A[r] == Sorted_A[N-2]: print(A[r])
  else:
    A.remove(Elias_A[r])
    print(A[N-2])
    A = copy.copy(Sorted_A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
al = [int(input()) for _ in range(0, N)]

max_a = max(al)
try:
  snd_a = max(filter(lambda x: x != max_a, al))
except:
  snd_a = max_a
  
for a in al:
  if a == max_a:
    print(snd_a)
  else:
    print(max_a)

Submission status: Wrong Answer

Solution code:
def main(A):
    maxInt = max(A)
    secondInt = sorted(A)[-2]

    for a in A:
        if a == maxInt:
            print(secondInt)
        else:
            print(maxInt)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
al = [int(input()) for _ in range(0, N)]
for a in al:
  try:
    max_a = max(filter(lambda x: x != a, al))
    print(max_a)
  except:
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
al = [int(input()) for _ in range(0, N)]
for a in al:
  el = list(filter(lambda x: x != a, al))
  if len(el):
    print(max(el))
  else:
    print(a)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = []
    ret = []
    for i in range(N):
        num = int(input())
        A.append(num)

    B = list(set(sorted(A)))
    for n in A:
        if B[-1] != n or len(B) == 1:
            ret.append(B[-1])
        else:
            ret.append(B[-2])

    for r in ret:
        print(r)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(set(A))[::-1]
if len(B)==1:
  for i in range(n):
    print(B[0])
else:
  for i in range(n):
    if A[i]==B[0]:
      print(B[1])
    else:
      print(B[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(set(A))[::-1]
if len(B)==1:
  print(B[0])
else:
  for i in range(n):
    if A[i]==B[0]:
      print(B[1])
    else:
      print(B[0])

Submission status: Wrong Answer

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

maxval = -999
second = -999
maxidx = -999
for idx, val in enumerate(A):
    if val > maxval:
        second = maxval
        maxval = val
        maxidx = idx

for i in range(N):
    if i == maxidx:
        print(second)
    else:
        print(maxval)

Submission status: Wrong Answer

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



m = max(A)
b = m
sec = 0
for k in range(0, len(A)):
  if(int(A[k]) == int(m)):
    for j in range(0, len(A)):
     if(j != k and sec <= int(A[j])):
      sec = int(A[j])
    m = sec

  print(m)
  m = b

Submission status: Wrong Answer

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



m = max(A)
sec = 0
for k in range(0, len(A)):
  if(int(A[k]) == int(m)):
    for j in range(0, len(A)):
     if(j != k and sec <= int(A[j])):
      sec = int(A[j])
    m = sec

  print(m)

Submission status: Wrong Answer

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



m = max(A)
sec = 0
for k in range(0, len(A)):
  if(int(A[k]) == int(m)):
    for j in range(0, len(A)):
     if(j != k and sec < int(A[j])):
      sec = int(A[j])
    m = sec

  print(m)

Submission status: Wrong Answer

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



m = max(A)
sec = 0
for k in range(0, len(A)):
  if(int(A[k]) == int(m)):
    for j in range(0, len(A)):
      if(sec < int(A[j]) and j != k):
        m = A[j]

  print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[]
B=[]
for i in range(n):
  a=int(input())
  A.append(a)
B=sorted(list(set(A)))[::-1]
for i in range(n):
  if B[0]==A[i]:
    if len(B)==1:
      print(B[0])
    else:
      print(B[1])
  else:
    print(B[0])

Submission status: Wrong Answer

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

m1=B[0]
m2=B[1]

for j in A:
    if j == B[0]:
        print(B[1])
    else:
        print(B[0])

Submission status: Wrong Answer

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

m1=B[0]
m2=B[1]

for j in A:
    if j == m1:
        print(m2)
    else:
        print(m1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())

max_num = 0
max_index = 0
second_num = 0
for i in range(N):
    num = int(input())
    if num >= max_num:
        if second_num < 1:
            max_num = num
        else:
            second_num, max_num = max_num, num
        max_index = i
    elif num > second_num:
        second_num = num
for i in range(N):
    if max_index == i:
        print(second_num)
    else:
        print(max_num)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())

max_num = 0
max_index = []
second_num = 0
for i in range(N):
    num = int(input())
    if num > max_num:
        if second_num < 1:
            second_num, max_num = num, num
        else:
            second_num, max_num = max_num, num
        max_index.clear()
        max_index.append(i)
    elif num == max_num:
        max_index.append(i)
    elif num > second_num:
        second_num = num

for i in range(N):
    if i in max_index:
        print(second_num)
    else:
        print(max_num)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())

max_num = 0
max_index = 0
second_num = 0
for i in range(N):
    num = int(input())
    if num > max_num:
        if second_num < 1:
            second_num, max_num = num, num
        else:
            second_num, max_num = max_num, num
        max_index = i
    elif num > second_num:
        second_num = num

for i in range(N):
    if max_index == i:
        print(second_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_sorted = sorted(a)
for x in a:
  if x == a_sorted[0]:
    print(a_sorted[1])
  else:
    print(a_sorted[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(input()) for _ in range(N))
m = max(A)

for x in A:
  if x < m:
    print(m)
  else:
    print(sorted(A)[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for _ in range(N)]
if N == 2:
    for j in A[::-1]:
        print(j)
else:
    tmp = sorted(A)
    del tmp[0:(N-2)]
    for i in range(N):
        if A[i] == tmp[1]:
            print(tmp[0])
        else:
            print(tmp[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 2:
    for _ in range(2):
        print(int(input()))
else:
    A = [input() for _ in range(N)]
    tmp = sorted(A)
    del tmp[0:(N-2)]
    for i in range(N):
        if A[i] == tmp[1]:
            print(tmp[0])
        else:
            print(tmp[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 2:
    print(input() for _ in range(2))
else:
    A = [input() for _ in range(N)]
    tmp = sorted(A)
    del tmp[0:(N-2)]
    for i in range(N):
        if A[i] == tmp[1]:
            print(tmp[0])
        else:
            print(tmp[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for _ in range(N)]
tmp = sorted(A)
del tmp[0:(N-2)]
for i in range(N):
    if A[i] == tmp[1]:
        print(tmp[0])
    else:
        print(tmp[1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for _ in range(n)]
m1=max(a)
m2=sorted(a)[n-2]
for i in range(n):
  if m1>=a[i]:
    print(m1)
  else:
    print(m2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for _ in range(n)]
m1=max(a)
m2=sorted(a)[n-2]
for i in range(n):
  if m1>a[i]:
    print(m1)
  else:
    print(m2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(input()) for _ in range(N))
max = max(A)

A_sorted = sorted(A)

for i in range(N):
    v = A[i]
    if v < max:
        print(max)
    else:
        print(A[-2])

Submission status: Wrong Answer

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

    a.sort()
    max_a = a[-1]
    next_max_a = a[-2]
    for cur_a in a:
        if cur_a == max_a:
            print(next_max_a)
        else:
            print(max_a)
    return()

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
m2 = sorted(a)[n-2]
print(m2)

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

Submission status: Wrong Answer

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

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
a2 = list(set(a))
a2.remove(m1)
if len(a2) > 0:
  m2 = max(a2)
else:
  m2 = 0

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

Submission status: Wrong Answer

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

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
a2 = list(set(a))
a2.remove(m1)
if len(a2) > 0:
  m2 = max(a2)
else:
  m2 = 0

for i in range(n):
  if m2 != 0 and a[i] == m1:
    print(m2)
  elif m2 != 0 and a[i] == m2:
    print(max(a[:i]+a[i+1:]))
  else:
    print(m1)

Submission status: Wrong Answer

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

for i in range (0,N):
  if A[i] != max(A):
    print(max(A))
  else:
    A1 = sorted(A)
    print(A1[1])

Submission status: Wrong Answer

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
B = copy.copy(A)
A.sort()

  
for r in range(N):
  A.remove(B[r])
  print(A[N-2])
  A = copy.copy(B)

Submission status: Wrong Answer

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

A = [0]*N

for r in range(N):
  A[r] = int(input())
A.sort()
B = copy.copy(A)
  
for r in range(N):
  A.remove(B[r])
  print(A[N-2])
  A = copy.copy(B)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for _ in range(N)]
lam = [0] * N
ram = [0] * N
for i in range(N):
  lam[i] = max(lam[i], a[i])
  ram[N - 1 - i] = max(ram[N - 1 - i], a[N - 1 - i])
print(ram[1])
for i in range(1, N - 1):
  print(max(lam[i - 1], ram[i + 1]))
print(lam[N - 2])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
max_value = 0
max_count = 1

for i in range(n):
  value = int(input())
  
  if value == max_value:
    max_count += 1
  
  max_value = max(max_value, value)
  a.append(value)
  
if max_count > 1:
  for i in range(n):
    print(max_value)
else:
  max_index = a.index(max_value)
  a.pop(max_index)
  second_max = max(a)
  
  for i in range(n):
    if i != max_index:
      print(max_value)
    else:
      print(second_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
max_value = 0
max_count = 1

for i in range(n):
  value = int(input())
  
  if value == max_value:
    max_count += 1
  
  max_value = max(max_value, value)
  a.append(value)
  
if max_count > 1:
  for i in range(n):
    print(max_value)
else:
  max_index = a.index(max_value)
  second_max = max(a[:max_index] + a[max_index+1:])
  
  for i in range(n):
    if i != max_index:
      print(max_value)
    else:
      print(second_max)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = list(int(input()) for _ in range(n))
b = sorted(a)
max = b[0]
sec_max = b[1]


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

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = list(int(input()) for _ in range(n))
max = np.amax(a)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
if len(set_a) == 1:
    s_set_a = max_a
else:
    s_set_a = sorted(set_a)[-2]

for i in range(n):
    if max_a == a[i]:
        print(s_set_a)
    else:
        print(max_a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = sorted(set(a))
for i in range(n):
    if max_a == a[i]:
        if len(set(a)) == 1:
            print(max_a)
        else:
            print(set_a[-2])
    else:
        print(max_a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
for i in range(n):
    if max(a) == a[i]:
        if len(set(a)) == 1:
            print(max(a))
        else:
            k = sorted(set(a))
            print(k[-2])
    else:
        print(max(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())
X = [0] * N
count = 0
max = 0
for i in range(N):
    for j in range(N):
        if j != i:
            if max < A[j]:
                max = A[j]
    X[i] = max
for i in range(N):
    print(X[i])

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=[]
maximum=0

for i in range(n):
    lists.append(int(input()))
print(lists)
for i in range(n):
    maximum=0
    for j in range(n):
        if j==i:
            continue
        else:
            maximum=max(maximum,lists[j])

    print(maximum)

Submission status: Wrong Answer

Solution code:
n = int(input())
ori_a = []
for i in range(n):
    a = int(input())
    ori_a += [a]
co_a = sorted(list(set(ori_a)))
one = co_a[-1]
if len(co_a) >= 2:
    two = co_a[-2]
    for j in ori_a:
        if j == one:
            print(two)
        else:
            print(one)
else:
    for j in range(n):
        print(one)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = [input() for _ in range(n)]
b=sorted(a)
c=[0]*n

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

Submission status: Wrong Answer

Solution code:
N = int(input())
An = list()
for i in range(N):
    An.append(input())
MaxIndex = An.index(max(An))
SecondIndex = An.index(sorted(An)[-2])
for i in range(N):
    if i == MaxIndex:
        print(An[SecondIndex])
    else:
        print(An[MaxIndex])

Submission status: Wrong Answer

Solution code:
n=int(input())
a = [input() for _ in range(n)]
b=a.copy()
b.sort()
bset=list(set(b))
c=[0]*(n)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a = [input() for _ in range(n)]
b=a.copy()
b.sort()
c=[0]*n

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
max_num = max(A)
result = [max(A[i], max_num) for i in range(N)]
for i in range(N):
    print(result[i])

Submission status: Wrong Answer

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

maxIndex = [i for i, x in enumerate(a) if x == max(a)]
if len(maxIndex)>=2:
    for i in range(n):
        print(max(a))
else:
    z = int(maxIndex[0])
    s = max(a[0:z],a[z+1:n+1])
    for k in range(z-1):
            print(max(a))
    print(s[0])
    for k2 in range (n-z):
        print(max(a))

Submission status: Wrong Answer

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

maxIndex = [i for i, x in enumerate(a) if x == max(a)]
if len(maxIndex)>=2:
    print(max(a) for i in range (n))
else:
    z = int(maxIndex[0])
    s = max(a[0:z],a[z+1:n+1])
    for k in range(n):
        if k==z:
            print(s[0])
        else:
            print(max(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
max_num = -1
mode_max = False
for i in range(n):
    ipt = int(input())
    if ipt == max_num:
        mode_max = True
        a.append(ipt)
    else:
        max_num = max(ipt, max_num)
        a.append(ipt)
if mode_max:
    for i in range(n):
        print(max_num)
else:
    a_copy = a[:]
    idx = a.index(max_num)
    a_copy.remove(max_num)
    sub_max = max(a_copy)
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
max_num = -1
mode_max = False
for i in range(n):
    ipt = int(input())
    if ipt == max_num:
        mode_max = True
        break
    else:
        max_num = max(ipt, max_num)
        a.append(ipt)
if mode_max:
    for i in range(n):
        print(max_num)
else:
    a_copy = a[:]
    idx = a.index(max_num)
    a_copy.remove(max_num)
    sub_max = max(a_copy)
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_num)
if mode_max:            
    for i in range(n):
        print(max(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
max_num = -1
mode_max = False
for i in range(n):
    ipt = int(input())
    if ipt == max_num:
        mode_max = True
        break
    else:
        max_num = max(ipt, max_num)
        a.append(ipt)
if mode_max:
    for i in range(n):
        print(max_num)
else:
    a_copy = a[:]
    idx = a.index(max_num)
    a_copy.remove(max_num)
    sub_max = max(a_copy)
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_num)
for i in range(n):
    print(max(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
max_num = -1
mode_max = False
for i in range(n):
    ipt = int(input())
    if ipt == max_num:
        mode_max = True
    else:
        max_num = max(ipt, max_num)
        a.append(ipt)
if mode_max:
    for i in range(n):
        print(max_num)
else:
    a_copy = a[:]
    idx = a.index(max_num)
    a_copy.remove(max_num)
    sub_max = max(a_copy)
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
max_num = -1
mode_max = False
for i in range(n):
    ipt = int(input())
    if ipt == max_num:
        mode_max = True
    else:
        max_num = max(ipt, max_num)
        a.append(ipt)
if mode_max:
    for i in range(n):
        print(max_num)
else:
    a_copy = a[:]
    idx = a.index(max(a))
    a_copy.remove(max(a))
    sub_max = max(a_copy)
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(input())
A_copy = A[:]
A_copy.sort()
# print(A, A_sort)
A_max = A_copy[N-1]
A_second = A_copy[N-2]
for i in range(N):
    if A[i] != A_max:
        print(A_max)
    else:
        print(A_second)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    A.append(input())
A_copy = A[:]
A_sort = sorted(A_copy)
# print(A, A_sort)
A_max = A_sort[-1]
A_second = A_sort[-2]
for i in range(N):
    if A[i] != A_max:
        print(A_max)
    else:
        print(A_second)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa-1)
  else:
    print(maxa)

Submission status: Wrong Answer

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

biggest_num = 0
secondly_biggest_num=0
for i in range(n):
    a = int(input())
    suretsu0.append(a)

suretsu = [x for x in suretsu0]
suretsu.sort()


biggest_num = suretsu[-1]
secondly_biggest_num=suretsu[-2]

print(secondly_biggest_num,biggest_num)


for ele in suretsu0:
    if ele==biggest_num:
        print(secondly_biggest_num)
    else:
        print(biggest_num)