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

Solution (Python):
import glob
import numpy as np
import collections



REL_PATH = 'ABC\\134\\C'


TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        seq_len = int(self.input_data())
        seq = np.zeros(seq_len, dtype=np.int)
        for i in range(seq_len):
            seq[i] = int(self.input_data())

        max_num = np.max(seq)
        times = collections.Counter(seq)[max_num]

        if times >= 2:
            for i in range(seq_len):
                print(str(max_num))
        else:
            for i in range(seq_len):
                if seq[i] != max_num:
                    print(str(max_num))
                else:
                    print(np.max(np.hstack((seq[0:i], seq[i+1:seq_len]))))


solver = C(REL_PATH)
solver.exec_resolve()

Solution (Python):
import copy
n = int(input())
l = []
for _ in range(n):
  l.append(int(input()))
m = max(l)
k = copy.copy(l)
k.remove(m)
m2 = max(k)
for i in range(0,n):
    if l[i] != m:
      print(m)
    else:
      print(m2)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A,reverse=True)
MAX1 = B[0]
MAX2 = B[1]

for x in A:
  if x == MAX1:
    print(MAX2)
  else:
    print(MAX1)

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

max_A = sorted_A[0]

for a in A:
    if max_A != a:
        print(max_A)
    else:
        print(sorted_A[1])

Solution (Python):


def solve():
    N = int(input())
    A = []
    max1_num, max2_num = 0, 0
    for i in range(N):
        a = int(input())
        A.append(a)

        if a >= max1_num:
            max1_num, max2_num = a, max1_num
        elif a > max2_num:
            max2_num = a

    """方針
    最大値と、2番めに大きい値を覚えておく。
    除く値が最大値のとき、答えは2番めに大きい値。それ以外は最大値が答え。
    """

    for a in A:
        if a == max1_num:
            print(max2_num)
        else:
            print(max1_num)


if __name__ == "__main__":
    solve()

Solution (Python):
import sys
input = sys.stdin.readline

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

max_d = [-1, -1]
semi_max_d = [-1, -1]

for i in range(n):
    if a[i] > max_d[1]:

        if max_d[1] > semi_max_d[1]:
            semi_max_d[0], semi_max_d[1] = max_d[0], max_d[1]

        max_d[0], max_d[1] = i, a[i]
    else:
        if a[i] > semi_max_d[1]:
            semi_max_d[0], semi_max_d[1] = i, a[i]

[print(semi_max_d[1]) if max_d[0] == i else print(max_d[1]) for i in range(n)]

Solution (Python):
N=int(input())
n1=0
n2=0
a=[]
for i in range(N):
    A=int(input())
    a.append(A)
    n2=max(n2,min(n1,A))
    n1=max(n1,A)
for i in range(N):
    if a[i]==n1:
        print(n2)
    else:
        print(n1)

Solution (Python):
n = int(input())
array =[]

for i in range(n):
  num = int(input())
  array.append(num)

sorta = sorted(array)
max1 = sorta[-1]
max2 = sorta[-2]

for x in array:
  if x != max1:
    print(max1)
  else:
    print(max2)

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

l=sorted(a)

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

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

Solution (Python):
import numpy as np

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

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

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


i1 = np.argmax(a)
temp = a[i1]
a[i1] = 0

i2 = np.argmax(a)
a[i1] = temp


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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline

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

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

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

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

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

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

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

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

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

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

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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

import numpy as np
import math
import copy
import re
import sys


inf = float("inf")
prime = 1

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

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

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

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


def gcd(a, b): 
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): 
  return a * b // gcd (a, b)

def gcd3(lis): 
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): 
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): 
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

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

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


"""
n = int(input())


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


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

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


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

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


"""
a = sorted(a)
a = sorted(a, reverse=True)

"""


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

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   
    print res.start()   
    print res.end()     
    print res.span()    
"""



"""

math.floor()

math.ceil()
"""


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

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

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

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

Solution (Python):
def resolve():
    n = int(input())
    nums = []

    for i in range(n):
        input_num = int(input())
        nums.append(input_num)

    max_num, second_num = max(nums[0], nums[1]), min(nums[0], nums[1])

    for i in range(2, n):
        if nums[i] > max_num:
            second_num = max_num
            max_num = nums[i]
        elif nums[i] > second_num:
            second_num = nums[i]

    for i in nums:
        if i == max_num:
            print(second_num)
        else:
            print(max_num)

resolve()

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




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

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

Solution (Python):

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

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):

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

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

Solution (Python):
n=int(input())
a=[int(input()) for _ in range(n)]
ax,ay = sorted(a, reverse=True)[0:2]
b = [ay if x == ax else ax for x in a]
print('\n'.join(map(str,b)))

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

Solution (Python):
n = int(input())

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

maxn = max(a)


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

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

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

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

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

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

Solution (Python):

def main():
    a = int(input())
    lists= [int(input()) for _ in range(a)]

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

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

if __name__ == '__main__' :
    main()

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

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

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

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


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

Solution (Python):
from operator import itemgetter

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

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

Solution (Python):

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

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

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

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

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

sorted_list = sorted(input_list)

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

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

Solution (Python):

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

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

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

main()

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


if __name__ == '__main__':
	main()

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

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



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

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

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

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

m2 = max(a)

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

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

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

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


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

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

temp = sorted(List)

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

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

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

sorted_a = sorted(a)

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

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

Solution (Python):
import numpy as np


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


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


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

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

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

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

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

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

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

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

Solution (Python):
from itertools import accumulate

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

Solution (Python):

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


all_max = max(c)
first_max_id = c.index(all_max)

c_dash = sorted(c,reverse=True)
second_max_value = c_dash[1]
for i,v in enumerate(c):
    if i != first_max_id:
        pr_val = all_max
    else:
        if all_max == second_max_value:
            pr_val = all_max
        else:
            pr_val = second_max_value
    print(pr_val)

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

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

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


if __name__ == '__main__':
    p_c()

Solution (Python):
N = int(input())
a= []
for i in range(N):
  a.append(int(input()))
max = max(a)
max2=sorted(a)[-2]

for i in range(N):
  if a[i]!=max:
    print(max)
  else:
    print(max2)

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

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

a_sorted = sorted(a)

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

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

Solution (Python):

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

Solution (Python):
N = int(input())

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

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

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

Solution (Python):


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

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

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

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

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

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

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

B = sorted(A)
A_max, A_second_max = B[-1], B[-2] 
for i in A:
    if i == A_max:
        print(A_second_max)
    else:
        print(A_max)

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

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

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

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

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

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

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


if __name__ == '__main__':
    
    main()

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

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

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

m = max(A)


c = 0
for a in A:
    if a == m:
        c += 1


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

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

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

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

A_sorted = sorted(A, reverse=True)

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

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

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

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

Solution (Python):



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

if __name__=='__main__':
  main()

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

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

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

Solution (Python):
n = int(input())
nums = [int(input()) for i in range(n)]
m = max(nums)
m2 = sorted(nums)[-2]
[print(m) if nums[i] != m else print(m2) for i in range(n)]

Solution (Python):
N=int(input())

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

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

Solution (Python):
import numpy as np

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

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


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

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

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

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

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

B = A[:]

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

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

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

Solution (Python):


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

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

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

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

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


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

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


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

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


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

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


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

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


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