#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second
typedef long long ll;
using namespace std;
const int N = 2e5;

int a[N+1];


int main() {
  ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
  int n,m = -1;
  cin >> n;
  
  int arr[n];
  for (int i=0; i<n; i++){
    cin >> arr[i];
    a[arr[i]]++;
    m=max(m,arr[i]);
  }
  
  for (int i=0; i<n; i++){
    for (int j=m; j>=0; j--){
      if (a[j]>1||(arr[i]!=j&&a[j])){
        cout << j;
        break;
      }
    }
    cout << "\n';
  }
  return 0;
}

