#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long int powr(long long int x, long long int y, long long int p) {
  int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void in_o() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  ;
}
long long int a[200001];
int main() {
  long long int n;
  cin >> n;
  for (long long int i = 0; i < (int)n; i++) {
    cin >> a[i];
  }
  long long int mx = 0, second_mx = 0;
  for (long long int i = 0; i < (int)n; i++) {
    if (a[i] > mx) {
      mx = a[i];
    }
  }
  for (long long int i = 0; i < (int)n; i++) {
    if (a[i] > second_mx && a[i] != mx) {
      second_mx = a[i];
    }
  }
  if (second_mx == 0) second_mx = a[0];
  for (long long int i = 0; i < (int)n; i++) {
    if (a[i] == mx)
      cout << second_mx << endl;
    else
      cout << mx << endl;
  }
  return 0;
}
