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: Accepted

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

l=sorted(a)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
lst = []
for _ in range(n):
  lst.append(int(input()))
max_idx = np.argmax(lst)
max_ = lst[max_idx]
lst[max_idx] = 0
next_max_ = max(lst)

for i in range(len(lst)):
  if i == max_idx:
    print(next_max_)
  else:
    print(max_)

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

max_num = max(A)
max_i = A.index(max_num)
A.remove(max_num)
second_max = max(A)
new_list = [max_num for _ in range(N)]

new_list[max_i] = second_max
print(*[val for sublist in new_list for val in sublist], sep='\n')

Submission status: Accepted

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

n = int(input())
nums = [None] * n

for i in range(n):
    nums[i] = int(input())
sorted_nums = sorted(nums)

for num in nums:
    max_val = sorted_nums[n - 1]
    if num == max_val:
        max_val = sorted_nums[n - 2]
    print(max_val)

Submission status: Accepted

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

n = int(input())
nums = [None] * n

for i in range(n):
    nums[i] = int(input())
sorted_nums = sorted(nums)

for i in range(n):
    max_val = sorted_nums[n - 1]
    if nums[i] == max_val:
        max_val = sorted_nums[n - 2]
    print(max_val)

Submission status: Accepted

Solution code:
n = int(input())
nums = [None] * n

for i in range(n):
    nums[i] = int(input())
sorted_nums = sorted(nums)

for i in range(n):
    max_val = sorted_nums[n - 1]
    if nums[i] == max_val:
        max_val = sorted_nums[n - 2]
    print(max_val)

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(input()) for _ in range(n)]
sorted_a_list = sorted(a_list)
max_num = sorted_a_list[-1]
second_max_num = sorted_a_list[-2]

result = [0]*n
for i in range(n):
    if a_list[i] == max_num:
        result[i] = second_max_num
    else:
        result[i] = max_num

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    # [4, 3, 3, 1, 3, 2]
    A = [int(input()) for _ in range(N)]
    current_max = max(A[1:N])
    current_max_index = A.index(current_max)
    # print('---')
    print(current_max)
    previous_max = current_max
    previous_max_index = current_max_index
    for i in range(1, N):
        # A_tmp = A[0:i] + A[i+1:N]
        if i != previous_max_index:
            current_max = max([A[i-1], previous_max])
            current_max_index = previous_max_index
        else:
            current_max = max(A[0:i] + A[i+1:N])
            current_max_index = A.index(current_max)
        print(current_max)
        previous_max = current_max
        previous_max_index = current_max_index


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): #最小公倍数
  return a * b // gcd (a, b)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#input stock
"""
n = int(input())

#list
a = map(int, input().split())
a,b = map(int, input().split())

#縦1dim-list
a = [int(input()) for i in range(n)]

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

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""


#math
"""
#切り捨て
math.floor()
# 切り上げ
math.ceil()
"""

#######################################
n = int(input())
a = [int(input()) for i in range(n)]
a = np.array(a)
max_idx = np.argmax(a)
max_val = np.max(a)

for i in range(max_idx):
  print(max_val)

tmp = np.delete(a, max_idx)
print(np.max(tmp))

for i in range(n-max_idx-1):
  print(max_val)

Submission status: Accepted

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:
            second_num = max_num
            max_num = nums[i]
        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: Accepted

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

# 最大値が２個以上あれば最大値を出力する
# 最大値が１個しか無ければ、最大値のアドレスでは２番めの値を出力する

max_value = max(A)
max_count = A.count(max_value)
max_address = A.index(max_value)

if max_count >= 2:
    for _ in range(N):
        print(max_value)
else:
    for i in range(N):
        if i == max_address:
            A.pop(max_address)
            print(max(A))
        else:
            print(max_value)

Submission status: Accepted

Solution code:
#coding utf-8
N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))

M=max(A)
x=A.index(M)
A[x]=-1
M2=max(A)

for i in range(N):
  if i==x:
    print(M2)
  else:
    print(M)

Submission status: Accepted

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

max_a = 0
for i in (range( n )) :
  temp = int( input())
  if temp > max_a : max_a = temp
  a.append( temp )
a_copy = a

max_index = a.index( max_a )
a_copy.pop( max_index )
max_a2 = max( a_copy )

for i in range( n ) :
  if i != max_index : print( max_a )
  else              : print( max_a2 )

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for _ in range(n)]
max_num = max(l)
second_num = sorted(l)[-2]

for i in range(n):
   if l[i] == max_num:
       print(second_num)
   else:
       print(max_num)

Submission status: Accepted

Solution code:

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

first = max(A)
second = sorted(A)[-2]
for i in range(n):
    if first == A[i]:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(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: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
a2 = sorted(a)
ma = a2[-1]
se = a2[-2]
result = []
for i in range(n):
    if a[i] == ma:
        result.append(se)
    else:
        result.append(ma)
for j in range(n):
    print(result[j])

Submission status: Accepted

Solution code:
n = int(input())

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

maxn = max(a)


if (a.count(maxn) ==1):
  sortedset = sorted(set(a))
  max2n = max(a)
  if len(sortedset) > 1:
    max2n = sortedset[-2]
  for num in a:
    if num != maxn:
      print (maxn)
    else:
      print (max2n)
else:
  for num in a:
    print(maxn)

Submission status: Accepted

Solution code:
def main():
    a = int(input())
    lists= [int(input()) for _ in range(a)]
 
    temp = lists.copy()
    first = max(temp)
    temp.remove(first)
    second = max(temp)
 
    for i in range(a):
        if lists[i] == first:
            print(second)
        else:
             print(first)
 
if __name__ == '__main__' :
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(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: Accepted

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

nums_sorted = sorted(nums)  
biggest = nums_sorted[-1]
second_biggest = nums_sorted[-2]
max_ind = nums.index(biggest)

if nums.count(biggest) == 1:
  for i in range(n):
    if i == max_ind:
      print(second_biggest)
    else:
      print(biggest)
else:
  for i in range(n):
    print(biggest)

Submission status: Accepted

Solution code:
# coding:utf-8
def main():
    a = int(input())
    lists= [int(input()) for _ in range(a)]

    temp = lists.copy()
    first = max(temp)
    temp.remove(first)
    second = max(temp)

    for i in range(a):
        if lists[i] == first:
            print(second)
        else:
            print(first)

if __name__ == '__main__' :
    main()

Submission status: Accepted

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

sorted_lst = sorted(lst)
Max = sorted_lst[-1]
Submax = sorted_lst[-2]

for i in range(n):
    if lst[i] == Max:
        print(Submax)
    else:
        print(Max)

Submission status: Accepted

Solution code:
import sys
import copy
def input():
    return sys.stdin.readline()
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))


A = max(a)
if a.count(A) >= 2:
  for i in range(n):
    print(A)
else:
  index = a.index(A)
  for i in range(index):
    print(A)
  print(sorted(a)[-2])
  for i in range(index+1,n):
    print(A)

Submission status: Accepted

Solution code:
from operator import itemgetter

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

a = sorted(a, key=itemgetter(1))
for i in range(n):
    if i == a[-1][0]:
        maxx = a[-2][1]
    else:
        maxx = a[-1][1]
    print(maxx)

Submission status: Accepted

Solution code:

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

for _ in range(n):
    arr.append(int(input()))

max_1 = -9999999999
max_1_i = -1
max_2 = -9999999999
max_2_i = -1
for i in range(len(arr)):
    if max_1 <= arr[i]:
        max_2 = max_1
        max_2_i = max_1_i
        max_1 = arr[i]
        max_1_i = i
        
    else:
        if max_2 <= arr[i]:
            max_2 = arr[i]
            max_2_i = i

for i in range(len(arr)):
    if i == max_1_i:
        print(max_2)
    else:
        print(max_1)

Submission status: Accepted

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

sorted_list = sorted(input_list)

first_val = sorted_list[-1]
second_val = sorted_list[-2]

for i in input_list:
  if i == first_val:
    print(second_val)
  else:
    print(first_val)

Submission status: Accepted

Solution code:

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

    sorted_a = sorted(a, reverse=True)
    one = sorted_a[0]
    two = sorted_a[1]

    for i in range(n):
        if one == a[i]:
            print(two)
        else:
            print(one)

main()

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	A = [0]*N
	for i in range(N):
		A[i] = int(input())
	a = list(A)
	a.sort(reverse=True)
	for i in range(N):
		if a[0] == A[i]:
			print(a[1])
		else:
			print(a[0])


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a, reverse = True)

a1 = b[0]
a2 = b[1]



for i in range(n):
	if a[i] == a1:
		print(a2)
	else:
		print(a1)

Submission status: Accepted

Solution code:
def C_ExceptionHandling():
    N = int(input())
    A = [int(input()) for x in range(N)]
    a_left = [0] * (N + 1)
    a_right = [0] * (N + 1)
    for x in range(N):
        a_left[x+1] = max(a_left[x], A[x])
        a_right[-x-2] = max(a_right[-x-1], A[-x-1])
    for x in range(N):
        print(max(a_left[x], a_right[x+1]))
    
if __name__ == "__main__":
    C_ExceptionHandling()

Submission status: Accepted

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

m1 = max(a)
mi = a.index(m1)
a.pop(mi)

m2 = max(a)

for i in range (n):
    if i == mi: print(m2)
    else: print(m1)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
one = max(a)
i = a.index(one)
two = max(a[:i] + a[i+1:])
for x in range(n):
  if x == i:
    print(two)
  else:
    print(one)

Submission status: Accepted

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

max_a = max(a)
sec_max_a = sorted(a)[-2]
ans = [max_a]*N
max_index = []
for i in range(N):
  if a[i] == max_a:
    max_index.append(i)
#print(max_index)

for i in max_index:
  ans[i] = sec_max_a
for i in ans:
  print(i)

Submission status: Accepted

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

temp = sorted(List)

ma = temp[N-1]
se = temp[N-2]

for i in range(N):
    if (List[i] == ma):
        print(se)
    else:
        print(ma)

Submission status: Accepted

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

sorted_a = sorted(a)

max_a = sorted_a[-1]
max_a_r = sorted_a[-2]

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

Submission status: Accepted

Solution code:
import numpy as np


n=int(input())
aList=[]
for i in range(n):
    aList.append(int(input()))


maxIndex = np.argmax(aList)
maxVal = aList[maxIndex]
del aList[maxIndex]
secondMaxVal= max(aList)


for i in range(n):
    if i==maxIndex:
        print(secondMaxVal)
    else:
        print(maxVal)

Submission status: Accepted

Solution code:
N = int(input())
li = list(int(input()) for _ in range(N))
li_sorted = sorted(li)
max = li_sorted[-1]
premax = li_sorted[-2]
for i in range(N):
  if li[i] == max:
    print(premax)
  else:
    print(max)

Submission status: Accepted

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

sorted_a = sorted(a)
max_a = sorted_a[-1]
max_a_r = sorted_a[-2]

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
m=max(a)
x=[i for i, x in enumerate(a) if x == m]
if(len(x)>=2):
  for i in range(n):
    print(m)
else:
  a.remove(m)
  M=max(a)
  for i in range(n):
    if(i==x[0]):
      print(M)
    else:
      print(m)

Submission status: Accepted

Solution code:
N = int(input())
A = []
first = 0
second = 0
for i in range(N):
    x = int(input())
    if x > first:
        first = x
    elif x >= second:
        second = x
    A.append(x)
for i in range(N):
    if A[i] == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
n = int(input())
li = []
for i in range(n):
  li.append(int(input()))
li_2 = sorted(li)
m_1 = li_2[-1]
m_2 = li_2[-2]
for i in range(n):
  if m_1 == li[i]:
    print(m_2)
  else:
    print(m_1)

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())
A = [int(input()) for _ in range(N)]
v = max(A)
i = A.index(v)
u = max(A[:i] + A[i + 1:])
for j in range(N):
    print(u if i == j else v)

Submission status: Accepted

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,reverse=True)
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: Accepted

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

    m = max(A)
    a = A.index(m)
    A.pop(a)
    b = max(A)

    for i in range(N):
        if i == a:
            print(b)
        else:
            print(m)


if __name__ == '__main__':
    p_c()

Submission status: Accepted

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 range(N):
  if a[i]!=max:
    print(max)
  else:
    print(max2)

Submission status: Accepted

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

Submission status: Accepted

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

a_sorted = sorted(a)

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

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range(0,N):
    A.append(int(input()))
a=max(A)
b=A.count(a)
if b>1:
    for i in range(0,N):
        print(a)
else:
    for i in range(0,N):
        if A[i]!=a:
            print(a)
        else:
            A[i]=0
            print(max(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

max_values = [-1, -1]
max_indices = [-1, -1]
for i in range(N):
  a = int(input())
  if a>max_values[0]:
    max_values[0] = a
    max_indices[0] = i
  elif a>max_values[1]:
    max_values[1] = a
    max_indices[1] = i

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc134/tasks/abc134_c

N = int(input())
numlist = []
for _ in range( N ):
    a = int(input())
    numlist.append( a )

numlist2 = sorted(numlist)
first  = numlist2[ -1 ]
second = numlist2[ -2 ]

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

Submission status: Accepted

Solution code:
import heapq
N = int(input())
a_ls = []
q_ls = []
_max = 0
_second = 0
_max_dupli = False
for i in range(N):
    a = int(input())
    a_ls.append(a)
    heapq.heappush(q_ls, -a)
_max = heapq.heappop(q_ls)
_second = heapq.heappop(q_ls)
_max = -_max
_second = -_second
for i in range(N):
    if a_ls[i] == _max:
        print(_second)
    else:
        print(_max)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
MAX = max(A)
count = A.count(MAX)
if count >= 2:
    for i in range(N):
        print(MAX)
else:
    for i in range(N):
        if A[i] == MAX:
            SECOND = max(A[:i] + A[i+1:])
            print(SECOND)
        else:
            print(MAX)

Submission status: Accepted

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

Submission status: Accepted

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

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: Accepted

Solution code:
N = int(input())
list = [int(input()) for i in range(N)]
if sorted(list)[-1] == sorted(list)[-2]:
    list2 = [max(list)]*N
    print("\n".join(map(str,list2)))
else:
    list2 = [max(list)]*list.index(max(list))
    list2.append(sorted(list)[-2])
    list3 = [max(list)]*(N-list.index(max(list))-1)
    list2.extend(list3)
    print("\n".join(map(str,list2)))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_sorted = sorted(a, reverse=True)[:2]
print('\n'.join(map(str, [a_sorted[an == a_sorted[0]] for an in a])))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
a_sorted = sorted(a)[::-1][:2]
for an in a:
    print(a_sorted[an == a_sorted[0]])

Submission status: Accepted

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

    maxA = 0
    maxA_idx = 0
    for i in range(n):
        if A[i] > maxA:
            maxA_idx, maxA = i, A[i]
    maxA2nd = 0
    maxA2_idx = 0
    for i in range(n):
        if i != maxA_idx and A[i] > maxA2nd:
            maxA2_idx, maxA2nd = i, A[i]

    for i in range(n):
        if i != maxA_idx:
            print(maxA)
        else:
            print(maxA2nd)
    # return


if __name__ == '__main__':
    # print(main())
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

m = max(A)

# 最大値をとる要素が何個あるかチェック
c = 0
for a in A:
    if a == m:
        c += 1

# 二番目
if len(A) > c:
    second = max([v for v in A if v != m])    

for i, a in enumerate(A):
    if a == m:
        if c > 1:
            print(m)
        else:
            print(second)
    else:
        print(m)

Submission status: Accepted

Solution code:
N = int(input())
A = list()

for i in range(0, N):
  A_i = int(input())
  A.append(A_i)

A_sorted = sorted(A, reverse=True)

for val in A:
  result = A_sorted[0]
  if val == A_sorted[0]:
    result = A_sorted[1]
  print(result)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
max_num = 0
for i in range(N):
    if A[i] == m:
        max_num += 1
        if max_num >1:
            print(m)
        else:
            print(max(A[:i]+A[i+1:]))
    else:
        print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
# /usr/bin/python3

def main():
  N = int(input())
  liA = list(map(int, [input() for _ in range(N)]))
  first, second = sorted(liA, reverse=True)[0:2]
  for a in liA:
    if a == first:
      print(second)
    else:
      print(first)
  pass

if __name__=='__main__':
  main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(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: Accepted

Solution code:
N=int(input())

max1,max2=-1,-1
alist=[]
for i in range(N):
  a=int(input())
  alist.append(a)
  if max1 <= a:
    max2 = max1
    max1 = a
  elif max2 < a:
    max2 = a
  
for a in alist:
  if a == max1:
    print(max2)
  else:
    print(max1)

Submission status: Accepted

Solution code:
n = int(input())
a_list = []
for _ in range(n):
    a_list.append(int(input()))
max_list = [0, 0]
for a in a_list:
    if a > max_list[0]:
        max_list[0] = a
    elif a > max_list[1]:
        max_list[1] = a
for a in a_list:
    if not a == max_list[0]:
        print(max_list[0])
    else:
        print(max_list[1])

Submission status: Accepted

Solution code:
import numpy as np

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

num_max = np.max(nums)
next_max = sorted(nums)[-2]


for idx, el in enumerate(nums):
	if num_max == el:
		print(next_max)		
	else:
		print(num_max)

Submission status: Accepted

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

sorted_li = sorted(li)
a, b = sorted_li[-1], sorted_li[-2]

for i in li:
  if i == a:
    print(b)
  else:
    print(a)

Submission status: Accepted

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

B = A[:]

a1 = max(A)
A.remove(a1)
a2 = max(A)

for i in range(N):
    if B[i] != a1:
        print(a1)
    else:
        print(a2)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
max_v = max(a)
a_copy = a[:]
a_copy.remove(max_v)
max_v2 = max(a_copy)
for i in a:
  if i != max_v:
    print(max_v)
  else:
    print(max_v2)

Submission status: Accepted

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

N = int(input())
A = [int(input()) for x in range(N)]
max1, max2 = sorted(A, reverse=True)[:2]
for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

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

b = sorted(a)
m = b[-1]
m1 = b[-2]

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

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    m1, m2 = sorted(a, reverse=True)[:2]
    return "\n".join(map(str, [m2 if _a == m1 else m1 for _a in a]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    m1, m2 = sorted(a)[::-1][:2]
    return "\n".join(map(str, [m2 if _a == m1 else m1 for _a in a]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    m1, m2 = sorted(a)[-2:]
    return "\n".join(map(str, [m1 if _a == m2 else m2 for _a in a]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    m1, m2 = sorted(a)[-2:]
    index = a.index(m2)
    return "\n".join(map(str, [m1 if i == index else m2 for i in range(n)]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    m1, m2 = sorted(a)[-2:]
    index = a.index(m2)
    return "\n".join([str(m1) if i == index else str(m2) for i in range(n)])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

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

Submission status: Accepted

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

mx, mxn = sorted(A, reverse=True)[:2]

result = [mxn if x==mx else mx for x in A]
print('\n'.join(map(str, result)))

Submission status: Accepted

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

mx, mxn = sorted(A, reverse=True)[:2]

for i in range(N):
    if A[i] == mx:
        print(mxn)
    else:
        print(mx)

Submission status: Accepted

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

sort = sorted(A, reverse=True)
mx = sort[0]
mxn = sort[1]

for i in range(N):
    if A[i] == mx:
        print(mxn)
    else:
        print(mx)