#include<iostream>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;

int main()
{
  ll A,B,i,j; cin>>A;
  ll answer[A];for(i=0;i<A;i++)cin>>answer[i];
  ll maximum1 = max_element(answer,answer+A);
  ll maximum2=0;
  for(i=0;i<A;i++)
  {
    if(answer[i]>maximum2 && answer[i]<maximum1)
      maximum2 = answer[i];
  }
  for(i=0;i<A;i++)
  {
   if(answer[i]==maximum1){cout<<maximum2<<endl;}
   else{cout<<maximum1<<endl;}
  }
  return 0;
}