#include <bits/stdc++.h>
using namespace std;
bool filled[100000], part[100000];
int boxSize[100000];
int n;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++) part[i]=1;
    for(int i=0; i<n; i++) cin>>boxSize[i];
    sort(boxSize, boxSize+n, greater<int>());
    for(int i=0; i<n-1; i++){
        int j=i+1;
        while(j<n && boxSize[j]>=boxSize[i]) j++;
        while(j<n && filled[i]) j++;
        while(j<n && !part[j]) j++;
        if(j==n || !part[j]) break;
        filled[i]=1;
        int p=j, sizeCpy = boxSize[i];
        while(p<n && sizeCpy-boxSize[p]>boxSize[p+1]) {
            part[p]=0;
            p++;
            sizeCpy-=boxSize[p];
        }
    }
    int length=0;
    for(int i=0; i<n; i++) if(part[i]) length+=boxSize[i];
    cout<<length<<"\n";
    return 0;
}
