#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
struct Edge {
  long long int to, weight;
  Edge(long long int t, long long int w) : to(t), weight(w) {}
};
using graph = vector<vector<long long int>>;
using Graph = vector<vector<Edge>>;
long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
long long int keta(long long int N) {
  int tmp{};
  while (N > 0) {
    tmp += (N % 10);
    N /= 10;
  }
  N = tmp;
  return N;
}
bool kai(string S) {
  bool flag = true;
  for (long long int i = 0; i < S.size() / 2; ++i) {
    if (S[i] != S[S.size() - i - 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
int main() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  long long int x = 0, y = 0;
  long long int count = 0;
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
    x = max(x, a[i]);
    if (a[i] < x) {
      y = max(y, a[i]);
    }
  }
  for (long long int i = 0; i < n; ++i) {
    if (a[i] == x) {
      count++;
    }
  }
  for (long long int i = 0; i < n; ++i) {
    long long int ans = x;
    if (a[i] == x and count == 1) {
      ans = y;
    }
    cout << ans << endl;
  }
  return 0;
}
