Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  vector<int>a(n);
  map<int,int>mp;
  int maxv=0;
  rep(i,n)cin>>a[i],mp[a[i]]++,chmax(maxv,a[i]);
  vector<int>b=a;
  sort(b.rbegin(),b.rend());
  int se=b[1];
  rep(i,n){
    if(a[i]==maxv){
      if(mp[a[i]]!=1)cout<<maxv<<endl;
      else cout<<b[i]<<endl;
    }
    else cout<<maxv<<endl;
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  vector<int>a(n);
  map<int,int>mp;
  int maxv=0;
  rep(i,n)cin>>a[i],mp[a[i]]++,chmax(maxv,a[i]);
  vector<int>b=a;
  sort(b.rbegin(),b.rend());
  int se=b[1];
  rep(i,n){
    if(a[i]==maxv){
      if(mp[a[i]]!=1)cout<<maxv<<endl;
      else cout<<b[i]<<endl;
    }
    else cout<<maxv<<endl;
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Compiler output:
a.cc:118:14: error: redefinition of 'constexpr const ll mod'
  118 | constexpr ll mod = 1e9 + 7;
      |              ^~~
a.cc:29:14: note: 'constexpr const ll mod' previously defined here
   29 | constexpr ll mod = 1e9 + 7;
      |              ^~~
a.cc:119:14: error: redefinition of 'constexpr const ll INF'
  119 | constexpr ll INF = 1LL << 60;
      |              ^~~
a.cc:30:14: note: 'constexpr const ll INF' previously defined here
   30 | constexpr ll INF = 1LL << 60;
      |              ^~~
a.cc:121:4: error: redefinition of 'll gcd(ll, ll)'
  121 | ll gcd(ll n, ll m) {
      |    ^~~
a.cc:32:4: note: 'll gcd(ll, ll)' previously defined here
   32 | ll gcd(ll n, ll m) {
      |    ^~~
a.cc:131:4: error: redefinition of 'll lcm(ll, ll)'
  131 | ll lcm(ll n, ll m) {
      |    ^~~
a.cc:42:4: note: 'll lcm(ll, ll)' previously defined here
   42 | ll lcm(ll n, ll m) {
      |    ^~~
a.cc:135:31: error: redefinition of 'template<class T> bool chmin(T&, T)'
  135 | template<class T> inline bool chmin(T& a, T b) {
      |                               ^~~~~
a.cc:46:31: note: 'template<class T> bool chmin(T&, T)' previously declared here
   46 | template<class T> inline bool chmin(T& a, T b) {
      |                               ^~~~~
a.cc:142:31: error: redefinition of 'template<class T> bool chmax(T&, T)'
  142 | template<class T> inline bool chmax(T& a, T b) {
      |                               ^~~~~
a.cc:53:31: note: 'template<class T> bool chmax(T&, T)' previously declared here
   53 | template<class T> inline bool chmax(T& a, T b) {
      |                               ^~~~~
a.cc:153:6: error: redefinition of 'void solve()'
  153 | void solve(){
      |      ^~~~~
a.cc:64:6: note: 'void solve()' previously defined here
   64 | void solve(){
      |      ^~~~~
a.cc:172:5: error: redefinition of 'int main()'
  172 | int main(){
      |     ^~~~
a.cc:83:5: note: 'int main()' previously defined here
   83 | int main(){
      |     ^~~~