#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
template <typename T>
T getSum(T array[], int length) {
  T sum = 0;
  for (int i = 0; i < length; i++) {
    sum += array[i];
  }
  return sum;
}
string ToString(int i) {
  char buffer[1000];
  sprintf(buffer, "%d", i);
  return string(buffer);
}
string convertToN(long n, int base) {
  string ans = "";
  while (n != 0) {
    int temp = n % base;
    ans = ToString(temp) + ans;
    n /= base;
  }
  return ans;
}
template <typename T>
bool containsKey(map<string, T> map, string key) {
  if (map.count(key) == 0) {
    return false;
  }
  return true;
}
bool isPrime(long long num) {
  if (num <= 1) {
    return false;
  }
  for (int i = 2; i < num / 2 + 1; i++) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
bool question(long long middle) { return false; }
long long binarySearch(long long left, long long right) {
  while (right - left > 1) {
    long long middle = (right + left) / 2;
    if (question(middle)) {
      left = middle;
    } else {
      right = middle;
    }
  }
  return left;
}
int main() {
  int N;
  cin >> N;
  int A[N];
  int ori[N];
  for (long long(i) = 0; (i) < (N); (i)++) {
    cin >> A[i];
    ori[i] = A[i];
  }
  sort(A, A + N, std::greater<long long>());
  long long first = A[0];
  long long second = A[0];
  for (long long(i) = 0; (i) < (N); (i)++) {
    if (first != A[i]) {
      second = A[i];
      break;
    }
  }
  for (long long(i) = 0; (i) < (N); (i)++) {
    if (ori[i] != first) {
      cout << first << endl;
      ;
    } else {
      cout << second << endl;
      ;
    }
  }
}
