package main

import (
	"fmt"
	"math"
	"sort"
)

var N int
var A []int

func binarySearch(a []int, k int) (right int) {
	n := len(a)
	left := -1
	right = n - 1
	for right-left > 1 {
		mid := (left + right) / 2
		if a[mid] >= k {
			right = mid
		} else {
			left = mid
		}
	}
	return right
}

func main() {
	fmt.Scan(&N)
	A = make([]int, N)
	max_for_all := -1
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
		if max_for_all < A[i] {
			max_for_all = A[i]
		}
	}
	B := make([]int, N)
	for i := 0; i < N; i++ {
		B[i] = A[i]
	}
	sort.Ints(B)
	for i := 0; i < N; i++ {
		res := max_for_all
		if A[i] == max_for_all {
			idx := binarySearch(B, A[i])
			if idx == 0 {
				idx++
				fmt.Println(B[idx])
				continue
			}
			// if idx <= len(B) {
			// 	if B[idx] == B[idx+1] {
			// 		fmt.Println(B[idx])
			// 		continue
			// 	}
			// }
			fmt.Println(B[idx-1])
			continue
		}
		fmt.Println(res)
	}
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type pairs []Pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}
