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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)	cin >> a[i];
  b = a;
  sort(b.rbegin(), b.rend());
  for(int i = 0; i < n; i++)	cout << (a[i]==b[0] ? b[1] : b[0]) << " \n"[i+1==n];
  return 0;
}