#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    # 左から埋めていく場合と
    # 右から埋めていく場合
    #A = []
    #for i in range(n):
    #    A.append(int(input()))
    A = [input() for _ in range(n)]
    
    left = [0] * (n+1)
    right = [0] * (n+1)
    for i in range(1,n+1):
        left[i] = max(left[i-1],A[i-1])
    for i in range(n-2,-1,-1):
        right[i] = max(right[i+1],A[i+1]) # right[i]なのか
    for i in range(n):
        print(max(left[i],right[i]))
if __name__ == '__main__':
  main()
