package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)
	ll := make([]int, n+1)
	rr := make([]int, n+1)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	for i := 1; i <= n; i++ {
		ll[i] = aa[i-1]
		rr[n-i] = aa[n-i]
		if ll[i] < ll[i-1] {
			ll[i] = ll[i-1]
		}
		if rr[n-i] < rr[n-i+1] {
			rr[n-i] = rr[n-i+1]
		}
	}

	for i := 1; i <= n; i++ {
		ans := ll[i-1]
		if ll[i-1] < rr[i+1] {
			ans = rr[i+1]
		}
		fmt.Fprintln(writer, ans)
	}

	writer.Flush()
}
