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):
def main():
  n = int(input())
  alist = [int(input()) for _ in range(n)]
  maxn, maxc, max2n = 0, 0, 0
  for a in alist:
    if maxn <= a:
      if maxn == a:
        maxc += 1
      else:
        max2n = maxn
        maxn = a
        maxc = 1
    elif max2n < a:
      max2n = a

  for a in alist:
    if a == maxn:
      if maxc > 1:
        print(maxn)
      else:
        print(max2n)
    else:
      print(maxn)


if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
a = []
m1 = -1
i1 = 0
m2 = -1
i2 = 1
for i in range(n):
  t = int(input())
  a.append(t)
  if t>m2:
    i2 = i
    m2 = t
  if m2>m1:
    i1, i2 = i2, i1
    m1, m2 = m2, m1
for i in range(n):
  if i!=i1:
    print(m1)
  else:
    print(m2)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
max_list = []
for i in a:
    if i == a_max:
        max_list.append(a.index(i))
if len(max_list) >= 2:
    for i in range(n):
        print(a_max)
else:
    for i in range(n):
        if i in max_list:
            a.remove(a_max)
            print(max(a))
        else:
            print(a_max)

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

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

A.sort(key=lambda A : A[0], reverse=True)

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

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
b=a.copy()
b.sort()
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])

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

pre=[]
suf=[]
temp=-10000000000
for i in range(len(A)):
    temp=max(A[i],temp)
    pre+=[temp]

temp=-100000000000
for i in range(len(A)-1,-1,-1):
    temp=max(temp,A[i])
    suf+=[temp]
suf=suf[::-1]
ans=[]
for i in range(len(A)):
    if i==0:
        ans+=[suf[1]]
    elif i==len(A)-1:
        ans+=[pre[len(A)-2]]
    else:
        ans+=[max(pre[i-1],suf[i+1])]
for x in ans:
    print(x)

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

ma = max(A)
B = sorted(A)

ma = B[-1]
ma2 = B[-2]

for a in A :
    if a == ma :
        print(ma2)
    else :
        print(ma)

Solution (Python):
from copy import copy

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

A.sort(reverse=True)

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

Solution (Python):




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

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

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

for i in range(N):
    print(max(0 if i == 0 else L[i-1], 0 if i == N-1 else R[i+1]))

Solution (Python):



import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

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

Solution (Python):
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]






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


b = [0]*2
for e in A:
    if e > b[0]:
        b[1] = b[0]
        b[0] = e
    elif e > b[1]:
        b[1] = e
        
for e in A:
    if b[0] == e:
        print(b[1])
    else:
        print(b[0])

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

As = sorted(A)

M1 = As[-1]
M2 = As[-2]
for i in range(N):
    a = A[i]
    if a != M1:
        print(M1)
    else:
        print(M2)

Solution (Python):
N, = (int(x) for x in input().split())
A_arr = []
for _ in range(N):
    A_arr.append(int(input()))

A2_arr = sorted(A_arr, reverse=True)

for a in A_arr:
    if a == A2_arr[0]:
        print(A2_arr[1])
    else:
        print(A2_arr[0])

Solution (Python):
n = int(input())
max = 0
sub_max = 0
max_index = 0
for i in range(n):
    a = int(input())
    if(a > max):
        sub_max = max
        max = a
        max_index = i
    elif(a > sub_max):
        sub_max = a
for i in range(n):
    if(i == max_index):
        print(sub_max)
    else:
        print(max)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    sa = sorted(a, reverse=True)

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




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):


n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
sa=sorted(a)
ma=max(a)
ma_2=0
n_ma=0
for i in range(n):
    target = sa[n-1-i]
    if target==ma:
        n_ma+=1
    else:
        ma_2=target
        break
for i in a:
    if i==ma and n_ma>=2:
        print(ma)
    elif i==ma and n_ma==1:
        print(ma_2)
    else:
        print(ma)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]
l1 = [0] * (n + 1)
l2 = [0] * (n + 1)
for i in range(n):
    l1[i + 1] = max(l1[i], a[i])
    l2[n - i - 1] = max(l2[n - i], a[n - i - 1])
for i in range(n):
    print(max(l1[i], l2[i + 1]))

Solution (Python):
n = int(input())
l = []
ll = []
for i in range(n):
  x = int(input())
  l.append(x)
  ll.append(x)
l.sort(reverse=True)
for i in ll:
  if i==l[0]:
    print(l[1])
  else:
    print(l[0])

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
S = sorted(A)
m1 = S[-1]
m2 = S[-2]
for a in A:
  if a == m1:
    print(m2)
  else:
    print(m1)

Solution (Python):
from collections import *
import sys
inp = raw_input

def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

N = ni()
A = [ni() for _ in range(N)]

A2 = list(A)
A2.sort()
for ai in A:
    if ai == A2[-1]:
        print(A2[-2])
    else:
        print(A2[-1])

Solution (Python):
N = int(input())
indexed_A = list(sorted([(int(input()), i) for i in range(N)]))
indexed_A = list(reversed(indexed_A))

for i in range(N):
    for a, j in indexed_A:
        if i != j:
            print(a)
            break

Solution (Python):

from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


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

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




BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
aa = []
for _ in range(n):
    a = int(input())
    aa.append(a)
a2, a1 = sorted(aa)[-2:]

for a in aa:
    if a == a1:
        print(a2)
    else:
        print(a1)

Solution (Python):
N = int(input())
A = [int(input()) for k in range(N)]
B = sorted(A)
for k in range(N):
    if A[k] == B[-1]:
        print(B[-2])
    else:
        print(B[-1])

Solution (Python):
import sys


fin = sys.stdin.readline
N = int(fin())
A_list = [int(fin()) for _ in range(N)]
max_prefix = []
cur_max = float('-inf')
for A in A_list:
    cur_max = max(cur_max, A)
    max_prefix.append(cur_max)

cur_max = float('-inf')
max_suffix = [None] * N
for i in reversed(range(N)):
    A = A_list[i]
    cur_max = max(cur_max, A)
    max_suffix[i] = cur_max

print(max_suffix[1])
for i in range(1, N - 1):
    print(max(max_prefix[i - 1], max_suffix[i + 1]))
print(max_prefix[-2])

Solution (Python):
N = int(input())
a_list = [int(input()) for _ in range(N)]
a_list2 = sorted(a_list)
max1 = a_list2[-1]
max2 = a_list2[-2]

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

Solution (Python):
n = int(input())
a = []
m1 = int(input())
m2 = -1
f = 0
s = -1
for i in range(n-1):
    q = int(input())
    if m1 <= q:
        m2 = m1
        m1 = q
        s = f
        f = i+1
    elif m2 <= q:
        m2 = q
        s = i

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

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

MAX_A = max(A)
MAX_A_CNT = A.count(MAX_A)

Second_MAX_A = B[1]
if MAX_A_CNT >= 2:
    for i in range(N):
        print(MAX_A)
else:
    for i in range(N):
        if A[i] == MAX_A:
            print(Second_MAX_A)
        else:
            print(MAX_A)

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

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

t = copy.deepcopy(A)
t.sort()
ma = t[-1]
maa = t[-2]

for i in A:
  if i == ma:
    print(maa)
  else:
    print(ma)

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

max1 = 0
max2 = 0
for i in range(N):
    if max2 < A[i]:
        if A[i] > max1:
            max2 = max1
            max1 = A[i]
        else:
            max2 = A[i]

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)]
l=sorted(A)[::-1]
for i in A:
    print(l[1] if i==l[0] else l[0])

Solution (Python):
N = int(input())
A = [int(input()) for _ in [0]*N]
B = sorted(A)[::-1]
for a in A:
    if a!=B[0]:print(B[0])
    else:print(B[1])

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

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    B = sorted(A)
    M1 = B[-1]
    M2 = B[-2]
    for a in A:
        if a == M1:
            print(M2)
        else:
            print(M1)
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A_list = [0] * N

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

A_list_sorted = sorted(A_list)

M1 = A_list_sorted[-1]
M2 = A_list_sorted[-2]

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

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

b = tuple(sorted(a, reverse=True))

for i, aa in enumerate(a):
    if b[0] == aa:
        print(b[1])
    else:
        print(b[0])

Solution (Python):
import numpy as np

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

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

arr.sort()



key = arr[-1]
sec = arr[-2]

for i in range(n):
    if raw[i] == key:
        print(sec)
    else:
        print(key)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))

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

A_c = copy.deepcopy(A)
A_c.sort()
for i in range(N):
    if A_c[-1] == A[i]:
        print(A_c[-2])
    else:
        print(A_c[-1])

Solution (Python):
import copy
N = int(input())
A = [int(input()) for i in range(N)]
B = copy.copy(A)
B.sort(reverse=True)
for i in range(N):
    if A[i]==B[0]:
        print(B[1])
    else:
        print(B[0])

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()
    print(3*n**2)
    return


def B():
    n,d = LI()
    f = [1]*(n+2*d+2)
    ans = 0
    for i in range(n):
        if f[i]:
            for j in range(i,i+2*d+1):
                f[j] = 0
            ans += 1
    print(ans)
    return


def C():
    n = I()
    a = IR(n)
    mi = max(a)
    if a.count(mi) > 1:
        for i in range(n):
            print(mi)
    else:
        b = [a[i] for i in range(n)]
        b.sort()
        b = b[::-1]
        for i in range(n):
            if mi != a[i]:
                print(mi)
            else:
                print(b[1])

    return


def D():
    n = I()

    return


def E():
    n = I()

    return


def F():
    n = I()

    return


if __name__ == "__main__":
    C()

Solution (Python):
import sys

inf = 10 ** 18
P = 10 ** 9 + 7

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

A_sorted = sorted(A)

for Ai in A:
    if Ai == A_sorted[-1]:
        print(A_sorted[-2])
    else:
        print(A_sorted[-1])

Solution (Python):
from fractions import gcd
import math


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    m = max(a)
    mi = a.index(m)
    m2 = max(a[:mi] + a[mi+1:])
    for i in range(n):
        if a[i] == m:
            print(m2)
        else:
            print(m)
main()

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


N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)
A.sort(reverse=True)
for i in range(N):
    if A[0]==B[i]:
        print(A[1])
    else:
        print(A[0])

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    s = sorted(A)
    for a in A:
        if a == s[-1]:
            print(s[-2])
        else:
            print(s[-1])
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=[]
for _ in range(n):
    x=int(input())
    a.append(x)
b=sorted(a)
p=b[-1]
q=b[-2]
cnt=0
for y in a:
    if y==p:
        cnt+=1
if cnt>=2:
    for i in range(n):
        print(p)
else:
    for i in range(n):
        if a[i]==p:
            print(q)
        else:
            print(p)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
B = [A[i] for i in range(N)]
B.sort()
for i in range(N):
    if A[i] == B[N - 1]:
        print(B[N - 2])
    else:
        print(B[N - 1])

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = [ni() for _ in range(n)]
b = [ai for ai in a]

first = max(a)
a.remove(first)
second = max(a)

for bi in b:
    print(first if bi != first else second)

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

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

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

Solution (Python):
n=int(input())
a=[[int(input()),i]for i in range(n)]
a.sort()
c=a[-1][0]
d=a[-2][0]
e=a[-1][1]
for i in range(n):
  if i==e:print(d)
  else:print(c)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
a = [(int(input()), i) for i in range(n)]
a.sort(reverse=True)
if a[0][0] == a[1][0]:
    for i in range(n):
        print(a[0][0])
else:
    ans = [0]*n
    for ai, i in a:
        if ai == a[0][0]:
            ans[i] = a[1][0]
        else:
            ans[i] = a[0][0]
    for i in ans:
        print(i)

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


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


if __name__ == "__main__":
    main()

Solution (Python):
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 a in A:
        if a == B[-1]:
            print(B[-2])
        else:
            print(B[-1])

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
AA = [inp() for _ in range(N)]
x = sorted(AA)
M1 = x[-1]
M2 = x[-2]

for a in AA:
    if a == M1:
        print(M2)
    else:
        print(M1)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = [0] * n
    for i in range(n):
        arr[i] = int(input())
    
    l = [0] * n
    r = [0] * n
    
    l[0] = arr[0]
    r[~0] = arr[~0]
    for i in range(1, n):
        l[i] = max(l[i - 1], arr[i])
        r[~i] = max(r[~(i - 1)], arr[~i])
    
    print(r[1])
    for i in range(1, n - 1):
        print(max(l[i - 1], r[i + 1]))
    print(l[~1])
    
    return 0

main()

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())
a=[int(input()) for i in range(n)]
b=sorted(a)
m=b[n-1]
s=b[n-2]
for i in range(n):
  if a[i]==m:
    print(s)
  else:
    print(m)

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

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

B = sorted(A)
M1 = B[-1]
M2 = B[-2]

for a in A :
    if a == M1 :
        print(M2)
    else :
        print(M1)

Solution (Python):
import queue

"""
N = int(input())



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

print(A)

"""
N = int(input())
A = [None]*N
mx = -1
mx2 = -1
for i in range(N):
	A[i] = int(input())
	if mx <= A[i]:
		mx2 = mx
		mx = A[i]
	elif mx2 < A[i]:
		mx2 = A[i]


for i in range(N):
	if A[i] == mx:
		print(mx2)
	else:
		print(mx)

Solution (Python):
import sys

n = int(input())
aaa = list(map(int, sys.stdin.readlines()))
bbb = [(a, i) for i, a in enumerate(aaa)]
bbb.sort()
am1, im1 = bbb[-1]
am2, im2 = bbb[-2]
for i in range(n):
    if i == im1:
        print(am2)
    else:
        print(am1)

Solution (Python):
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 5 + 10)





def main():
    num = int(input())
    data = [int(input()) for i in range(num)]

    aaa = max(data)


    if data.count(aaa) >= 2:
        for i in range(num):
            print(aaa)
    else:
        bbb = 0
        for j in range(num):
            if data[j] == aaa:
                continue
            bbb = max(data[j], bbb)

        for i in range(num):
            if data[i] == aaa:
                print(bbb)
            else:
                print(aaa)





if __name__ == '__main__':
    main()

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

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

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)[::-1]
mx = b[0]
mx2 = b[1]

for i in a:
    if i == mx:
        print(mx2)
    else:
        print(mx)

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