#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int>B=A;
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  int Max=B.at(0);
  int Max1=B.at(1);
  for(int i=0;i<N-1;i++){
  if(A.at(i)!=Max)
    cout<<Max<<" ";
    else
      cout<<Max1<<" ";
  
  }if(A.at(N-1)!=Max);
      cout<<Max<<endl;
  else
    cout<<Max1<<endl;

return 0;
}