#include <bits/stdc++.h>
using namespace std;
void chmax(int* a, int* c, int b) {
  if (*a < b) {
    *a = b;
  }
  if (*a > b && b > *c) {
    *c = b;
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> ai(n);
  vector<int> ans(n);
  int max = -1;
  int max2 = -1;
  for (int i = 0; i < n; i++) {
    cin >> ai[i];
    ans[i] = ai[i];
    chmax(&max, &max2, ai[i]);
  }
  sort(ai.begin(), ai.end(), greater<int>());
  int maxcount = 0;
  for (int i = 0; i < n; i++) {
    if (max == ai[i]) {
      maxcount += 1;
      continue;
    } else {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (maxcount > 1) {
      cout << max << endl;
    } else {
      if (max == ans[i])
        cout << max2 << endl;
      else
        cout << max << endl;
    }
  }
  return 0;
}
