#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[1000005];
signed main(){
freopen("matHS.in","r",stdin);
freopen("matHS.out","w",stdout);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int maxn=0;
for(int i=1;i<=n;i++){
maxn=max(maxn,a[i]);
}
int tot=0;
for(int i=1;i<=n;i++){
if(a[i]==maxn){
tot++;
}
}
cout<<tot+maxn+maxn;
return 0;
}