include
include
include
include <bits/stdc++.h>
using namespace std;
int main() { long long n; cin >> n; vector a(n), d(n+1); for(int i = 0; i < n; i++) cin >> a[i]; sort (a.begin() , a.end(),greater()); d[1] = a[0]; d[2] = a[0] + a[1]; d[3] = d[2]; d[4] = d[2] + a[3]; d[5] = min(d[2] + a[3] + a[4],d[1] + a[1] + a[2]); for (int i = 6;i<=n;i++) { d [i] = min(d[i-3] + a[i-2] + a[i-1],min(d[i-5] + a[i-5] + a[i-4] + a[i-3],d[i-1] + a[i-1])); } cout << d[n];
return 0;
}