#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  
  int vec[200002];
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
    map.insert(vec[i]);
  }
  
  for (int i = 0; i < n; ++i) {
    int key = vec[i];
    auto it = map.rbegin();
    if (key < *it) {
      cout << *it << endl;
    }
    else {
      if (map.count(key) > 1) {
        cout << key << endl;
      }
      else {
        auto it = map.find(key);
        if (it != map.begin()) it--;
        cout << *it << endl;
      }
    }
  }
  
  return 0;
}