#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

bool check(vector<int> &v1, vector<int> &v2){
    vector<int> cnt(5);
    for(auto e : v1) ++cnt[e];
    for(auto e : v2) ++cnt[e];
    int dup = 0;
    for(int i = 0; i < 5; ++i) if(cnt[i] > 1) ++dup;
    return dup <= 1;
}

long long solve(int n, vector<int> &a){
    vector<vector<int>> v;
    vector<vector<int>> v2;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < i;++j){
            v.push_back({j, i});
            for(int k = 0; k < j; ++k){
                v2.push_back({k, j, i});
                for(int l = 0; l < k; ++l){
                    v2.push_back({l, k, j, i});
                }
            }
        }

    vector<vector<vector<int>>> v3(1);
    for(auto &vv : v2) v3.push_back({vv});
    for(auto &vv : v2) for(auto &vvv : v2) if(check(vv, vvv)) v3.push_back({vv, vvv});
    int tmp = 0;

    for(auto vx : v3)
        for(int i = 0; i < (1<<v.size()); ++i){
            vector<long long> cnt(n);
            int pop = 0;
            for(auto vvx : vx){
                pop += vvx.size()-1;
                for(auto e : vvx){
                    ++cnt[e];
                }
            }
            bool okok = true;
            for(int j = 0; j < (int)v.size(); ++j){
                if(~i >> j & 1) continue;
                for(auto vvx : vx) if(!check(vvx, v[j])) okok = false;
                for(auto e : v[j]) ++cnt[e];
                ++pop;
            }
            if(!okok) continue;
            bool ok = true;
            for(int j = 0; j < n; ++j) if(cnt[j] > a[j]) ok = false;
            if(!ok) continue;
            tmp = max(tmp, pop);
        }

    return accumulate(a.begin(), a.end(), 0ll) - tmp;
}

int main(){
    vector<int> a(5);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a[i];
    cout << solve(n, a) << endl;
}
### Prompt

Please create a solution in CPP to the following problem:

There is a complete graph of m vertices. Initially, the edges of the complete graph are uncolored. Sunuke did the following for each i (1 ≤ i ≤ n): Select ai vertices from the complete graph and color all edges connecting the selected vertices with color i. None of the sides were painted in multiple colors. Find the minimum value that can be considered as m.

Constraints

* 1 ≤ n ≤ 5
* 2 ≤ ai ≤ 109

Input


n
a1
.. ..
an


Output

Output the minimum value of m on one line.

Examples

Input

2
3
3


Output

5


Input

5
2
3
4
5
6


Output

12

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

bool check(vector<int> &v1, vector<int> &v2){
    vector<int> cnt(5);
    for(auto e : v1) ++cnt[e];
    for(auto e : v2) ++cnt[e];
    int dup = 0;
    for(int i = 0; i < 5; ++i) if(cnt[i] > 1) ++dup;
    return dup <= 1;
}

long long solve(int n, vector<int> &a){
    vector<vector<int>> v;
    vector<vector<int>> v2;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < i;++j){
            v.push_back({j, i});
            for(int k = 0; k < j; ++k){
                v2.push_back({k, j, i});
                for(int l = 0; l < k; ++l){
                    v2.push_back({l, k, j, i});
                }
            }
        }

    vector<vector<vector<int>>> v3(1);
    for(auto &vv : v2) v3.push_back({vv});
    for(auto &vv : v2) for(auto &vvv : v2) if(check(vv, vvv)) v3.push_back({vv, vvv});
    int tmp = 0;

    for(auto vx : v3)
        for(int i = 0; i < (1<<v.size()); ++i){
            vector<long long> cnt(n);
            int pop = 0;
            for(auto vvx : vx){
                pop += vvx.size()-1;
                for(auto e : vvx){
                    ++cnt[e];
                }
            }
            bool okok = true;
            for(int j = 0; j < (int)v.size(); ++j){
                if(~i >> j & 1) continue;
                for(auto vvx : vx) if(!check(vvx, v[j])) okok = false;
                for(auto e : v[j]) ++cnt[e];
                ++pop;
            }
            if(!okok) continue;
            bool ok = true;
            for(int j = 0; j < n; ++j) if(cnt[j] > a[j]) ok = false;
            if(!ok) continue;
            tmp = max(tmp, pop);
        }

    return accumulate(a.begin(), a.end(), 0ll) - tmp;
}

int main(){
    vector<int> a(5);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a[i];
    cout << solve(n, a) << endl;
}
```