#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

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