#include <bits/stdc++.h>
using namespace std;
void fastik() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
void solve() {}
int main() {
  fastik();
  long long n;
  cin >> n;
  vector<long long> a(n, 0);
  multiset<long long> s;
  set<long long> ss;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
    s.insert(a[i]);
    ss.insert(a[i]);
  }
  for (int i = 0; i < (int)(n); ++i) {
    for (auto it = ss.rbegin(); it != ss.rend(); ++it) {
      if (*it != a[i] || (*it == a[i] && s.count(*it) > 1)) {
        cout << *it << '\n';
        break;
      }
    }
  }
  return 0;
}
