#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 5;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  int maxi = 0;
  int suma = 0;
  int maa = 0;
  int mama = 0;
  std::vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > maxi) {
      maxi = a[i];
      suma = i;
    }
    if (a[i] <= maxi) {
      maa = a[i];
      mama = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == suma) {
      v.push_back(maa);
    } else {
      v.push_back(maxi);
    }
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << endl;
  }
  return 0;
}
