#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a;
  int amax = 0, maxn = 1, second = 0;
  for (int i = 1; i <= n; i++) {
    int ai;
    cin >> ai;
    a.push_back(ai);
    if (ai == amax) {
      maxn++;
    }
    if (ai > amax) {
      amax = ai;
      maxn = 1;
    }
    if (ai > second && ai < amax) second = ai;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i - 1] < amax)
      cout << amax << endl;
    else {
      if (maxn >= 2)
        cout << amax << endl;
      else
        cout << second << endl;
    }
  }
  return 0;
}
