package main

import (
	"fmt"
)

func main() {
	var n int
	var m = 0
	array := []int{}
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		array = append(array, a)
		if m < a {
			m = a
		}
	}
	for i := 0; i < n; i++ {
		b := max(array, i, m)
		fmt.Println(b)
	}
}

func max(a []int, index, m int) int {
	max := a[0]
	for in, i := range a {
		if i > max && index != in {
			max = i
		}
		if m == max {
			break
		}
	}
	return max
}
