#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int>V(n);

    int maxN=0;
    int maxNN=0
    for(int k = 0; k < n; k++){
      cin >> V.at(k);
      if(k!=0 || k!=n-1){
        maxN = max(maxN,V.at(j);
        maxNN = max(maxN,V.at(j);
      }
    }
    cout << maxN << endl;
    cout << maxNN << endl;

    maxN=0;
    for(int i = 1; i<n-1; i++){
      for(int j = 1; j<n-1; j++){
        if(i!=j){
          maxN = max(maxN,V.at(j));
        }
      }
      cout << maxN <<endl;
      maxN =0;
    }
}









