#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std

int main(){
  int N;
  int[] A = new int[N];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int[] B = A;
  sort(A.begin(), A.end(), greater<int>());
  int M = A[0];
  for(int i=0;i<N;i++){
    if(B[i] != M){
      cout << M << endl;
    }
    else{
      cout << A[1] << endl;
    }
  }
