#include <bits/stdc++.h>
using namespace std;
long long num[200000];
long long s[200000];
bool fl[200000];
int fc = 0;
long long fn = 0, sn = 0;
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> num[i];
    if (num[i] > fn) {
      sn = fn;
      fn = num[i];
      fl[i] = true;
      fc++;
    } else if (num[i] == fn)
      fc++;
    else if (num[i] > sn && fn != num[i]) {
      sn = num[i];
    }
  }
  for (long long i = 0; i < n; i++) {
    if (num[i] != fn) {
      cout << fn << endl;
    } else if (sn == 0) {
      cout << fn << endl;
    } else if (fc > 1)
      cout << fn << endl;
    else
      cout << sn << endl;
  }
}
