Problem:


Score : 300 points

Problem Statement

You are given a sequence of length N: A_1, A_2, ..., A_N.
For each integer i between 1 and N (inclusive), answer the following question:

Find the maximum value among the N-1 elements other than A_i in the sequence.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.

The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.

The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.

Sample Input 2

2
5
5

Sample Output 2

5
5



Sample input:
3
1
4
3


Sample output:
4
3
4

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_sorted = sorted(A, reverse=True)
    A_max = A_sorted[0]
    found_semi_max = False
    for i in range(N):
        if A_max != A_sorted[i]:
            A_semi_max = A_sorted[i]
            found_semi_max = True
            break
    
    for i in range(N):
        if A[i] == A_max and found_semi_max:
            print(A_semi_max)
        else:
            print(A_max)
main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    A_sorted = sorted(A, reverse=True)
    A_max = A_sorted[0]
    A_max_idx = []
    found_semi_max = False
    for i in range(N):
        if A_max == A[i]:
            A_max_idx.append(i)
    for i in range(N):
        if A_max != A_sorted[i]:
            A_semi_max = A_sorted[i]
            found_semi_max = True
            break
    
    for i in range(N):
        if (i in A_max_idx) and found_semi_max:
            print(A_semi_max)
        else:
            print(A_max)
main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    A_sorted = sorted(A, reverse=True)
    A_max_idx = []
    A_max = A_sorted[0]
    found_semi_max = False
    for i in range(N):
        if A_max == A[i]:
            A_max_idx.append(i)
    for i in range(N):
        if A_max != A_sorted[i]:
            A_semi_max = A_sorted[i]
            found_semi_max = True
            break

    for i in range(N):
        if (i in A_max_idx) and found_semi_max:
            print(A_semi_max)
        else:
            print(A_max)
main()

Submission status: Wrong Answer

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

A_sorted = sorted(A, reverse=True)
A_max_idx = []
A_max = A_sorted[0]
for i in range(N):
    if A_max == A[i]:
        A_max_idx.append(i)

found_semi_max = False
for i in range(N):
    if A_max != A_sorted[i]:
        A_semi_max = A_sorted[i]
        found_semi_max = True
        break

for i in range(N):
    if i in A_max_idx and found_semi_max:
        print(A_semi_max)
    else:
        print(A_max)

Submission status: Wrong Answer

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

for i in a:
    i = 0
    print(max(a))

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

lis = []
for _ in range(n):
    lis.append(int(input()))
    
slis = sorted(copy.deepcopy(lis), reverse=True)
    
m = max(lis)
s = sorted(set(slis), reverse=True)
s.remove(m)
if s:
    sm  = max(s)
else:
    sm = m

for i in range(n):
    if lis[i] != m:
        print(m)
    else:
        print(sm)

Submission status: Wrong Answer

Solution code:
n = int(input())
apple = []
for _ in range(n):
    apple.append(int(input()))
big = sorted(apple)[-1]
print(big)
for i in range(1, n):
    if apple[i] != big:   
        if apple[i-1] >= big:
            print(apple[i-i])
            big = apple[i-1]
        else:
            print(big)
    else:
        orange = apple[0:i] + apple[i+1:n]
        print(max(orange))
        big = max(orange)

Submission status: Wrong Answer

Solution code:
n = int(input())
apple = []
for _ in range(n):
    apple.append(int(input()))
big = max(apple[1:n+1])
print(big)
for i in range(1, n):
    if apple[i] != big:   
        if apple[i-1] >= big:
            print(apple[i-i])
            big = apple[i-1]
        else:
            print(big)
    else:
        orange = apple[0:i] + apple[i+1:n]
        print(max(orange))
        big = max(orange)

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())

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

for i in range(N):
    remain = set(A) - set([A[i]])

    if remain == set():
        print(A[i])
    else:
        print(max(remain))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())

set_a =  sorted(set(a))
if len(set_a) == 1:
    l = [set_a[-1]]*n
    print(*l)
    exit()
max_1 = set_a[-1]
max_2 = set_a[-2]
l = [max_2 if x == max_1 else max_1 for x in a]
print(*l)

Submission status: Wrong Answer

Solution code:
n   = int(input())
li1 = [int(input()) for i in range(n)]
li2 = li1.copy()
mx  = max(li1)

for i in range(n):
    if i==mx:
        li2.remove(li1[i])
        print(max(li2))
        li2.append(li1[i])
    else:
        print(mx)

Submission status: Wrong Answer

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

import heapq

h = []
for a in A:
    if len(h) < 2:
        heapq.heappush(h, a)
    else:
        heapq.heappushpop(h, a)

print('h', h)

for a in A:
    if a == h[1]:  # 最も大きい数値
        print(h[0])
    else:
        print(h[1])

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    max_A = max(A)
    max_A_2 = 1
    if len(set(A)) == 1:
        max_A_2 = max_A
    else:
        for a in A:
            if max_A_2 < a and a != max_A:
                max_A_2 = a

    for a in A:
        if a != max_A:
            print(max_A)
        else:
            print(max_A_2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
from itertools import permutations as perm


N = int(input())
#H1,M1,H2,M2,K= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())
l=[]
for i in range(N):
    B = int(input())
    l.append(B)

for i in range(N):
    a=l.pop(i)
    m=max(l)
    print(m,l,i)
    l.insert(i,a)

Submission status: Wrong Answer

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

m = max(A)
c = A.count(m)
if c == 1:
    m2 = sorted(set(A))[1]
    for i in A:
        print (m) if i != m else print(m2)
else:
    for _ in range(n):
        print (m)

Submission status: Wrong Answer

Solution code:
N = int(input())

max_num = -1
max_index = []
second_num = -1
dic = {}
for i in range(1, N+1):
    num = int(input())
    dic[i] = num
    if num > max_num:
        second_num = max_num
        max_num = num
        max_index.clear()
        max_index.append(i)
    elif num == max_num:
        max_index.append(i)
    elif second_num > num:
        second_num = num

for i in range(1, N+1):
    if dic[i] < max_num:
        print(max_num)
    elif dic[i] == max_num:
        if len(max_index) > 1:
            print(max_num)
        else:
            print(second_num)

Submission status: Wrong Answer

Solution code:
N = int(input())

max_num = -1
max_index = []
second_num = -1
dic = {}
for i in range(1, N+1):
    num = int(input())
    dic[i] = num
    if num > max_num:
        max_num = num
        max_index.clear()
        max_index.append(i)
    elif num == max_num:
        max_index.append(i)

    if num > second_num and num < max_num:
        second_num = num

for i in range(1, N+1):
    if dic[i] < max_num:
        print(max_num)
    elif dic[i] == max_num:
        if len(max_index) > 1:
            print(max_num)
        else:
            print(second_num)

Submission status: Wrong Answer

Solution code:
N = int(input())

max_num = -1
max_index = []
second_num = -1
dic = {}
for i in range(1, N+1):
    num = int(input())
    dic[i] = num
    if 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(1, N+1):
    if dic[i] < max_num:
        print(max_num)
    elif dic[i] == max_num:
        if len(max_index) > 1:
            print(max_num)
        else:
            print(second_num)

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):
	b=a.pop()
	print(max(a))
	a.append(b)

Submission status: Wrong Answer

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

for i in range(n):
    h.append(int(input()))
    
h_sort = sorted(h, reverse=True)

for i in range(n):
    if h[i] == h_sort[0]:
        print(h[1])
    else:
        print(h[0])

Submission status: Wrong Answer

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

for i in range(n):
    h.append(int(input()))
    
h_sort = sorted(h, reverse=True)

for i in range(n):
    if h[i] == h_sort[0]:
        print(h[1])
    else:
        print(h[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for i in range(N)]
import copy
B = copy.copy(A)
B.sort()
a1 = B[-1]
a2 = B[-2]
if a1 == a2:
  for i in range(N):
    print(a1)
else:
  for i in range(N):
    if A[i] == a1:
      print(a2)
    else:
      print(a1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [input() for i in range(N)]
import copy
B = copy.copy(A)
B.sort()
a1 = B[0]
a2 = B[1]
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)]
ans = 0
for i in range(n):
  for j in range(i-1,0):
    for k in range(i+1,n):
      ans1 = max(a[j],a[k])
      ans = max(0,ans1)
      print(ans)
b=0
for i in range(n-1):
  b = max(a[i],a[i+1])
  ans2 = max(b,0)
print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
ll = [[] for _ in range(n+1)]

count = 1
for i in range(n):
    ll[0].append(int(input()))
    ll[count] = ll[0].copy()
    ll[count][count-1] = 0
    max = 0
    for j in ll[count]:
        if j>max:
            max = j
        else:
            pass
    print(max)
    count+=1

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

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

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = ILs(N)

A.sort()

MAX1 = A[-1]
MAX2 = A[-2]

for a in A:
  if a == MAX1:
    P(MAX2)
  else:
    P(MAX1)

Submission status: Wrong Answer

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


N = inp()
A = []
i1, i2 = 0, 0

for i in range(N):
    A.append(inp())
    if A[i] > A[i1]:
        i1 = i


for i in range(N):
    if A[i] > A[i2] and i != i1:
        i2 = i
for i in range(N):
    if i != i1:
        print(A[i1])
    else:
        print(A[i2])

Submission status: Wrong Answer

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


N = inp()
A = []
i1, i2 = 0, 0
for i in range(N):
    A.append(inp())
    if A[i] > A[i1]:
        i1 = i
for i in range(N):
    if A[i] > A[i2] and i != i1:
        i2 = i

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

Submission status: Wrong Answer

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


N = inp()
A = []
m1, m2 = 0, 0
for i in range(N):
    A.append(inp())
    if A[i] > m1:
        m1 = A[i]
    if A[i] > m2 and A[i] < m1:
        m2 = A[i]
if m2 == 0:
    m2 = m1
for i in range(N):
    if A[i] != m1:
        print(m1)
    else:
        print(m2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
MAX = 0
SECOND = 0
MAX_COUNT = 0
for a in A:
    if a > MAX:
        MAX = a
        MAX_COUNT = 1
    elif a == MAX:
        MAX_COUNT += 1
    if a > SECOND and a != MAX:
        SECOND = a
for a in A:
    if a == MAX and MAX_COUNT == 1:
        print(SECOND)
    elif a == MAX and MAX_COUNT > 1:
        print(MAX)
    else:
        print(MAX)

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    maxA = max(A)
    countMax = A.count(maxA)
    if countMax > 1:
        [print(maxA) for _ in range(N)]
    else:
        next = -1
        maxIdx = A.index(maxA)
        if maxIdx == 0:
            next = max(A[1:])
        elif maxIdx == N - 1:
            next = max(A[:N - 1])
        else:
            next = max(max(A[0:maxIdx], A[maxIdx + 1:N]))
        for i in range(N):
            if not i == maxIdx:
                print(maxA)
            else:
                print(next)


resolve()

Submission status: Wrong Answer

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

for i in range(N):
    append(int(input()))
    
sum = sum(A)
for a in A:
    print(sum - a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
#print(a)
lm = [0] * n
rm = [0] * n

for i in range(1, n):
    lm[i] = max(a[i-1], lm[i-1])

for i in range(n-2, -1, -1):
    rm[i] = max(a[i+1], rm[i+1])

print(lm)
print(rm)

for i in range(n):
    print(max(lm[i], rm[i]))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
A = np.array(list(int(input()) for i in range(n)))
A_max = np.array([max(A)]*n)
A_dif = A - A_max
for i in range(n):
    if A_dif[i]<0:
        print(A_max)
    else:
        A_copy = A.copy()
        A_del = np.delete(A_copy, i)
        print(max(A_del))

Submission status: Wrong Answer

Solution code:
def exception_handling(n, ali):

    ali.sort(reverse=True)

    alimax = ali[0]
    alimax2 = ali[1]

    ans = []

    for i in ali:
        if i != alimax:
            ans.append(alimax)
        else:
            ans.append(alimax2)

    return ans

def main():
    n = int(input())
    ali = [int(input())for i in range(n)]
    ans = exception_handling(n, ali)
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
al = []
for i in range(n):
  a = int(input())
  al.append(a)
mal = max(al)
for i in range(n):
  if al[i] != mal:
    print(al[i])
  else:
    print(mal)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
print(sum(a)-min(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
print(sum(a)-max(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

n= int(input())
a = [int(input()) for i in range(n)]
a_s = sorted(a,reverse=True)

for i in range(n):
    ans = a[0]
    if a[i]==a_s[0]:
        ans = a[1]
    
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(input()) for i in range(N)]
B=[]
for k in range(N):
  A0=A[0]
  A.remove(A0)
  print(A)
  print(max(A))
  A.append(A0)

Submission status: Wrong Answer

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    N,=pin()
    A=[int(input())for i in range(N)]
    B=sorted(A)
    first=B[-1]
    second=B[-2]
    for a in A:
        if a==first:print(second)
        print(first)
          
#%%submit!    
resolve()

Submission status: Wrong Answer

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

m1=max(a)
m2=max(a[a.index(max(a)):]+a[:a.index(max(a))+1])
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 _ in range(N)]
AMax = max(A)
x = A.index(AMax)
Aelse = A[:x]+A[x+1:]
AelseMax = max(Aelse)
if AMax == AelseMax:
    for i in range(N):
        print(AMax)
else:
    for i in range(N):
        if x == i:
            print(AMax)
        else:
            print(AelseMax)

Submission status: Wrong Answer

Solution code:
N=int(input())

seq=[]

for i in range(N):

    a= int(input())
    
    seq.append(a)

numbers=set(seq)

A_max=list(numbers)[-1]

if N>=2:
    if len(numbers)>=2:
        A_second = list(numbers)[-2]
    else:
        A_second = A_max

for k in range(N):
    if seq[k]==A_max:
        print(A_second)
    else:
        print(A_max)

# 2.両端から
# left=[0]
# for i in range(N-1):
#     left_i=max(left[i],seq[i])

#     left.append(left_i)

# right=[0]

# for j in range(N-1):
#     right_j = max(right[j],list(reversed(seq))[j])

#     right.append(right_j)

# right = list(reversed(right))

# for k in range(N):
#     print(max(left[k],right[k]))

Submission status: Wrong Answer

Solution code:
inNum = int(input())

intArr = []

sortArr = []
while(inNum > 0):
    tempNum =int(input())
    intArr.append(tempNum)
    inNum = inNum-1
    if(not tempNum in sortArr):
        sortArr.append(tempNum)
sortArr  = sorted(sortArr, reverse = True)

for x in range(len(intArr)):
    if(intArr[x] != sortArr[0] or len(sortArr)==1):
        print(sortArr[0])
    else:
        print(sortArr[1])

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
  inNum = int(input())
  intArr = []


  while(inNum > 0):
      tempNum =int(input())
      intArr.append(tempNum)
      inNum = inNum-1

  intArr
  sortArr = intArr
  sortArr.sort()
  for x in intArr:
      if(not x == sortArr[-1]):
          print(sortArr[-1])
      if(x == sortArr[-1]):
          print(sortArr[-2])

Submission status: Wrong Answer

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

maxR = [0] * n
maxL = [0] * n
maximum = 0
for i in range(n):
    maximum = max(maximum,a[i])
    maxL[i] = maximum
maximum = 0
for i in range(n):
    maximum = max(maximum,a[n-i-1])
    maxR[n-i-1] = maximum


print(maxR[0])
for i in range(1,n-1):
    print(max(maxL[i-1],maxR[i+1]))
print(maxL[n-1])

Submission status: Wrong Answer

Solution code:
import itertools
import math
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
maxa = max(a)

b=[]
for i in range(n):
    b.append(a[i])
    if b[i] == maxa:
        b[i] = 0
maxb = max(b)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [[i, int(input())] for i in range(n)]
print(a)
a.sort(reverse=True, key=lambda x:x[1])
first, second = a[0][1], a[1][1]
a.sort(key=lambda x:x[0])
for i in range(n):
  print(first if a[i][1] != first else second)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [[i, int(input())] for i in range(n)]
a.sort(reverse=True, key=lambda x:x[1])
first, second = a[0][1], a[1][1]
a.sort(reverse=True, key=lambda x:x[0])
for i in range(n):
  print(first if a[i][1] != first else second)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=[int(input()) for i in range(n)]
t=sorted(v)
for i in v:
  print(t[1] if i==t[0] else t[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=[int(input()) for i in range(n)]
m1=v[0]
m2=v[1]
if m2>m1:m1,m2=m2,m1
for i in v:
  if i > m1:
    m2=m1
    m1=i
  elif i>m2:
    m2=i
for i in v:
  print(m2 if i==m1 else m1)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=[int(input()) for i in range(n)]
m1=m2=v[0]
for i in v:
  if i > m1:
    m2=m1
    m1=i
  elif i>m2:
    m2=i
for i in v:
  print(m2 if i==m1 else m1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
aa = [0,0]
for i in range(n):
    if a[i] >= aa[-1]:
        aa[-1] = a[i]
    else:
        if a[i] >= aa[-2]:
            aa[-2] = a[i]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
aa = [0,0]
for i in range(n):
    if a[i] >= aa[-1]:
        aa[-1] == a[i]
    else:
        if a[i] >= aa[-2]:
            aa[-2] == a[i]
if aa[-1] == aa[-2]:
    for i in range(n):
        print(aa[-1])
else:
    for i in range(n):
        if i == a.index(aa[-1]):
            print(aa[-2])
        else:
            print(aa[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[input() for i in range(N)]
num=max(A)
for i in range(N):
    if A[i]==num:
        D=A[0:i]+A[i+1:]
        print(max(D))
    else:
        print(num)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(input()) for _ in range(n)]
m=max(A)
p=A.index(m)
l=A[0]
for i in range(n):
	if i!=p:
		l=max(l,A[i])
for i in range(n):
	if i==p:
		print(l)
	else:
		print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [None for _ in range(N)]
for i in range(N):
  A[i] = int(input())
MAX = max(A)
As = sorted(list(set(A)),reverse = True)
print(MAX)
print(As)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [None for _ in range(N)]
for i in range(N):
  A[i] = int(input())
MAX = max(A)
As = sorted(list(set(A)),reverse = True)
if len(set(A)) > 1:
  second = As[1]
for i in range(N):
  if A[i] != MAX:
    print(MAX)
  elif len(set(A)) == 1:
    print(MAX)
  else:
    print(second)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(input() for _ in range(N))
B = A[:]
B.sort()
mx = B[-1]
mx2 = B[-2]

if mx == mx2:
  for _ in range(N):
    print(mx)
  exit()
for a in A:
  if a == mx:
    print(mx2)
  else:
    print(mx)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = list(input() for _ in range(N))
B = A[:]
B.sort()
mx = B[-1]
mx2 = B[-2]

for a in A:
  if a == mx:
    print(mx2)
  else:
    print(mx)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = list(input() for _ in range(N))
B = A[:]
B.sort()
mx = B[-1]
mx2 = B[-2]
print(mx, mx2)
for a in A:
  if a == mx:
    print(mx2)
  else:
    print(mx)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
m = max(l)
ans = [m]*n
if len(set(l)) == 1:
    for i in ans:
        print(i)
else:
    x = sorted(set(l))[-2]
    a = [index for index, value in enumerate(l) if value == m]
    for i in a:
        ans[i] = x
    for i in ans:
        print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
m = max(l)
ans = [m]*n
if len(set(l)) == 1:
    [print(i) for i in ans]
else:
    x = sorted(set(l))[-2]
    a = [index for index, value in enumerate(l) if value == m]
    for i in a:
        ans[i] = x
    [print(i) for i in ans]

Submission status: Wrong Answer

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

def resolve():
    n=int(input())
    l=[int(input()) for i in range(n)]

    if len(set(l))==1:
        for i in range(n):
            print(max(l))
    else:
        biggest = max(l)
        niban=sorted(set(l))[-2]
        for j in range(n):
            if l[j]!=biggest:
                print(biggest)
            else:
                print(niban)
resolve()

Submission status: Wrong Answer

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

def resolve():
    n=int(input())
    l=[int(input()) for i in range(n)]
    biggest=max(l)
    if len(set(l))==1:
        niban=max(l)
    else:
        niban=sorted(set(l))[-2]
    for j in range(n):
        if l[j]!=biggest:
            print(biggest)
        else:
            print(niban)
resolve()

Submission status: Wrong Answer

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

d = {i: v for i, v in enumerate(a)}
d = dict(sorted(d.items(), key=lambda x:x[1],reverse=True))
#print(d)
#print("===")
k_t = list(d.keys())[0]
v_t = list(d.values())[0]
v_s = list(d.values())[1]
for i in range(n):
    if i == k_t:
        print(v_s)
    else:
        print(v_t)

Submission status: Wrong Answer

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

d = {i: v for i, v in enumerate(a)}
d = dict(sorted(d.items(), key=lambda x:x[1],reverse=True))
#print(d)
#print("===")
for i in range(n):
    if i == list(d.keys())[0]:
        print(list(d.values())[1])
    else:
        print(list(d.values())[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for i in range(n)]
t=max(a)
s=a.index(t)
a.pop(s)
u=max(a)
a.insert(s,a)
for i in range(n):
  if a[i]!=t:
    print(t)
  else:
    print(u)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for i in range(n)]
t=max(a)
if a.count(t)>1:
  for i in range(n):
    print(t)
else:
  
  s=a.index(t)
  a=a[:s]+a[s+1:]
  u=max(a)
  for i in range(n):
    if i!=s:
      print(t)
    else:
      print(u)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for i in range(n)]
t=max(a)
if a.count(t)>1:
  for i in range(n):
    print(t)
else:
  
  s=a.index(t)
  a.pop(s)
  u=max(a)
  for i in range(n):
    if i!=s:
      print(t)
    else:
      print(u)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for i in range(n)]
t=max(a)
s=a.index(t)
a.pop(s)
u=max(a)
for i in range(n):
  if i!=s:
    print(171429)
  else:
    print(u)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for i in range(n)]
t=max(a)
s=a.index(t)
a.pop(s)
u=max(a)
for i in range(n):
  if i!=s:
    print(t)
  else:
    print(u)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[input() for _ in range(n)]
b=sorted(a)
b=b[::-1]
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=[input() for _ in range(n)]
b=sorted(a)
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=[input() for i in range(n)]
t=max(a)
s=a.index(t)
a.pop(s)
u=max(a)
for i in range(n):
  if i==s:
    print(u)
  else:
    print(t)