#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define INF 100100100
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  vector<int> a(n), copy(n);
  rep(i,n){
  	cin >> a[i];
  	copy[i] = a[i]
  }

  sort(copy.begin(), copy.end(), greater<int>());
  rep(i,n){
  	if(a[i] == copy[0]) cout << copy[1] << endl;
  	else cout << copy[0] << endl;
  }
  return 0;
}
