#include <bits/stdc++.h>
using namespace std;
int N;
int a[200010];
int main() {
  cin >> N;
  for (int i = 0; (i) < (int)(N); (i)++) scanf("%d", &a[i]);
  int x = 0, y = 0, cnt = 0;
  for (int i = 0; (i) < (int)(N); (i)++)
    if (x <= a[i]) {
      x = a[i];
      cnt++;
    }
  for (int i = 0; (i) < (int)(N); (i)++)
    if (y <= a[i]) {
      if (cnt == 1) {
      } else if (1 < cnt) {
        y = a[i];
      }
    }
  for (int i = 0; (i) < (int)(N); (i)++) {
    if (a[i] == x) {
      cout << y << endl;
    } else {
      cout << x << endl;
    }
  }
  return 0;
}
