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())
lst = []
for _ in range(n):
  lst.append(int(input()))
set_ = list(set(lst))
set_.sort()
if len(set_)==1:
  for _ in range(n):
  	print(set_[0])
else:
  max_ = set_[-1]
  next_max_ = set_[-2]
  for c in lst:
    if c==max_:
      print(next_max_)
    else:
      print(max_)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = []
for _ in range(n):
  lst.append(int(input()))
set_ = list(set(lst))
set_.sort()
if len(set_)==1:
  print(set_[0])
else:
  max_ = set_[-1]
  next_max_ = set_[-2]
  for c in lst:
    if c==max_:
      print(next_max_)
    else:
      print(max_)

Submission status: Wrong Answer

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

# 最大値のインデックス
i1 = np.argmax(a)
temp = a.pop(i1)
# ２番目の最大値のインデックス
i2 = np.argmax(a)
a.insert(i1, temp)

for i in range(n):
  if i == i1:
    print(a[i2])
  else:
    print(a[i1])

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    nums = []

    for i in range(n):
        input_num = int(input())
        nums.append(input_num)

    max_num, second_num = max(nums[0], nums[1]), min(nums[0], nums[1])

    for i in range(2, n):
        if nums[i] > max_num:
            max_num = nums[i]
            second_num = max_num
        elif nums[i] > second_num:
            second_num = nums[i]

    for i in nums:
        if i == max_num:
            print(second_num)
        else:
            print(max_num)
            
resolve()

Submission status: Wrong Answer

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

b=a.copy()
b=sorted(b, reverse=True)
print(b)

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())
l = [int(input()) for _ in range(n)]
max_num = max(l)
m = [i for i in l if i != max_num]
second_num = max(m) if m else max_num

for i in l:
   if i == max_num:
       print(second_num)
   else:
       print(max_num)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
l = deque([int(input()) for _ in range(n)])
max_num = max(l)
m = deque([i for i in l if i != max_num])
second_num = max(m) if m else max_num

for i in l:
   if i == max_num:
       print(second_num)
   else:
       print(max_num)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for _ in range(n)]
ax,ay = sorted(a, reverse=True)[0:2]
b = [ay if x == ax else ax for x in a]
print('\n'.join(map(str,b)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

maxn = max(a)
sortedset = sorted(set(a))
max2n = maxn
if len(sortedset) > 1:
  max2n = sortedset[-2]

for num in a:
  if num != maxn:
    print (maxn)
  else:
    print (max2n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for i in range(n)]
b = sorted(a, reverse=True)
for i in range(n):
    if b[0] == b[1]:
        print(b[0])
    else:
        if a[i] == 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 = max(a)
for i in range(n-1):
    if a[i] != b:
        print(b)
    else:
        del a[i]
        print(max(a))
        a.insert(i, b)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for i in range(n)]
b = max(a)
for i in range(n):
    if a[i] != b:
        print(b)
    else:
        del a[i]
        print(max(a))
        a.insert(i, b)

Submission status: Wrong Answer

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




for i in range(n):
	a[i] = 0
	print(max(a))

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
A = deque(int(input()) for i in range(N))
for i in range(N):
    M = max(A)
    p= A.pop()
    MM = max(A)
    if M == MM:
        print(M)
    else:
        print(MM)
    A.appendleft(p)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(input()) for i in range(N))
ans = A[0]
for i in range(N):
    stor = A.pop(i)
    for n in range(N-1):
        if ans < A[n]:
            ans = A[n]
    A.insert(i,stor)
    print(ans)
    ans = A[0]

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(int(input()) for i in range(N))
ans = A[0]
for i in range(N):
    for n in range(i):
        if ans < A[i]:
            ans = A[i]
    for n in range(i+1,N):
        if ans < A[i]:
            ans = A[i]
    print(ans)
    ans = A[0]

Submission status: Wrong Answer

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

ans = max(a)
for i in range(n):
  if a[i] == ans:
    temp = ans
    a.remove(ans)
    ans = max(a)
    a.insert(i, temp)
  print(ans)

Submission status: Wrong Answer

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

max_a = max(a)
ans = [max_a]*N
max_index = []
for i in range(N):
  if a[i] == max_a:
    max_index.append(i)
try:
  sec_max_a = max([i for i in a if i !=max_a])
except:
  for i in range(N):
    print(ans[i])
else:
  for i in max_index:
    ans[i]=sec_max_a
  for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

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

max_a = max(a)
ans = [max_a]*N
max_index = []
for i in range(N):
  if a[i] == max_a:
    max_index.append(i)
try:
  sec_max_a = max([i for i in a if i !=max_a])
except:
  print(*ans)
else:
  for i in max_index:
    ans[i]=sec_max_a
  print(*ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = int(input())
c = [int(input()) for i in range(a)]

#最大値のindexを探し、最大値が複数あるか確認
all_max = max(c)
first_max_id = c.index(all_max)

c_dash = sorted(c)
second_max_value = c_dash[1]
for i,v in enumerate(c):
    if i != first_max_id:
        pr_val = all_max
    else:
        if all_max == second_max_value:
            pr_val = all_max
        else:
            pr_val = second_max_value
    print(pr_val)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = []
B = []
for i in range(N):
    j = int(input())
    A.append(j)
    B.append(j)
B.sort(reverse=True)
B.pop(0)
for i in A:
    if i == max(A):
        print(i)
    else:
        print(max(B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

B = sorted(A)
A_max, A_second_max = B[-1], B[-2] 
for i in A:
    if i == A_max:
        print(A_second_max)
    else:
        print(A_max)

Submission status: Wrong Answer

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

B = A.copy()
A_max = max(A)
B.remove(max(A))
second_max = max(B)
for i in A:
    if i == A_max:
        print(second_max)
    else:
        print(A_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(int(input()) for i in range(n))

L_sorted = sorted(L, reverse = True)
print(L)
for i in L:
    max = L_sorted[0]
    if max == i:
        print(L_sorted[1])
    else:
        print(max)

Submission status: Wrong Answer

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

tmpA = sorted(A)
m1,m2 = tmpA[-1], tmpA[-2]

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

Submission status: Wrong Answer

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

sA = sorted(A, reverse=True)
maxA,smaxA = sA[0:2]

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

Submission status: Wrong Answer

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

sA = sorted(A, reverse=True)
maxA,smaxA = sA[0:2]

for i in range(N):
    if A[i] == maxA:
        print(smaxA)
    else:
        print(maxA)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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):
    if A[i] != B[N-1]:
        print(B[N-1])
    else:
        for j in range(N):
            if A[i] != B[(N-1)-j]:
                print(B[N-1-j])
                break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

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


ans = ["" for _ in range(n)]
for i in range(n):
    a_test = a[:]
    del a_test[i]
    ans[i] = max(a_test)

print(ans)

Submission status: Wrong Answer

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

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

for idx,i in enumerate(a):
    if m != i:
        print(m)
    else:
        print(m1)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
amax = max(a)
amax2 = sorted(a)[-2]
print(amax, amax2)
for i in range(len(a)):
  if a[i]==amax:
    print(amax2)
  else:
    print(amax)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
a.sort(reverse=True)
amax = a[0]
amax2 = a[1]
for i in range(len(a)):
  if a[i]==amax:
    print(amax2)
  else:
    print(amax)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
a.sort(reverse=True)
amax = a[0]
for i in range(len(a)):
  if a[i]==amax:
    print(a[1])
  else:
    print(amax)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.zeros(N)

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

ind = A.argsort()[::-1][:2]

first_a = A[ind[0]]
second_a = A[ind[1]]

for i, a in enumerate(A):
    if i == ind[0]:
        print(second_a)
    else:
        print(first_a)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.zeros(N)

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

ind = A.argsort()[:2]

first_a = A[ind[0]]
second_a = A[ind[1]]

for i, a in enumerate(A):
    if i == ind[0]:
        print(second_a)
    else:
        print(first_a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
maxNum=-1
secNum=-1
maxI=-1
for i in range(N):
    A.append(int(input()))
    if(maxNum<A[i]):
        secNum=maxNum
        maxNum=A[i]
        maxI=i
    elif(secNum<A[i]):
        secNum=A[i]
for i in (A):
    if(i!=maxI):
        print(maxNum)
    else:
        print(secNum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for _ in range(n)]
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:
def main():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    MAX1 = a[0]
    MAX2 = a[1]
    if MAX2 > MAX1:
        MAX1, MAX2 = MAX2, MAX1
    for j in a:
        if j >= MAX1:
            MAX1 = j
        elif j > MAX2:
            MAX2 = j
        else:
            continue
    for i in range(n):
        ans = MAX2 if a[i] == MAX1 else MAX1
        print(ans)


if __name__ == '__main__':
    main()

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):
    if B[-1] == A[i-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)

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

Submission status: Wrong Answer

Solution code:
N=int(input())

l=list(int(input()) for i in range(N))

sort_l=sorted(l,reverse=True)

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

Submission status: Wrong Answer

Solution code:
N=int(input())

l=list(int(input()) for i in range(N))

sort_l=sorted(l,reverse=True)

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

Submission status: Wrong Answer

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

sa = sorted(a)
max = sa[len(sa)-1]
max_2 = sa[len(sa)-2]

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

Submission status: Wrong Answer

Solution code:
def abc_134c(N):
    max_1 = (0, 0)
    max_2 = (0, 0)
    for i in range(N):
        buf = int(input())
        if max_2[1] < buf:
            if max_1[1] < buf:
                max_2 = max_1
                max_1 = (i, buf)
            else:
                max_2 = (i, buf)

    output = [max_1[1] for _ in range(N)]
    output[max_1[0]] = max_2[1]
    print(output)


if __name__ == "__main__":
    N = int(input())
    abc_134c(N)

Submission status: Wrong Answer

Solution code:
#h = list(map(int, input().split()))
#r = int(input())
#n, d = map(int, input().split())

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

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

sa = sorted(a)
sa.reverse()

m1 = sa[0]
m2 = sa[0]
for i in sa:
    if i != m1:
        m2 = i
        break

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

Submission status: Wrong Answer

Solution code:
#h = list(map(int, input().split()))
#r = int(input())
#n, d = map(int, input().split())

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

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

sa = sorted(a)
sa.reverse()

ma = sa[0]
mi = sa[0]
for i in sa:
    if i != mi:
        mi = i

for x in sa:
    if i == ma:
        print(mi)
    else:
        print(ma)

Submission status: Wrong Answer

Solution code:
#h = list(map(int, input().split()))
#r = int(input())
#n, d = map(int, input().split())

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

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

sa = sorted(a)
sa.reverse()

h = {}
for i in sa:
    h[i] = i
    for j in sa:
        if j != i:
            h[i] = j
            break
            
for x in sa:
    print(h[x])

Submission status: Wrong Answer

Solution code:
import numpy as np
#　まずinput
n = int(input())

#　リストを作る
ll = []

for m in range(n):
    aa=input()
    ll.append(int(aa))
#print(n)
#print(ll)

for p in range(n):
    s = 0
    for l in range(n):
        s = s+ ll[l]
    s = s - ll[p]
    print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
#　まずinput
n = int(input())

#　リストを作る
ll = []

for m in range(n):
    aa=input()
    ll.append(int(aa))
print(n)
print(ll)

for p in range(n):
    s = 0
    for l in range(n):
        s = s+ ll[l]
    s = s - ll[p]
    print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

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

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = [int(input()) for _ in range(n)]
m = max(num)
sec = sorted(num)[-2]
for x in num:
    if x != m:
        print(x)
    else:
        print(sec)

Submission status: Wrong Answer

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

B = A
for i in range(N):
    B.append(0)
    B.remove(B[i])
    c = max(B, key=int)
    print(c)
    B = A

Submission status: Wrong Answer

Solution code:
n=int(input())
t1=int(input())
t2=int(input())

if t1 >= t2:
    m1, i1 = t1, 1
    m2, i2 = t2, 2
else:
    m1, i1 = t2, 2
    m2, i2 = t1, 1

a = [m1,m2]
for i in range(2, n):
    v = int(input())
    if m1 < v:
        m2, i2 = m1, i1
        m1, i1 = v, i
    elif m2 < v:
        m2, i2 = v, i1
        i2 = i

for i in range(0, n):
    if m1 == m2:
        print(m1)
    elif i+1 == i1:
        print(m2)
    else:
        print(m1)

Submission status: Wrong Answer

Solution code:
n=int(input())
t1=int(input())
t2=int(input())

m1 = max([t1, t2])
i1 = 1
m2 = min([t1, t2])
i2 = 2
a = [m1,m2]
for i in range(2, n):
    v = int(input())
    if m1 < v:
        m2, i2 = m1, i1
        m1, i1 = v, i
    elif m2 < v:
        m2, i2 = v, i1
        i2 = i

for i in range(0, n):
    if i == i1:
        print(m2)
    else:
        print(m1)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
A = max(a)
if a.count(A) > 1:
    for i in range(len(a)):
        print(A)
for i in range(len(a)):
    if i == a.index(A):
        print(sorted(a)[-2])
    else:
        print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
A = max(a)
if a.count(A):
    for i in range(len(a)):
        print(A)
for i in range(len(a)):
    if i == a.index(A):
        print(sorted(a)[-2])
    else:
        print(A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

arr = []
s_arr = []

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

s_arr.sort()

for a in arr:
    if a >= s_arr[0]:
        print(s_arr[1])
    else:
        print(s_arr[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
n = []
for i in range(N):
  n.append(input())
  
for i in range(N):
  n1 = sorted(n)
  print(n[N - 1])

Submission status: Wrong Answer

Solution code:
a = int(input())
b = [input() for i in range(a)]
h = max(b)
o = b.index(h)
c = b.copy()
c.remove(h)
k = max(c)
for i in range(a):
    if i == o:
        print(k)
    else:
        print(h)

Submission status: Wrong Answer

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

for i in range(N):
  temp=[s[x] for x in range(i)]+[s[x] for x in range(i+1, N)]
  print(min(temp))

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
#a, b = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

a = max(s)
b = sorted(s)[-2]

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a = list(map(int, input()))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a1 = int(input())
a2 = int(input())
if n == 2:
    print(a2)
    print(a1)
else:
    a3 = int(input())
    s1 = max(a2, a3)
    s2 = max(a1, a3)
    s3 = max(a1, a2)
    print(s1)
    print(s2)
    print(s3)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]
t1 = max(a)
t1_idx = [i for i, v in enumerate(a) if v == t1]
a.sort()
try:
    t2 = a[-1*len(t1_idx)-1]
except:
    t2 = t1
for i in range(n):
    if i in t1_idx:
        print(t2)
    else:
        print(t1)

Submission status: Wrong Answer

Solution code:
from copy import copy


def main():
    N = int(input())
    A_list = [int(input()) for _ in range(N)]
    tmp_list = copy(A_list)
    tmp_list.sort()
    max_num = tmp_list[-1]
    second_max_num = tmp_list[-2]
    max_index = A_list.index(max_num)
    for i in range(N):
        if i is max_index:
            print(second_max_num)
            continue
        print(max_num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

tmp = A.copy();
tmp.sort()
max1_A = tmp[-1];
max2_A = tmp[-2];
max_count = A.count(max1_A);

# 最大値が複数ある場合
if max_count > 1:
  for i in range(N):
    print(max1_A)
# 最大値が1つある場合
else:
  for i in range(N):
    if A[i] < max1_A:
      print(max1_A)
    else:
      print(max2_A)
      break
  for j in range(i,N):
    print(max1_A)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0))
m=max(a)

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

Submission status: Wrong Answer

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

for j in range(n):
    copy_list = a_list.copy()
    del copy_list[j]
    max = 0
    for k in copy_list:
        if k > max:
            max = k
    print(k)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = [int(input()) for x in range(N)]

sorted_list = sorted(A_list, reverse = True)
max_1st = sorted_list[0]
for num in sorted_list:
    max_2nd = num
    if max_1st != max_2nd:
        break

for num in A_list:
    if num != max_1st:
        print(max_1st)
    else:
        print(max_2nd)

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(input()) for i in range(N-1)]
s = sorted(a)
for i in range(N-1):
  if s[0]==s[i]:
    print(s[0])
  else:
    print(s[1])

Submission status: Wrong Answer

Solution code:
import copy

def main():

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

    srtdA = copy.copy(list(set(A)))
    srtdA.sort(reverse=True)


    for  i in A:
        if len(srtdA)==1:
            print(srtdA[0])
        elif i == srtdA[0]:
            print(srtdA[1])
        else:
            print(srtdA[0])

if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy

def main():

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

    srtdA = copy.copy(list(set(A)))
    srtdA.sort(reverse=True)

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

if __name__== "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy

def main():

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

    srtdA = copy.copy(list(set(A)))
    srtdA.sort(reverse=True)

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

if __name__== "__main__":
    main()

Submission status: Wrong Answer

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

big_1st = max(A_list[0], A_list[1])
big_2nd = min(A_list[0], A_list[1])

for i in range(2, N):
  if big_2nd < A_list[i] and A_list[i] < big_1st:
    big_2nd = A_list[i]
  elif big_1st < A_list[i]:
    big_2nd = big_1st
    big_1st = A_list[i]

for i in A_list:
  if i == big_1st:
    print(big_2nd)
  else:
    print(big_1st)

Submission status: Wrong Answer

Solution code:
N = int(input())
num_array = [int(input()) for i in range(N)]
num_array.sort()
for i in range(N):
    if (i == N-1):
        print(num_array[-2])
        break
    print(num_array[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())

A = []

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

maxa = max(A)

copy = A[:]
copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == max:
        print(maxa2)
    else:
        print(maxa)

Submission status: Wrong Answer

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

L_max=max(L)

L_max_count=0
for l in L:
    if l==L_max:
        L_max_count+=1
    if L_max_count > 1:
        break

for i in range(N):
    now=L[i]
    
    if L_max_count > 1:
        ans=L_max
    
    elif now!=L_max:
        ans=L_max
        
    else:
        L_temp=L.copy()
        L_temp_p=L_temp.pop(i)
        ans=max(L_temp)
    
    print(ans)
    
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
maxnum = max(ls)
ind = ls.index(maxnum)
ls.remove(maxnum)
secondnum = max(ls)
ls = ls[0:ind] + [maxnum] + ls[ind:]
print(ls)
if maxnum == secondnum:
    for i in range(n):
        print(maxnum)
    quit()
for i in range(n):
    if ls[i] == maxnum:
        print(secondnum)
    else:
        print(maxnum)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
maxnum = max(ls)
ind = ls.index(maxnum)
ls.remove(maxnum)
secondnum = max(ls)
ls = ls[0:i] + [maxnum] + ls[i+1:]
if maxnum == secondnum:
    for i in range(n):
        print(maxnum)
    quit()
for i in range(n):
    if ls[i] == maxnum:
        print(secondnum)
    else:
        print(maxnum)

Submission status: Wrong Answer

Solution code:
N =int(input())
nums = [int(input()) for i in range(N)]
A = set(nums)
m1 = sorted(A)[-1]
l = len(A)
if l == 1:
  print(m1)
else:
  for i in range(N):
    if nums[i] == m1:
      m2 = sorted(set(nums))[-2]
      print(m2)      
    else:
      print(m1)

Submission status: Wrong Answer

Solution code:
N =int(input())
nums = [int(input()) for i in range(N)]
m1 = sorted(set(nums))[-1]
for i in range(N):
  if nums[i] == m1:
    if len(set(nums)) == 1 :
      print(m1)
    else:
      m2 = sorted(set(nums))[-2]
      print(m2)      
  else:
    print(m1)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

m = max(a)

for i in range(n):
  if m != a[i]:
    print(m)
    continue
  else:
    print(max(max(a[:i],a[i+1:])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

values = [0]*N
value_count_map = {}
for i in range(N):
    in_value = int(input())
    values[i] = in_value
    value_count = 0
    if in_value in value_count_map:
        value_count = value_count_map[in_value]
    value_count_map[in_value] = value_count + 1

sorted_values = sorted(value_count_map.keys(), reverse=True)
max_value = sorted_values[0]
next_max_value = max_value
if len(sorted_values) > 1:
    next_max_value = sorted_values[1]

for row in range(N):
    if value_count > 1:
        print(max_value)
    elif values[row] == max_value:
        print(next_max_value)
    else:
        print(max_value)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*(n)
num = 0
max = 0
smax = 0
for i in range(n):
    a[i] = int(input())
for i in range(n):
    if a[i] > max:
        max = a[i]
        num = i
for j in range(n):
    if j != i:
        if a[j] > smax:
            smax = a[j]
for j in range(n):
    if j == num:
        max = smax
    print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*(n)
num = 0
max = 0
smax = 0
for i in range(n):
    a[i] = int(input())
for i in range(n):
    if a[i] > max:
        max = a[i]
        num = i
for j in range(n):
    if j != i:
        if a[j] > smax:
            smax = a[j]
for j in range(n):
    if j == i:
        max = smax
    print(max)