#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, to) for (int x = 0; x < (to); x++) #define REP(x, a, to) for (int x = (a); x < (to); x++) #define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++) #define EPS (1e-14) using namespace std; typedef long long ll; typedef pair PII; typedef pair PLL; typedef complex Complex; typedef vector< vector > Mat; int N; int A[100005]; int b[100005]; set S; multiset mS; void solve() { rep(i, N) mS.insert(A[i]); rep(i, N) { S.insert(A[i]); b[i] = (*--S.end()); // cout << (*--S.end()) << " hoge" << endl; mS.erase(mS.find(A[i])); if (mS.find(A[i]) == mS.end()) { S.erase(A[i]); } } rep(i, N) { cout << b[i] << " "; } cout << endl; } int main() { cin >> N; rep(i, N) cin >> A[i]; solve(); return 0; }