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 = [int(input()) for _ in range(N)]

m1 = m2 = 0

for x in A:
    if x > m2:
        if x >= m1:
            m1, m2 = x, m1
        else:
            m2 = x

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

Submission status: Accepted

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

ans=sorted(A, reverse=True)[:2]
for n in A:
    if n == ans[0]:
        print(ans[1])
    else:
        print(ans[0])

Submission status: Accepted

Solution code:
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
B = sorted(A,reverse=True)
for a in A:
    if a < B[0]:
        print(B[0])    
    else:
        print(B[1])

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
adic={}
amod=[]
for i in range(n):
    aa=int(input())
    a[i]=aa
    if aa in adic:
        adic[aa]+=1
    else:
        adic[aa]=1
    if adic[aa]<3:
        amod.append(aa)    
amod=sorted(amod)
p=len(amod)
for i in range(n):
    m = p - 1
    while a[i] == amod[m] and adic[a[i]]==1 and m > 0:
        m -= 1
    print(amod[m])

Submission status: Accepted

Solution code:
n = int(input())
A = []
for i in range(n):
	A.append(int(input()))
	
B = A.copy()
B.remove(max(B))

A_max = max(A)
B_max = max(B)

for i in range(n):
	if A[i] == A_max:
		print(B_max)
	else:
		print(A_max)

Submission status: Accepted

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

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)

Submission status: Accepted

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

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

max_num, index = max(a), a.index(max(a))
a = sorted(a, reverse=True)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li = []
for i in range(n):
    x = int(input())
    li.append(x)
p = max(li)
r = li.index(p)
li.remove(p)
q = max(li)
for i in range(n):
    if i == r:
        print(q)
    else:
        print(p)

Submission status: Accepted

Solution code:
from copy import copy

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

DD = copy(D)
v1 = max(D)
m1 = D.index(v1)

del D[m1]
v2 = max(D)

[print(v2) if i == v1 else print(v1) for i in DD]

Submission status: Accepted

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

    set_A = set(A)
    max_A = max(A)
    count_A = A.count(max_A)
    for a in A:
        if a == max_A and count_A == 1:
            print(sorted(set_A)[-2])
        else:
            print(max_A)

main()

Submission status: Accepted

Solution code:
N=int(input())

max_index=-1
max_number=-1
second_number=-1
max_count=0
i=0
while(i<N):
    a=int(input())
    if(max_number<a):
        second_number=max_number
        
        max_number=a
        max_index=i
        max_count=0
    elif(max_number==a):
        max_count+=1
        max_index=-1
    elif(second_number<a):
        second_number=a
    i+=1

j=0
while(j<N):
    if(j==max_index and max_count==0):
        print(second_number)
    else:
        print(max_number)
    j+=1

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
sa = sorted(a)
maxi = sa.count(sa[-1])
ans = sa[-1]
max_index = a.index(sa[-1])
if maxi == 1:
    for i in range(n):
        if i == max_index:
            print(sa[-2])
        else:
            print(ans)
else:
    for i in range(n):
        print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
a = A.index(A_max)
A.sort(reverse=True)
for i in range(N):
    if i == a:
        print(A[1])
    else:
        print(A[0])

Submission status: Accepted

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

b = sorted(A)
maxi = b[-1]
for a in A:
    if a == maxi:
        print(b[-2])
    else:
        print(maxi)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
a = sorted(A.copy())
a1 = a[len(A)-1]
a2 = a[len(A)-2]

for i in A:
    if i == a1:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

Solution code:
n = int(input())

a = []
max_lst = [0,0]
for _ in range(n):
    d = int(input())
    a.append(d)

    if d > max_lst[1]:
        tmp = max_lst[1]
        max_lst[1] = d 
        max_lst[0] = tmp
    
    elif d > max_lst[0]:
        max_lst[0] = d
        
max_lst = sorted(max_lst, reverse=True)

for i in a:
    if i != max_lst[0]:
        print(max_lst[0])
    else:
        print(max_lst[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
B=sorted(A)
maximum=A.index(max(A))
for i in range(N):
    if i==maximum:
        print(B[-2])
    else:
        print(B[-1])

Submission status: Accepted

Solution code:
N,*A=list(map(int, open(0).read().split()))

m1 = 0
m1i = 0
m2 = 0
for i,a in enumerate(A):
    if a > m2:
        m2 = a
    if a > m1:
        m2 = m1
        m1 = a
        m1i = i

for n in range(N):
    if n == m1i:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
n = int(input())
l1 = []
for i in range(n):
    l1.append(int(input()))
l2 = sorted(l1, reverse=True)
m1 = l2[0]
m2 = l2[1]
for i in range(n):
    if (l1[i] == m1):
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

inf = float('inf')

L = list(accumulate(A, max))
R = list(accumulate(reversed(A), max))

L = [-inf] + L
R = [-inf] + R[:-1]

M = (max(l, r) for l, r in zip(L, reversed(R)))

for m in M:
    print(m)

Submission status: Accepted

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

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

max_value, max_cnt, sub_max = -1, 0, -1
for v in A:
	if v > max_value:
		sub_max = max_value
		max_value = v
		max_cnt = 1
	elif v == max_value:
		max_cnt += 1
	elif v > sub_max:
		sub_max = v

if max_cnt >= 2:
	print('\n'.join([str(max_value)] * N))
else:
	for v in A:
		print('%d' % (max_value if v != max_value else sub_max))

Submission status: Accepted

Solution code:
import sys

def solve(n, d):
    d_sorted = sorted(d, reverse=True)
    for i in range(n):
        print d_sorted[0] if d[i] != d_sorted[0] else d_sorted[1]


if __name__ == '__main__':

    n = int(sys.stdin.readline().strip())
    d = []
    for i in range(n):
        d.append(int(sys.stdin.readline().strip()))
    solve(n, d)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

n = int(input())
l = [0]*n
s = set()
f_max,s_max = 0,0
c = 0
for i in range(n):
    a = int(input())
    l[i] = a
    if f_max < a:
        s_max = f_max
        f_max = a
        c = 0
    elif s_max < a < f_max:
        s_max = a
    elif f_max == a:
        c+=1

#s.sort()

if len(s)==1:
    for i in range(n):
        print(l[0])

    exit()

if c==0:
    for i in range(n):
        if l[i]==f_max:
            print(s_max)
        else:
            print(f_max)
else:
    for i in range(n):
        print(f_max)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_v(n)

    max_asc = [0]
    for a in arr[:n - 1]:
        max_asc.append(max(max_asc[-1], a))
    #  print(max_asc)

    max_desc = [0]
    for a in arr[::-1][:n - 1]:
        max_desc.append(max(max_desc[-1], a))
    max_desc = max_desc[::-1]
    #  print(max_desc)

    #  assert len(max_asc) == len(max_desc)
    #  print(len(max_asc))

    for a, d in zip(max_asc, max_desc):
        print(max(a, d))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

for _ in range(N):
    A = int(input())
    A_LIST.append(A)

sorted_A_LIST = sorted(A_LIST)
largest = sorted_A_LIST[-1]
second_largest = sorted_A_LIST[-2]

for i in range(N):
    if A_LIST[i] < largest:
        print(largest)
    else:
        print(second_largest)

Submission status: Accepted

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


def main():
    n = int(input())

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

    a_sorted = sorted(a, reverse=True)
    a_max = max(a)

    for i in a:
        if i != a_max:
            print(a_max)
            continue

        index = a_sorted.index(i)
        if index == 0:
            print(a_sorted[index + 1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

most_max = max(value_list)

if len([i for i, x in enumerate(value_list) if x == most_max]) == 2:
    for i in range(n):
        print(most_max)
else:
    most_max_index = value_list.index(most_max)
    value_list[most_max_index] = 0
    second_max = max(value_list) 
    value_list[most_max_index] = most_max
    
    for i in range(n):
        if value_list[i] == most_max:
            print(second_max)
        else:
            print(most_max)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
max_a = max(A)
max_count = A.count(max_a)
if max_count == 1:
    ind = A.index(max_a)
    max_b = max(A[:ind]+A[ind+1:])

for i in range(N):
    if max_count > 1:
        print(max_a)
    else:
        if A[i] == max_a:
            print(max_b)
        else:
            print(max_a)

Submission status: Accepted

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

imax = max(a)
b = sorted(a)
#print(imax)
for i in range(n):
    if not a[i] == imax:
        print(imax)
    else:
        print(b[n-2])

Submission status: Accepted

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


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_keys = list(A_hash.keys())
A_keys.sort()

if len(A_keys) > 1:
        A_second_max = A_keys[-2]
else:
        A_second_max = A_keys[-1]



for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
    
b = sorted(a,reverse=True)
maxa = b[0]
submaxa = b[1]
maxid = np.argmax(a)
for i in range(n):
    if i == maxid:
        print(submaxa)
    else:
        print(maxa)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    leftmax = [-1] * N
    rightmax = [-1] * N
    for i in range(1, N):
        leftmax[i] = max(leftmax[i-1], A[i-1])
        rightmax[N-i-1] = max(rightmax[N-i], A[N-i])
    #print(leftmax)
    #print(rightmax)
    ans = ""
    for i in range(N):
        ans += str(max(leftmax[i], rightmax[i])) + " "
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

m = 0
m_index = -1
for i in range(N):
    if A[i] > m : 
        m = A[i]
        m_index = i

mm = 0
mm_index = -1
for i in range(N):
    if i != m_index:
        if A[i] > mm : 
            mm = A[i]
            mm_index = i          

for i in range(N):
    if i == m_index : 
        print(mm)
    else :
        print(m)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
nums = np.array([int(input()) for _ in range(N)])

# 最も大きな値を調べる
sorted_nums = sorted(nums, reverse=True)
max_num = sorted_nums[0]
# 2番目に大きな値を調べる
second_max_num = sorted_nums[1]

for i in range(N):
    # 除外する値を取得する
    exclude_num = nums[i]
    # 除外する値が最大値なら2番目の値を表示する
    if exclude_num == max_num:
        print(second_max_num)
    # それ以外なら最大値を表示する
    else:
        print(max_num)

Submission status: Accepted

Solution code:
import copy

n = int(input())
arr = [int(input()) for i in range(n)]
brr = sorted(arr, reverse=True)
ind = arr.index(max(arr))
# for i in range(n):
#     brr = copy.copy(arr)
#     brr.pop(i)
#     print(max(brr))
for i in range(n):
    if i == ind:
        print(brr[1])
    else:
        print(brr[0])

Submission status: Accepted

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

maxleft = [0] * (N+2)
maxright = [0] * (N+2)

for i in range(N):
    maxleft[i+1] = max(maxleft[i],A[i])
    maxright[N-i] = max(maxright[N-i+1],A[N-i-1])

for i in range(N):
    print(max(maxleft[i], maxright[2+i]))

Submission status: Accepted

Solution code:
n = int(input())

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

temp = sorted(arr)
max_element = temp[-1]
second_max = temp[-2]

for i in arr:
	if i != max_element:
		print(max_element)
	else:
		print(second_max)

Submission status: Accepted

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

max1=max(A)
if A.count(max(A))>1:
    for i in range(N):
        print(max1)
else:
    max2=sorted(A)[-2]
    for a in A:
        if a==max1:
            print(max2)
        else:
            print(max1)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(list(set(a[:])),reverse=True)
maxa=aa[0]
f=False if a.count(maxa) != 1 else True
for i in range(n):
    if a[i] == maxa and f:
        print(aa[1] if len(aa) != 1 else maxa)
    else:
        print(maxa)

Submission status: Accepted

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

"""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]
    if m == m2:
        [print(m) for _ in r(n)]
    else:
        [print(m2) if a[i] == m else print(m) for i in r(n)]


main()

Submission status: Accepted

Solution code:
n = int(input())

arr = []
max_num = 0
label = 1
for i in range(n):
    inp = int(input())
    if inp >= max_num:
       max_num = inp
       label = i
    arr.append(inp)



arr_sub = arr[:]
arr_sub.pop(label)
second_max = max(arr_sub)


for i in range(n):
    if i != label:
        print(max_num)
    else:
        print(second_max)

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = []
count = [0 for _ in range(200001)]
for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(200000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))

Submission status: Accepted

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
a = [0]
ma = 0
for i,j in enumerate(l):
    if j > ma:
        ma = j
    a.append(ma)
a.append(0)
b = [0]
ma = 0
for i,j in enumerate(reversed(l)):
    if j > ma:
        ma = j
    b.append(ma)
b.append(0)
#print(a,b)
for i in range(n):
    print(max(a[i],b[-i-3]))

Submission status: Accepted

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

Submission status: Accepted

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

s = sorted(A, reverse=True)
for a in A:
    if a == s[0] and a != s[1]:
        print(s[1])
    else:
        print(s[0])

Submission status: Accepted

Solution code:
N = int(input())
A, A_sorted = [], []
for i in range(N):
    x = int(input())
    A.append(x)
    A_sorted.append(x)
A_sorted.sort()
vmax, vmax2 = A_sorted[-1], A_sorted[-2]

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

Submission status: Accepted

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

n = int(input())
a = [int(input()) for _ in range(n)]
ans=max(a)
if a.count(ans)>1:
    for _ in range(n):
        print(ans)
else:
    for i in range(n):
        print(ans if a[i]!=ans else sorted(a)[-2])

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
n = INT()

ans = 0
# a = [INT() for i in range(n)]
a = []
for i in range(n):
    a.append(INT())
l = []
# print(a)

b = sorted(a, reverse=True)
# print(a)
m1 = b[0]
m2 = b[1]
for i in range(n):
    if a[i] != m1:
        print(m1)
    else:
        print(m2)
     




# # for i in range(n):
#     l = []
#     for j in range(n):
#         if i != j:
#             l.append(a[j])
#     print(max(l))
#         # print(l)
#         # print(max(l))

#     # print(a[0:i], a[i:n])
#     # print(ans)
#

Submission status: Accepted

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

max_A = max(A)
max_A_counter = 0
sec_A = max_A
for a in sorted(A, reverse=True):
    if a==max_A:
        max_A_counter+=1
    if a!=max_A:
        sec_A=a
        break

for i in range(N):
    if A[i]==max_A:
        print(max_A if 2<=max_A_counter else sec_A)
    else:
        print(max_A)

Submission status: Accepted

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

maxNum = max(A)
index = -1
for i in range(N):
    if A[i] == maxNum:
        index = i

for i in range(N):
    if i != index:
        print(maxNum)
        continue
    else:
        A.remove(maxNum)
        print(max(A))

Submission status: Accepted

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

A_max = max(A)
A_copy = A.copy()
A_copy.remove(A_max)
A_max_second = max(A_copy)

for a in A:
    if a != A_max:
        print(A_max)
    else:
        print(A_max_second)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
N=int(N)
A=[]
for i in range(N):
    b=input()
    b=int(b)
    A.append(b)
flag=0
max_value=max(A)
for i in range(N):
    if flag==1:
        print(max_value)
    elif A[i]<max_value:
        print(max_value)
    else:
        data=A.pop(i)
        print(max(A))
        A.insert(i,data)
        if max(A)==max_value:
            flag=1

Submission status: Accepted

Solution code:
N = int(input())

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

"順方向の最大値、逆方向の最大値"

left_max = [A[0]]
right_max = [A[-1]]

for i in range(1, N):
    left_max.append(max(left_max[-1], A[i]))


for i in range(N-2, -1, -1):
    right_max.append((max(right_max[-1], A[i])))

# print(left_max)
right_max.reverse()
# print(right_max)

print(right_max[1])  # 最初の項A1を除いた最大値
for i in range(1, N-1):
    print(max(left_max[i-1], right_max[i+1]))
print(left_max[-2])

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
li = [int(input()) for _ in range(n)]
m = max(li)
ind = li.index(m)
li.sort()
mm= li[n-2]
for i in range(n):
  if i == ind:
    print(mm)
  else:
    print(m)

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.readline

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

A=sorted(a)


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

Submission status: Accepted

Solution code:
import copy

N = int(input())

A = [int(input()) for _ in range(N)]
B = sorted(A)
max_1 = B[-1]
max_2 = B[-2]

for i in range(N):
    if(A[i]==max_1):
        print(max_2)
    else:
        print(max_1)

Submission status: Accepted

Solution code:
N = int(input())
A = []
for i in range(N):
        A.append(int(input()))
m = max(A)
n = A.index(m)
A.remove(m)
m1 = max(A)
for i in range(n):
        print(m)
print(m1)
for i in range(N-1-n):
        print(m)

Submission status: Accepted

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

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

li2 = sorted(li,reverse=True)
ans = max(li)

for i in range(N):
    if(ans == li[i]):
        print(li2[1])
    else:
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]
na = np.array(a)
maxI = np.argmax(na)
maxA = na[maxI]
nb = np.copy(na)
nb[maxI] = 0
maxA2 = np.max(nb)
for i in range(n):
    if i != maxI:
        print(na[maxI])
    else:
       print(maxA2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

a_max = max(a)
a_max_count = a.count(a_max)

if a_max_count > 1:
  for i in range(n):
    print(a_max)
    
else:
  print(max(a[1:]))
  
  for i in range(1, n-1):
    if a[i] == a_max:
      print(max(max(a[:i]), max(a[i+1:])))
      
    else:
      print(a_max)

  print(max(a[:-1]))

Submission status: Accepted

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

# 入力された数列を降順でソート
sortA = sorted(A, reverse=True)

if sortA[0] == sortA[1]:
    # 最大値が2個発生するならば、そのときはすべての行で最大値が表示される
    for i in range(N):
        print(sortA[0])
else:
    # 最大値が1個しかない場合、最大値の存在する位置では最大から2番めの値が表示されるが、それ以外では最大値が表示される
    maxP = A.index(sortA[0])
    for i in range(maxP):
        print(sortA[0])
    print(sortA[1])
    for i in range(maxP+1, N):
        print(sortA[0])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

max_value = max(a)
max_value_index = a.index(max(a))

a.pop(max_value_index)
second_max_value = max(a)
a.insert(max_value_index,max_value)

#print("======")
#print(max_value)
#print(max_value_index)
#print(second_max_value)
#print("======")

for i in a:
    if i != max_value:
        print(max_value)
    else:
        print(second_max_value)

Submission status: Accepted

Solution code:

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

srtd = sorted(A)
for i in range(N):
    # print(str(i) + '番目')
    if srtd[-1] != A[i]:
        print(srtd[-1])
    else:
        print(srtd[-2])

Submission status: Accepted

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


a_max = max(a_s)
i_max_arg = a_s.index(a_max)
del a_s[i_max_arg]

#2番目に大きい値
a_max2 = max(a_s)    

for i in range(n):
  if i != i_max_arg:
    ans = a_max
  else:
    ans = a_max2
  print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(range(0))

top1Num = 0
top2Num = 0
topCount = 0

# countが必要

for i in range(N):
    A = int(input())
    A_list.append(A)
    if A > top1Num:
        top2Num = top1Num
        top1Num = A
    elif A > top2Num:
        top2Num = A

# print(A_list)
# print(top1Num)
# print(top2Num)

topCount = A_list.count(top1Num)
# print(topCount)

# print("--------------------")

for i in range(N):
    if A_list[i] == top1Num:
        print(top2Num)
    else:
        print(top1Num)

Submission status: Accepted

Solution code:
import copy

N = int(input())

x_list = []
for i in range(N):
    x = int(input())
    x_list.append(x)

max_value = max(x_list)

get_index = x_list.index(max(x_list))

tmp_list = copy.deepcopy(x_list)
tmp_list.pop(get_index)
without_max_value = max(tmp_list)

for i in range(len(x_list)):
    if i != get_index:
        print(max_value)
    else:
        print(without_max_value)