#include <bits/stdc++.h>
using namespace std;
const int maxn = 200002;
int n, d[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int max1 = 0, max2 = 0, cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    if (d[i] > max1) {
      max1 = d[i];
      cnt1 = 1;
    } else if (d[i] == max1)
      ++cnt1;
    else if (d[i] > max2) {
      max2 = d[i];
      cnt2 = 1;
    } else if (d[i] == max2)
      ++cnt2;
  }
  for (int i = 0; i < n; ++i)
    if (d[i] == max1 && cnt1 == 1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  return 0;
}
