package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i, _ := range a {
		fmt.Scan(&a[i])
	}

	for i := 0; i < n; i++ {
		num1 := 0
		num2 := 0
		for j := 0; j < i; j++ {
			num1 = max(num1, a[j])
		}
		for j := i + 1; j < n; j++ {
			num2 = max(num2, a[j])
		}
		fmt.Println(max(num1, num2))
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}