#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;scanf("%d",&n);
  int a[n],b[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);b[i] = a[i];
  }
  sort(b,b+n,greater<int>());
  for(i=0;i<n;i++){
    if(a[i]==b[0]) printf("%d\n",b[1]);
    else printf("%d\n",b[0]);
  }
}