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: Runtime Error

Solution code:
N = int(input())
a = [0]*N
for i in range(N):
    a[i] = int(input())
m = max(a)
a.remove(m)
n = max(a)


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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for i in range(N)]
maxA = max(A)
secA = sorted(set(A))[-2]
num=A.count(maxA)
#print(N,A,maxA,secA,num)

for i in range(N):
  if num>1:
    print(maxA)
  elif A[i]==maxA:
    print(secA)
  else:
    print(maxA)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
c=max(a)
check=False
for i in range(n):
    if a[i]==c&&check==False:
        b=a[:i]+a[i+1:]
        d=max(b)
        print(d)
    elif a[i]==c&&check==True:
        print(d)
    else:
        print(c)

Submission status: Runtime Error

Solution code:
from sys import stdin

readline = stdin.readline


def ns():
    """
    入力を`[\\s]`を除いて文字列として取得
    """
    return readline().rstrip()


def ni():
    """
    入力を`int`に変換
    """
    return int(ns())


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n = ni()
    a = list(nf())
    for i in range(n):
        tmp = a[:]
        tmp.pop(i)
        print(max(tmp))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
for i range(N):
  cop = arr.copy()
  del cop[i]
  print(max(cop))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]
na = np.array(a)
for i in range(n):
    print(np.max(a[:i] + a[i+1:]))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())

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


max_a = np.max(A)
max_i = np.argmax(A)

for i in range(N):
   if(i == max_i):
      max_n0 = np.max(A[0:i-1])
      max_n1 = np.max(A[i+1,N-1])
      if(max_n0 > max_n1):
         print(max_n0)
      else:
         print(max_n1)
   else:
      print(max_a)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(a[:])
for i in range(n):
  k=a[i]
  t=-1
  while True:
    if aa[t] != k:
      print(aa[t])
      break
    else: t -= 1

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
amax = max(a)
amax_id = a.index(amax)
amax2 = max(a.pop(amax_id))
for i in range(n):
  if i == amax_id:
    print(amax2)
  else:
    print(amax)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]
na = np.array
for i in range(n):
    print(np.max(a[:i] + a[i+1:]))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())

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


max_a = np.max(A)
max_i = np.argmax(A)

for i in range(N):

   if(i == max_i):
      max_n0 = np.max(A[0:i-1)
      max_n1 = np.max(A[i+1,N-1)
      if(max_n0 > max_n1):
         print(max_n0)
      else:
         print(max_n1)
   else:
      print(max_a)

Submission status: Runtime Error

Solution code:


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

tmp_a = sorted(list(set(a)), reverse=True)

for each in a:
  if each == tmp_a[0]:
    print(tmp_a[1])
  else:
    print(tmp_a[0])

Submission status: Runtime Error

Solution code:
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
for i range(N):
  cop = arr.copy()
  del cop[i]
  cop.sort()
  print(cop[-1])

Submission status: Runtime Error

Solution code:
N = int(input())
a = [0]*N
for i in range(N):
    a[i] = int(input())
b = set(a)
m = max(b)
b.remove(m)
n = max(b)
for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Submission status: Runtime Error

Solution code:
import numpy as np
l = list(map(int, input().split()))
n = l[0]
A = np.array(l[1:])
for i in range(n):
  m = np.max(A)
  if A[i] == m:
    mask = A != A[i]
    print(np.max(A[mask]))
  else:
    print(m)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

c = Counter(A)

mx = max(A)
B = list(set(A))
B.remove(mx)
bmx = max(B)
for i in range(N):
    if A[i] != mx:
        print(mx)
    elif c[mx] == 1:
        print(bmx)
    else:
        print(mx)

Submission status: Runtime Error

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

max_itr = [i for i, v in enumerate(A) if v == max(A)]
max_number = max(A)
for i in range(N):
  if i not in max_itr:
    print(max_number)
  else:
    print(sorted(A)[-2])

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(input()) for _ in range(n)]
aa=sorted(a[:])
for i in range(n):
  k=a[i]
  t=-1
  while True:
      if aa[t] != k:
          print(aa[t])
          break
      else: t -= 1

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

ANS = []
for i in range(N):
  Alist = A[:i]+A[i+1:]
  ANS.append(max(Alist))

for i in ANS:
    print(i)

Submission status: Runtime Error

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

for i in range(len(num)):
    a = max(num[:i])
    b = max(num[i+1:])
    print(max(a, b))

Submission status: Runtime Error

Solution code:
# Setup
import sys
sys.setrecursionlimit(4100000)
n = int(input())
a = [int(input()) for i in range(n)]
heap = []
for i in range(n):
    heapq.heappush(heap,-a[i])
for i in range(n):
    temp = heapq.heappop(heap)
    if -a[i] == temp:
        temp2 = heapq.heappop(heap)
        print(-temp2)
        heapq.heappush(heap,temp)
        heapq.heappush(heap,temp2)
    else:
        print(-temp)
        heapq.heappush(heap,temp)

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
ma=max(a)
ma_index=a.index(ma)
for i in range(n):
    if i==ma_index:
        print(*max(a[:i]+a[i+1:]))
    else:
        print(ma)

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
a=[]
for i in range(n):
  a+=int(input())
for i in range(n):
  b = copy.copy(a)
  b.pop(i)
  print(max(b))

Submission status: Runtime Error

Solution code:
N = int(input())
li = []
for _ in range(N):
    r = int(input())
    li.append(r)
li_uniq = list(set(li))
li_uniq.sort(reverse = True)
Max1 = li_uniq[0]
Max2 = li_uniq[1]
for i in li:
    if i == Max1:
        print(Max2)
    else:
        print(Max1)

Submission status: Runtime Error

Solution code:
A[:].remove(mx1)

Submission status: Runtime Error

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

sA.sort(reverse=True)

f = sA[0]
s = sA[1]

for i in range(N):
    if A[i] == f:
        print(s)
    else:

Submission status: Runtime Error

Solution code:
import copy
A = list(map(int, input().split()))

a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Submission status: Runtime Error

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

m = max(A)
c = A.count(m)
if c==2:
  for _ in range(N):
    print m
else:
  for a in A:
    if a==m:
      print max(t for t in A if t!=m)
    else:
      print m

Submission status: Runtime Error

Solution code:
import copy
A = list(map(int, input().split))

a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Submission status: Runtime Error

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

for a in As:
    print(max([i for i in As if i != a]))