package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var as []int
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		as = append(as, a)
	}

	sortedAS := make([]int, len(as))
	copy(sortedAS, as)
	sort.Sort(sort.IntSlice(sortedAS))

	for i := 0; i < n; i++ {
		for x := 1; x <= n; x++ {
			if as[i] == sortedAS[n-x] {
				continue
			}
			fmt.Println(sortedAS[n-x])
			break
		}
	}
}
