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:
from collections import defaultdict
N = int(input())
A = []
a_dict = defaultdict(int)
for _ in range(N):
    a = int(input())
    A.append(a)
    a_dict[a] += 1

max_a = max(A)
for i, a in enumerate(A):
    if a == max_a and a_dict[a] == 1:
        B = []
        for j, b in enumerate(A):
            if b != a:
                B.append(b)
        ans = max(B)
        print(ans)
    else:
        print(max_a)

Submission status: Accepted

Solution code:
n = int(input())
s = []
second = 0
max_k = 0
for _ in range(n):
    k = int(input())
    max_k, min_k = max(k, max_k), min(k, max_k)
    second = max(min_k, second)
    s.append(k)
kk = s.index(max_k)
for i in range(n):
    if i != kk:
        print(max_k)
    else:
        print(second)

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = a[:]
b.sort()
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 = [0 for i in range(N)]
for i in range(N):
    A[i] = int(input())
B = sorted(A)
maxA = B[-1]
smaxA = B[-2]
for i in range(N):
    if A[i] == maxA:
        print(smaxA)
    else:
        print(maxA)

Submission status: Accepted

Solution code:
N = int(input())
max = 0
max2 = 0
n_max = 0
A = []
for _ in range(N):
  a = int(input())
  A.append(a)
  if a > max:
    max2 = max
    max = a
    n_max = 1
  elif a == max:
    n_max += 1
  elif a > max2:
    max2 = a

for a in A:
  if a == max:
    if n_max == 1:
      print(max2)
    else:
      print(max)
  else:
    print(max)

Submission status: Accepted

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

b = [0]*n
c = [0]*n
b[0] = a[0]
c[n-1] = a[n-1]
for i in range(1,n):
    b[i]=max(b[i-1],a[i])
    c[n-1-i]=max(c[n-i],a[n-1-i])

for i in range(n):
    if i==0:
        print(c[1])
    elif i==n-1:
        print(b[n-2])
    else:
        print(max(b[i-1],c[i+1]))

Submission status: Accepted

Solution code:
N  = int(input())
A_list = []
primary_max = 0
secondary_max = 0

for i in range(N) :
    n = int(input())
    if (primary_max <= n) :
        if (primary_max == secondary_max) :
            primary_max = n
        else :
            secondary_max = primary_max
            primary_max = n
    elif (secondary_max < n and n < primary_max) :
        secondary_max = n

    A_list.append(n)

for a in A_list :
    if (a == primary_max) :
        print(secondary_max)
    else :
        print(primary_max)

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())

values = [0]*N
max_value_count = 0
max_value = 0
next_max_value = max_value

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

    if in_value == max_value:
        max_value_count = max_value_count + 1
    elif in_value > max_value:
        next_max_value = max_value
        max_value = in_value
        max_value_count = 1
    elif in_value > next_max_value:
        next_max_value = in_value

for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)

Submission status: Accepted

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

N = int(input())

values = [0]*N
value_count_map = {}
max_value = 0
next_max_value = max_value

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

    if in_value > max_value:
        next_max_value = max_value
        max_value = in_value
    elif in_value > next_max_value:
        next_max_value = in_value

max_value_count = value_count_map[max_value]

for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())

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

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

for row in range(N):
    if values[row] == max_value and max_value_count == 1:
        print(next_max_value)
    else:
        print(max_value)

Submission status: Accepted

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

num = a.index(max(a))
a_max = max(a)
a_second = sorted(a)[-2]
for i in range(n):
    if i == num:
        print(a_second)
    else:
        print(a_max)

Submission status: Accepted

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

N = int(input())

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

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

Submission status: Accepted

Solution code:
import copy
n=int(input())
list=[int(input()) for i in range(n)]
temp_list = copy.copy(list)
temp_list.sort(reverse=True)

max = 0
for c in list:
    if(c == temp_list[0]):
        print(temp_list[1])
    else:
        print(temp_list[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
num = a.index(max(a))
a_max = max(a)
a_second = sorted(a)[-2]
for i in range(n):
    if i == num:
        print(a_second)
    else:
        print(a_max)

Submission status: Accepted

Solution code:
from collections import Counter

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

A_cp = A[:]
A_max1 = max(A_cp)
A_cp.remove(A_max1)
A_max2 = max(A_cp)

for i in A:
    print(A_max1 if i!=A_max1 else A_max2)

Submission status: Accepted

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

left = [0]
right = [0]

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


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

# print(len(left))
# print(len(right))

right.reverse()

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

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

for i in A:
    if (A_s[0] == i) & (A_s[1] == i):
        print(A_s[0])
    elif (A_s[0] == i) & (A_s[0] != A_s[1]):
        print(A_s[1])
    else:
        print(A_s[0])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(input()) for i in range(n)]
b=a[:]
a.sort()
for i in range(n):
    if b[i]<a[-1]:
        print(a[-1])
    elif b[i]==a[-1]:
        print(a[-2])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
firstMax = max(a)
minVal = min(a)
secondMax = max(map(lambda x:x if x != firstMax else minVal, a)) if len(str(a).split(str(firstMax))) == 2 else firstMax
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
A = [read_int()[0] for _ in range(N)]

def solve() -> str:

    M = max(A)

    semi_M = 0
    num_of_M = 0
    for i in range(N):
        if A[i] == M:
            num_of_M += 1
        else:
            semi_M = max(semi_M, A[i])

    for i in range(N):
        if A[i] == M and num_of_M == 1:
            print(semi_M)
        else:
            print(M)
    return

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input())
a = []
#print('n a',n,a)
for i in range(n):
        a.append(int(input()))
#print('As',a)
max1 = max(a)
location1 = a.index(max1)
#print('1st MAX',max1,'INDEX',location1)
a.remove(a[location1])
max2 = max(a)
#print('2nd MAX',max2)
if max1 == max2:
        #print('1=2')
        for i in range(n):
                print(max1)
else:
        #print('1!=2')
        for i in range(n):
                if i == location1:
                        #print('max2')
                        print(max2)
                else:
                        #print('max1')
                        print(max1)

Submission status: Accepted

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

max1 = list1.index(max(list1))
max2 = max(list1)
list2 = list1[:max1]+list1[max1+1:]
max3 = max(list2)

for i in range(N):
  if i != max1:
    print(max2)
  else:
    print(max3)

Submission status: Accepted

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

Amax = sorted(A,reverse=True)[0]
Anmax = sorted(A,reverse=True)[1]
for i in A:
  if i == Amax:
    print(Anmax)
  else:
    print(Amax)

Submission status: Accepted

Solution code:
n = int(input())
a_max = 0
data = [int(input()) for i in range(n)]
a_max = max(data)
flag = True if 2 <= data.count(a_max) else False
for i in range(n):
  if data[i] == a_max and not flag:
    tmp = data.pop(i)
    print(max(data))
    data.insert(tmp,0)
    
  else:
  	print(a_max)

Submission status: Accepted

Solution code:
N = int(input())
l = [int(input()) for i in range(N)]
l_ = sorted(l)
for Ai in l:
  if l_[-1] == Ai:
    print(l_[-2])
  else:
    print(l_[-1])

Submission status: Accepted

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

sbmx, mx = sorted(a)[n-2:]
for m in a:
        if m==mx: print(sbmx)
        else: print(mx)

Submission status: Accepted

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

L = [0] * (N+1)
R = [0] * (N+2)

for i in range(1, N+1):
    L[i] = max(L[i-1], A[i-1])
    R[N-i+1] = max(R[N-i+2], A[N-i+2])

for i in range(1, N+1):
    print(max(L[i], R[i]))

Submission status: Accepted

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

B = A.copy()
B.sort(key=lambda x:-x)

last = B[0]
second = B[1]

for num in A:
  if num != last:
    print(last)
  else:
    print(second)

Submission status: Accepted

Solution code:
n = int(input())
list = [int(input()) for i in range(n)]
list2 = sorted(list)
m1 = list2[-1]
m2 = list2[-2]
 
for i in list:
    if i == m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

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

A_max = max(A)
A_second = A_max

if A.count(A_max) == 1:
  AA = []
  for a in A:
    if a != A_max:
      AA.append(a)
  A_second = max(AA)

for i in range(len(A)):
  if A[i] == A_max:
    print(A_second)
  else:
    print(A_max)

Submission status: Accepted

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

Submission status: Accepted

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

B = sorted(A, reverse=True)
  
max_ = B[0]
max__ = B[1]

for i in range(N):
  if A[i] == max_:
    print(max__)
  else:
    print(max_)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lis = [int(input()) for _ in range(n)]
lis2 = sorted(lis)
m1 = lis2[-1]
m2 = lis2[-2]

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
l=[]
for i in range(n):
    p=int(input())
    a.append(p)
    l.append(p)
a.sort()
a=a[::-1]
if a[0]==a[1]:
    for i in range(n):
        print(a[0])
else:
    for i in range(n):
        if l[i]==a[0]:
            print(a[1])
        else:
            print(a[0])

Submission status: Accepted

Solution code:
N = int(input())
Alist = [int(input()) for _ in range(N)]
Alist_sorted = sorted(Alist)

m = max(Alist)
for i in range(N):
    if Alist[i]==m:
        print(Alist_sorted[-2])
    else:
        print(m)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    ml = A.copy()
    ml.sort(reverse=True)

    Am = ml[0]
    As = ml[1]

    for i in range(N):
        if(A[i] == Am):
            print(As)
        else:
            print(Am)
    

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())
L = [ int(input()) for _ in range(N)]
L2 = sorted(enumerate(L),key=lambda i:i[1])
for i in range(N):
  if i == L2[-1][0]:
    print(L2[-2][1])
  else:
    print(L2[-1][1])

Submission status: Accepted

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

for val in a:
    if val == sorted_a[0]:
        print(sorted_a[1])
    else:
        print(sorted_a[0])

Submission status: Accepted

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

b = a.copy()
b.sort()
for number in a:
    if b[-1] != number:
        print(b[-1])
    else:
        print(b[-2])

Submission status: Accepted

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

Submission status: Accepted

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

a_sort = sorted(a, reverse=True)

for ele in a:
    if ele==a_sort[0]:
        print(a_sort[1])
    else:
        print(a_sort[0])

Submission status: Accepted

Solution code:
num = int(input())
a_list = []
for i in range(num):
    a_list.append(int(input()))
M = max(a_list)
M_num = a_list.index(M)
a_list.pop(M_num)
for i in range(num):
    if i != M_num:
        print(M)
    else:
        print(max(a_list))

Submission status: Accepted

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

Submission status: Accepted

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

max = max(tmp)

unk = sorted(tmp, reverse=True)
unk2 = unk[1]

counter = 0
for i in tmp:
    if i == max:
        counter += 1

if counter > 1:
    for i in range(n):
        print(max)
else:
    for i in tmp:
        if i == max:
            print(unk2)
        else:
            print(max)

Submission status: Accepted

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

Submission status: Accepted

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

A=[]
_max = 0
_max2 = 0
N=int(input())
for i in range(N):
    a=int(input())
    A.append(a)
    if _max<a:
        _max2=_max
        _max=a
    elif _max2<a:
        _max2=a

for a in A:
    print(_max if _max!=a else _max2)

Submission status: Accepted

Solution code:
A=[]
_max = 0
_max2 = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
    if _max<A[-1]:
        _max2,_max=_max,A[i]
    elif _max2<A[-1]:
        _max2=A[i]
    #_,_max2,_max=sorted([A[-1],_max2,_max])

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

Submission status: Accepted

Solution code:
N = int(input())

maxA1 = 0
maxi = 0
maxA2 = 0
for i in range(N):
    a = int(input())
    if maxA1<a:
        maxA2 = maxA1
        maxA1 = a
        maxi = i
    elif maxA2<a:
        maxA2 = a

for i in range(N):
    if i == maxi:
        print(maxA2)
    else:
        print(maxA1)

Submission status: Accepted

Solution code:
A=[]
_max = 0
_max2 = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
    _,_max2,_max=sorted([A[-1],_max2,_max])

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

Submission status: Accepted

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

A=[]
B = []
max = 0
max2 = 0
count = 0
N=int(input())
for i in range(N):
    A.append(int(input()))
for i in range(len(A)):
    if A[i] > max:
        max = A[i]
        B.append(A[i])
for i in range(len(A)):
    if A[i] == max:
        count +=1

    
for i in range(len(A)):
    if count >= 2:
        print(max)
    if count == 1:
        if A[i] > max2 and A[i] != max:
            max2 = A[i]
for i in range(len(A)):
    if count ==1:
        if A[i] == max:
            print(max2)
        else:
            print(max)

Submission status: Accepted

Solution code:
#input 
n = int(input())

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

max_value = max(numbers)

count_max = numbers.count(max_value)
index_max = numbers.index(max_value)

numbers_second = numbers
del numbers_second[index_max]
second_max_value = max(numbers_second)

if count_max >= 2:
    for i in range(n):
        print(max_value)

else:
    for i in range(n):
        if i == index_max:
            print(second_max_value)
        else:
            print(max_value)

Submission status: Accepted

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

sorted_a = sorted(a)
first_a = sorted_a[-1]
second_a = sorted_a[-2]

for i in range(len(a)):
    if a[i] == first_a:
        print(second_a)
    else:
        print(first_a)

Submission status: Accepted

Solution code:
n = int(input())
s = [int(input()) for _ in range(n)]
max1 = max(s)
max2 = sorted(s)[-2]
max1_index = s.index(max1)
for i in range(n):
  if(max1_index == i):
    print(max2)
  else:
    print(max1)

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
m=max(l)
a=l.index(m)
for i in range(n):
  if i==a:
    l[i]=0
    print(max(l)) 
  else:print(m)

Submission status: Accepted

Solution code:
N = int(input())

A = [int(input()) for _ in range(N)]
A_sort = sorted(A, reverse=True)

A_max = A_sort[0]
A_max_ = A_sort[1]

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

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()
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())
As = [int(input()) for _ in range(N)]
As2 = sorted(As)
m1 = As2[-1]
m2 = As2[-2]
for a in As:
    if a == m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

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

Submission status: Accepted

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

for a in A:
    if a == sa[0]:
        print(sa[1])
    else:
        print(sa[0])

Submission status: Accepted

Solution code:
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

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

max = 0

index_max = np.argmax(A)
A_temp = np.copy(A)
A_temp[index_max] = 0
index_max_second = np.argmax(A_temp)

result = np.full(N, A[index_max])
result[index_max] = A[index_max_second]

for i in range(0, N, 1):
    print(int(result[i]))

Submission status: Accepted

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

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

Submission status: Accepted

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

A.sort()
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans1 = A[-1]
if d[ans1] >= 2:
    ans2 = A[-1]
else:
    ans2 = A[-2]

for b in B:
    if b == ans1:
        print(ans2)
    else:
        print(ans1)

Submission status: Accepted

Solution code:
import copy
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for i in range(N)]
copy_A = copy.copy(A)
copy_A.sort(reverse=True)
max_a, sec_a = copy_A[0], copy_A[1]
for i in range(N):
  if A[i] == max_a:
    print(sec_a)
  else:
    print(max_a)

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
# print(l)
x=[]
for i in range(n):
    x.append(l[i])
x.sort()
for i in range(n):
    if(l[i]!=x[n-1]):
     
        print(x[n-1])
    else:

        print(x[n-2])

Submission status: Accepted

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

a_sort=sorted(a,reverse=True)

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

Submission status: Accepted

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

L = [1]
for n in range(N-1):
    L.append(max(L[-1], A[n]))

R = [1]
A.reverse()
for n in range(N-1):
    R.append(max(R[-1], A[n]))
R.reverse()

for i in range(N):
    print(max(L[i], R[i]))

Submission status: Accepted

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

Submission status: Accepted

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

    sorted_A = sorted(A)

    max_A = sorted_A[-1::][0]
    next_max_A = sorted_A[-2:-1:][0]

    for i in range(N):
        if A[i] == max_A:
            print(next_max_A)
        else:
            print(max_A)

Submission status: Accepted

Solution code:
N = int(input()) #1行目のNを取得する
s = []
s = [int(input()) for i in range(N)] #複数行の数値の入力を取得

max_num = max(s)
max_ind = s.index(max_num)
s.remove(max_num)
max2_num = max(s)
 
for i in range(N):
    if i == max_ind:
        print(max2_num)
    else:
        print(max_num)

Submission status: Accepted

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

for i in li:
    if i >= maximam:
        second_maximam = maximam
        maximam = i
    elif i >= second_maximam:
        second_maximam = i

for i in li:
    if i == maximam:
        print(second_maximam)
    else:
        print(maximam)

Submission status: Accepted

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

Submission status: Accepted

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

comp = data.copy()
data.sort()


for _ in comp:
    if _ == data[-1]:
        print(data[-2])
    else:
        print(data[-1])

Submission status: Accepted

Solution code:
N=int(input())
lis=[]
for i in range(N):  
  lis.append(int(input()))
lis2=sorted(lis)
ma1=lis2[-1]
ma2=lis2[-2]

for i in range(N):
  if lis[i] == ma1:
    print(ma2)
  else:
    print(ma1)

Submission status: Accepted

Solution code:
num = int(input())
hako = [int(input()) for _ in range(num)]
hako_mirror = hako.copy()
hako_mirror.sort(reverse=True)
for h in hako:
  if h == hako_mirror[0]:
    print(hako_mirror[1])
  else:
    print(hako_mirror[0])

Submission status: Accepted

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

Submission status: Accepted

Solution code:
n = int(input())
numlist = []
for i in range(n):
    numlist.append(int(input()))
argmax = numlist.index(max(numlist))
maxnum = max(numlist)
del numlist[argmax]
secondnum = max(numlist)
                       
for i in range(argmax):
    print (maxnum)
print (secondnum)
for i in range(argmax+1,n):
    print (maxnum)

Submission status: Accepted

Solution code:
N=int(input())
maxi=0
maxinum=0
submaxi=0
for n in range(N):
    tmp=int(input())
    if tmp>maxi:
        submaxi=maxi
        maxi=tmp
        maxinum=n
    elif tmp>submaxi:
        submaxi=tmp
for n in range(N):
    if n==maxinum:
        print(submaxi)
    else:
        print(maxi)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
ind=a.index(m)
m2=-1e10
for i in range(n):
    if i!=ind:
        m2=max(m2,a[i])
for i in range(n):
    if i==ind:
        print(m2)
    else:
        print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
max1=0
max2=0

for i in range(n):
    a[i] = int(input())
    if max1 < a[i]:
        max1 = a[i]
    elif max2 < a[i]:
        max2 = a[i]
for i in range(n):
    if max1 == a[i]:
        print(max2)
    else:
        print(max1)

Submission status: Accepted

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

import itertools as ite
import math
import random
import sys
import codecs
from collections import defaultdict

INF = 10 ** 18
MOD = 10 ** 9 + 7

sys.setrecursionlimit(1000000)

N = input()
A = [input() for i in range(N)]
maxA = max(A)
if A.count(maxA) > 1:
    for i in range(N):
        print maxA
else:
    for i in range(N):
        if A[i] == maxA:
            print max(A[:i] + A[i + 1:])
        else:
            print maxA

Submission status: Accepted

Solution code:
import numpy as np

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

_a = np.array(a)
max_index = np.argmax(_a)
max_val_1 = np.max(_a)
_a[max_index] = 0
max_val_2 = np.max(_a)

for i in range(n):

    if max_val_1 == max_val_2:
        print(max_val_1)
        
    elif max_val_1 != max_val_2 and a[i] == max_val_1:
        print(max_val_2)
    
    else:
        print(max_val_1)

Submission status: Accepted

Solution code:
# 整数(数列長)の入力
N = int(input())
# 数列の入力
A = [int(input()) for _ in range(N)]
# 数列の最も大きい値取得
A_max = sorted(A)[-1]
# 数列の二番目に大きい値取得
A_2ndmax = sorted(A)[-2]

# 出力
for i in range(N):
    
    if A[i] == A_max:
        print("{}".format(A_2ndmax))
    
    else:
        print("{}".format(A_max))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

#入力ループ
list = []
for i in range(n):
    list.append(int(input()))

#入力リストを降順にソート
new_list = sorted(list,reverse=True)

#出力ループ
for c in range(n):
    if new_list[0] == list[c]:
        print(new_list[1])
    else:
        print(new_list[0])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
for x in a:
    print(b[(x < b[-1]) - 2])

Submission status: Accepted

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

max_val = max(a)
max_total = a.count(max_val) - 1

for i in range(n):
    if max_val > a[i]:
        print(max_val)

    elif max_val == a[i] and max_total != 0:
        print(max_val)
        max_total -= 1
    else:
        temp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = temp

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
A_Index = sorted(range(len(A)), key = lambda k: A[k])
A = sorted(A)

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