#include <iostream>
#include <vector>
using namespace std;


int main(void){

  int buff;
  int n;

  vector<int> seq;
  cin >> n;

  for(int i = 0; i < n; i++)
  {
    cin >> buff;

    seq.push_back(buff);
  }
  int indent = *max_element(seq.begin(),seq.end());
  sort(seq.begin(),seq.end());

  for(i = 0; i< n;i++)
    {
      if(indent != seq[i])
        cout << indent << '\n';

      cout << seq[1] << '\n';
    }
  cout << endl;
  return 0;    
}
