#include<bits/stdc++.h>
using namespace std;
int s[20101];
int xx(int a)
{
for(int q=a;q<=20000;q++)
{
if(s[q]>=1)
{
s[q]-=1;
s[a+q]+=1;
return q;
}
}
}
int main()
{
int a,d,f=0,g=0,h=0;
cin>>a;
for(int q=1;q<=a;q++)
{
cin>>d;
s[d]+=1;
}
for(int w=1;w<=20000;w++)
{
if(s[w]>=1)
{
s[w]-=1;
f+=xx(w);
f+=w;
g+=1;
}
if(g==a-1)
{
cout<<f;
return 0;
}
}
}