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.array([0 for i in range(seq_len)])
        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(seq[0:i]) if np.max(seq[0:i]) > np.max(seq[i+1:seq_len]) else np.max(seq[i+1:seq_len]))


solver = C(REL_PATH)
solver.exec_resolve()


### FIXED CODE ###

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()