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())
b = [int(input()) for _ in range(N)]
a = sorted(b)
ma = a[-1]
sa = a[-2]
for c in b:
    if c == ma:print(sa)
    else:print(ma)

Submission status: Accepted

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

Submission status: Accepted

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

max_1 = sorted(lis)[-1]
max_2 = sorted(lis)[-2]

for i in range(n):
    if lis[i] == max_1:
        print(max_2)
    else:
        print(max_1)

Submission status: Accepted

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

max_ = max(a_s)
max2 = sorted(a_s)[-2]
for a in a_s:
    if a == max_:
        print(max2)
    else:
        print(max_)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
b=a.copy()
ma=max(a)
a.remove(ma)
ma2 = max(a)
for i in range(n):
    if b[i]==ma:
        print(ma2)
    else:
        print(ma)

Submission status: Accepted

Solution code:
n=int(input())
al=[int(input()) for _ in range(n)]
b=al[:]
b=sorted(b,reverse=True)
m=max(al)
if al.count(m)>1:
    for _ in range(n):
        print(m)
else:
    for a in al:
        if a==m:
            print(b[1])
        else:
            print(m)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
  A=int(input())
  a.append(A)
  b.append(A)
b.sort()
max1=b[n-1]
max2=b[n-2]
for i in range(n):
  if a[i]==max1:
    print(max2)
  else:
    print(max1)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(input()) for i in range(N)]
sortA = sorted(A)
maxA = sortA[-1]
count_a = Counter(A)
if count_a[maxA] >= 2:
    for i in range(N):
        print(maxA)
elif count_a[maxA] == 1:
    for a in A:
        if a == maxA:
            print(sortA[-2])
        else:
            print(maxA)

Submission status: Accepted

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

num_max = max(li)
cnt = li.count(num_max)

if cnt >= 2:
    for i in range(n):
        print(num_max)
else:
    s = li.index(num_max)
    for i in range(n):
        if i != s:
            print(num_max)
        else:
            li[i] = 0
            print(max(li))

Submission status: Accepted

Solution code:


def submit():
    # read input
    n = int(input())

    first = 0
    second = 0

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

        if alist[-1] > first:
            second = first
            first = alist[-1]
        elif alist[-1] > second:
            second = alist[-1]

    for a in alist:
        if a == first:
            print(second)
        else:
            print(first)


    return


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
a_list = [[int(elem) for elem in fin().split()][0] for _ in range(N)]

sorted_a = sorted(a_list)
all_max = sorted_a[-1]
all_second = sorted_a[-2]

for i in range(N):
    if a_list[i] == all_max:
        print(all_second)
    else:
        print(all_max)

Submission status: Accepted

Solution code:
import sys

n= int(sys.stdin.readline())
ai= [ int(sys.stdin.readline()) for _ in range(n) ]
m= max(ai)
j=ai.index(m)
for i in range(n):
    if i==j: print( max(ai[:i]+ai[i+1:]) )
    else: print(m)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np
# from fractions import gcd
# import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()
    """この下から書いてね"""
    n = ip.I()
    a = ip.ILS(n)

    m = max(a)
    m2 = sorted(a)[-2]
    # m3 = sorted(a)[3]

    if m == m2:
        for _ in r(n):
            print(m)
    else:
        for i in r(n):
            if a[i] == m:
                print(m2)
            else:
                print(m)


main()

Submission status: Accepted

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

B  = copy.deepcopy(A)
B.sort()
M1 = B[-1]
M2 = B[-2]

for i in range(N):
    if A[i] == M1:
        print(M2)
    else:
        print(M1)

Submission status: Accepted

Solution code:
n = int(input())
l = []
mx = 0
mn = 0
for i in range(n):
    a = int(input())
    l.append(a)
    if a > mx:
        mx = a
        mn = i+1
l.sort()
if l.count(mx) > 1:
    for i in range(n):
        print(mx)
else:
    for i in range(mn-1):
        print(mx)
    print(l[n-2])
    for i in range(n-mn):
        print(mx)

Submission status: Accepted

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

B = sorted(A, reverse=True)


MAX1 = B[0]
MAX2 = B[1]


if MAX1 == MAX2:
    for a in range(N):
        print(MAX1)
else:
    for a in A:
        if a != MAX1:
            print(MAX1)
        else:
            print(MAX2)

Submission status: Accepted

Solution code:
n = int(input())
a_list = []
first = 0
second = 0
for i in range(n):
    a = int(input())
    if a >= first:
        second = first
        first = a
    elif a >= second:
        second = a
    a_list.append(a)

for i in a_list:
    if i == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

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

left = [0 for i in range(n+1)]
right = [0 for i in range(n+1)]

for i in range(n+1):
    if i == 0:
        left[i] = -10000000000
        continue
    if A[i-1] > left[i-1]:
        left[i] = A[i-1]
    else:
        left[i] = left[i-1]

for i in reversed(range(n+1)):
    if i == n:
        right[i] = -10000000000
        continue
    if A[i] > right[i+1]:
        right[i] = A[i]
    else:
        right[i] = right[i+1]

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

Submission status: Accepted

Solution code:
n = int(input())
first = 0
second = 0
x1 = 0
for i in range(n):
  a = int(input())
  if a > second:
    if a > first:
      second = first
      first = a
      x1 = i
    else:
      second = a
for i in range(x1):
  print(first)
print(second)
for i in range(x1+1,n):
  print(first)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
l,r=0,0
lm=[0]
rm=[0]
for i in range(n):
    l=max(l,a[i])
    r=max(r,a[-1-i])
    lm.append(l)
    rm.append(r)
for i in range(n):
    print(max(lm[i],rm[n-i-1]))

Submission status: Accepted

Solution code:
from collections import *
n=int(input())
l=[int(input()) for i in range(n)]
dic=Counter(l)
s=set(l)
a=max(s)
if(len(s)>1):
    s.remove(a)
    b=max(s)
for i in range(n):
    if(l[i]==a and dic[a]>1):
        print(a)
    elif(l[i]!=a):
        print(a)
    else:
        print(b)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
    temp = int(input())
    A.append((temp, i))
A.sort(key = lambda x: -x[0])

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=[0]*2
index=[-1]*2
for i in range(n):
    if m[0]<a[i]:
        m[1]=m[0]
        index[1]=index[0]
        m[0]=a[i]
        index[0]=i
    elif m[1]<=a[i]:
        m[1]=a[i]
        index[1]=i
for i in range(n):
    if i==index[0]:
        print(m[1])
    else:
        print(m[0])

Submission status: Accepted

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

m = list(sorted(A))
if m[-1] == m[-2]:
    for _ in range(N):
        print(m[-1])
else:
    for _ in A:
        if _ == m[-1]:
            print(m[-2])
        else:
            print(m[-1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())

first, second = sorted(A,reverse=True)[:2]
for i in range(N):
    if A[i] == first:
        print(second)
    else:
        print(first)

Submission status: Accepted

Solution code:
N = int(input())

max1 = 0
max2 = 0

arr = []

for i in range(N):
    a = int(input())
    arr.append(a)
    if a >= max1:
        max2 = max1
        max1 = a
    elif a > max2:
        max2 = a

for i in range(N):
    if arr[i] == max1:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
from sys import stdin
from sys import stdout
n = int(input())
a = [int(stdin.readline()) for _ in range(n)]
s = max(a)
cnt = a.count(s)
if cnt > 1:
    for x in a:
        stdout.write("{}\n".format(s))
    quit()
t = -1
for x in a:
    if x != s:
        t = max(t, x)
for x in a:
    stdout.write("{}\n".format(s if x != s else t))

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

L = []
n = []

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

L = sorted(L)
if L[-1] == L[-2]:
	for i in range(N):
		print(L[-1])
else:
	for i in range(N):
		if n[i] == L[-1]:
			print(L[-2])
		else:
			print(L[-1])

Submission status: Accepted

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


max_a = max(a)

max_a_count = 0
for i in range(n):
    if a[i] == max_a:
        max_a_count += 1

if max_a_count > 1:
    for i in range(n):
        print(max_a)
elif max_a_count == 1:
    b = sorted(range(len(a)), key=a.__getitem__)
    for i in range(n):
        if a[i] != max_a:
            print(max_a)
        else:
            print(a[b[-2]])

Submission status: Accepted

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

from collections import Counter

a_c = Counter(a)

first = max(a_c)
a_c[first] -= 1
second = max(+a_c)

for ai in a:
    if ai != first:
        print(first)
    else:
        print(second)

Submission status: Accepted

Solution code:
import sys

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

    B = sorted(A, key=lambda x: -x)
    for a in A:
        if a == B[0]:
            print(B[1])
        else:
            print(B[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = []
m = 0
count = 0
for _ in range(N):
    a = int(input())
    A.append(a)
    if a > m:
        m = a
        count = 1
    elif a == m:
        count += 1
B = A[:]
B.sort(reverse=True)

for a in A:
    if a == m:
        if count > 1:
            print(a)
        else:
            print(B[1])
    else:
        print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 最大値はひとつだけ、自分自身が最大値の場合を除く

n = int(input())
max_a, max_ai = 0, 0
arr = []
for i in range(n):
    a = int(input())
    arr.append(a)
    if a > max_a:
        max_a = a
        max_ai = i + 1
arr = sorted(arr)

for i in range(n):
    if max_ai == i + 1:
        print(arr[-2])
    else:
        print(max_a)

Submission status: Accepted

Solution code:
N = int(input())

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

sort_A = sorted(A)
max_A = sort_A[-1]
next_max_A = sort_A[-2]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

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


    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Accepted

Solution code:
N = int(input())
max_1 = 0
max_2 = 0
max_1_index = -1
for i in range(N):
	new_num = int(input())
	if max_1 <= new_num:
		max_2 = max_1
		max_1 = new_num
		max_1_index = i
	elif max_2 <= new_num:
		max_2 = new_num
	
for i in range(N):
	if max_1_index == i:
		print(max_2)
	else:
		print(max_1)

Submission status: Accepted

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = ii2nn(N)
    Ai = [(i, a) for i, a in enumerate(A)]
    Ai.sort(key=lambda v: v[1])
    i1 = Ai[-1][0]
    M = max(A)
    M2 = Ai[-2][1]
    for i, a in enumerate(A):
        if i == i1:
            print(M2)
        else:
            print(M)

main()

Submission status: Accepted

Solution code:
words = lambda t : list(map(t, input().split()))
n = int(input())
xs = []
fst = 0
snd = 0
for i in range(n):
    x = int(input())
    xs.append(x)
    if x > fst:
        t = fst
        fst = x
        x = t
    if x > snd:
        snd = x

for a in xs:
    if a == fst:
        print(snd)
    else:
        print(fst)

Submission status: Accepted

Solution code:
n = int(input())

a = []

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

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

Submission status: Accepted

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

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

sorted_a = sorted(A)
max_a = sorted_a[-1]
max_i = A.index(max_a)

second_a = sorted_a[-2]
second_i = A.index(second_a)

for i in range(N):
    if i == max_i:
        print(second_a)
    else:
        print(max_a)

Submission status: Accepted

Solution code:
N = int(input())
li = [int(input()) for i in range(N)]
lis = sorted(li)
k = lis[-1]
for i in range(N):
    if li[i] == k:
        print(lis[-2])
    else:
        print(k)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input())for _ in range(N)]
all_m = max(A)
maxs = A.count(all_m)
for ind,i in enumerate(A):
    if(all_m==i):
        if(maxs>=2):
            print(all_m)
        else:
            print(max(A[:ind]+A[ind+1:]))
    else:
        print(all_m)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
for i in range(n):
    a.append(int(input()))
    b.append(a[i])
b.sort()
m0=b[-1]
m1=b[-2]

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

Submission status: Accepted

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

m = max(a[0], a[1])
mm = min(a[0], a[1])
for i in range(2, n):
    if a[i] >= m:
        mm = m
        m = a[i]
    elif a[i] > mm:
        mm = a[i]

for i in range(n):
    if a[i] == m:
        print(mm)
    else:
        print(m)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = [int(input()) for _ in range(n)]
    max_a = max(a)
    if a.count(max_a) > 1:
        for i in range(n):
            print(max_a)
    else:
        index = a.index(max_a)
        max2_a = sorted(a, reverse=True)[1]
        for i in range(n):
            if index == i:
                print(max2_a)
            else:
                print(max_a)

Submission status: Accepted

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

A_np = np.asarray(A)
max = np.max(A_np)
idx = np.argmax(A_np)
A_temp = A_np
A_temp[idx] = 0

for i in range(n):
    if i == idx:
        print(np.max(A_temp))
    else:
        print(max)

Submission status: Accepted

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

Submission status: Accepted

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

B = sorted(A, reverse=True)
ma = B[0]

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
B = sorted(A, reverse=True)
Ap = B[0]
As = B[1]

for a in A:
    if a == Ap:
        print(As)
        continue
    print(Ap)

Submission status: Accepted

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

    m = 0
    s = 0

    for i in range(n):
        tmp = int(input())
        if tmp>=m:
            s = m
            m = tmp
        elif tmp>=s:
            s = tmp
            
        a.append(tmp)

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


main()

Submission status: Accepted

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

a_sort = sorted(a_list,reverse=True)

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

Submission status: Accepted

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

right = [0] * (N + 1)
left = [0] * (N + 1)
for i in range(1, N + 1):
    right[i] = max(right[i-1], A[i-1])
    left[N - i] = max(left[N + 1 -i], A[N - i])

# print (right)
# print (left)

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

Submission status: Accepted

Solution code:
n = int(input())
dat = []
dat2 = []
for i in range(n):
    a = int(input())
    dat.append(a)
    dat2.append(a)
dat.sort()
m = dat[n-1]
#print(m)
for i in range(n):
    #print("in: {0}".format(dat2[i]))
    if dat2[i] == m:
        print(dat[n-2])
    else:
        print(m)

Submission status: Accepted

Solution code:
import copy
N=int(input())
A=list(int(input()) for _ in range(N))
a=copy.deepcopy(A)
a.sort(reverse=True)
x=a[0]
y=a[1]

for i in range(N):
    if A[i]==x:
        print(y)
    else:
        print(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    A.append(int(input()))
    
est=max(A)
B=A[:]
A.remove(est)
er=max(A)
A=B

for i in range(n):
    if A[i] != est:
        print(est)
    else:
        print(er)

Submission status: Accepted

Solution code:
n = int(input())

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

max_arr = max(arr)
next_max = 0

cnt = 0
for i, a in enumerate(arr):
    if a == max_arr:
        cnt += 1
        idx = i
    else:
        next_max = max(next_max, a)

if cnt >= 2:
    ans = [max_arr] * n
else:
    ans = [max_arr] * idx + [next_max] + [max_arr] * (n - idx - 1)

print(*ans, sep="\n")

Submission status: Accepted

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

c=max(b)
d=b.index(c)
b.pop(d)
e=max(b)

for i in range(a):
  if i==d:
    print(e)
  else:
    print(c)

Submission status: Accepted

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

sorted_A = sorted(A, reverse=True)
A1 = sorted_A[0]
A2 = sorted_A[1]
for A_i in A:
    if A_i == A1:
        print(A2)
    else:
        print(A1)

Submission status: Accepted

Solution code:
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = [int(input()) for _ in range(n)]

    a_sorted = sorted(a_list)
    a_max = a_sorted[-1]
    a_second = a_sorted[-2]
    for a in a_list:
        if a == a_max:
            print(a_second)
        else:
            print(a_max)

Submission status: Accepted

Solution code:
import math
def myinput_int():
    return list(map(int, input().split()))

N, = myinput_int()
hairetu=[]
max=-1
max_pos=-1
next=-1
for i in range(N):
    temp, = myinput_int()

    if max<temp :
        max=temp
        max_pos=i
    elif next<temp :
        next=temp

for i in range(N):
    if i==max_pos:
        print(next)
    else:
        print(max)

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
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: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = []
for i in range(N):
    A.append(_I())

max_v = max(A)
max_v_count = A.count(max_v)
if max_v_count >= 2:
    # どれをとっても最大は最大
    for a in A:
        print(max_v)
else:
    for a in A:
        if a == max_v:
            second_max_v = [_ for _ in A]
            second_max_v.remove(max_v)
            second_max_v = max(second_max_v)
            print(second_max_v)
        else:
            print(max_v)

Submission status: Accepted

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

Amax = max(A)
if A.count(Amax) > 1:
    for i in range(N):
        print(Amax)

else:
    for i in A:
        if i != Amax:
            print(Amax)
        else:
            print(sorted(A)[-2])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

a = []
ans = []

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

a_sorted = sorted(a)
a_max1 = a_sorted[-1]
a_max2 = a_sorted[-2]
for a_value in a:
    if a_value != a_max1:
        ans.append(str(a_max1))
    else:
        ans.append(str(a_max2))

print("\n".join(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def argmax(a):
    m, n = -(1 << 31), -1
    for i, v in enumerate(a):
        if m < v:
            m, n = v, i
    return m, n


def solve(N: int, A: "List[int]"):
    m, mi = argmax(A)
    m2, mi2 = argmax(A[:mi]+A[mi+1:])
    for i in range(N):
        if i == mi:
            print(m2)
        else:
            print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

b = sorted(a, reverse=True)
max1 = b[0]
max2 = b[1]

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

Submission status: Accepted

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

A_max = max(A)
max_index = A.index(A_max)
A.pop(max_index)
A_second = max(A)
for i in range(N):
  if i == max_index:
    print(A_second)
  else:
    print(A_max)