#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
inline long long read() {
  register long long s = 0, t = 0;
  register char ch = getchar();
  while (!isdigit(ch)) t |= ch == '-', ch = getchar();
  while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
int a[maxn], n;
int Max, Second;
int num;
int main() {
  n = read();
  for (register int i = 1; i <= n; i++) {
    a[i] = read();
    if (a[i] == Max)
      num++;
    else
      Max = max(a[i], Max), num = 1;
  }
  if (num == 1) {
    for (register int i = 1; i <= n; i++) {
      if (a[i] != Max) Second = max(Second, a[i]);
    }
  }
  if (num == 1) {
    for (int i = 1; i <= n; i++) {
      if (a[i] == Max)
        cout << Second << endl;
      else
        cout << Max << endl;
    }
  } else
    for (int i = 1; i <= n; i++) cout << Max << endl;
  return 0;
}
