#include <iostream>
using namespace std;

int main()
{
  
  int n; cin>>n;
  int arr[n];
  for(int i = 0 ; i < n; i++) cin>>arr[i];
  int pre[n]  = {};
  int post[n] = {};
  pre[0] = arr[0];
  post[n - 1] = arr[n - 1];
  for(int i = 1; i < n ; i++) pre[i] = max(pre[i - 1],arr[i]);
  for(int i = n - 2; i>=0; i--) post[i] = max(post[i + 1] , arr[i]);
  
  for(int i = 0; i < n; i++)
  {
    if(i == n - 1) cout<<pre[i - 1]<<" ";
    else if(i) cout<<post[i + 1]<<" ";
    else cout<<max(pre[i - 1], post[i + 1])<<" ";
  }
  return 0;
}
