#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
using pll = pair<ll, ll>;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vpii = vector<pii>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
vector<pair<ll, pll>> buf;
pll m;
void dfs(int f,int pos,int cnt,ll s) {
	if (buf.size() == pos) {
		m = max(m, pll(cnt,s));
		return;
	}
	if (buf.size() - pos + cnt <= m.first)return;
	if (!(f&buf[pos].second.first))dfs(f | 1<<pos, pos + 1, cnt + 1, s | 1ll << pos);
	dfs(f, pos + 1, cnt, s);
}
int main() {
	int n;
	cin >> n;
	vi in(n);
	for (auto &a : in)cin >> a;
	sort(ALL(in));
	ll fa = 1ll << 60;
	do{
		buf.clear();
		rep(i, n) {
			int a = in[i];
			m = pii();
			dfs(0, 0, 0, 0);
			ll f = m.second;
			ll s = 0;
			int k = 0;
			int mf = 0;
			for (int i = 0; 1ll << i <= f; i++)if (f & 1ll << i) if (buf[i].first > 1)mf |= 1ll << (buf.size() + k++); else mf |= 1ll << i;
			if (a > m.first)mf |= 1 << buf.size() + k;
			int l = 0;
			for (int i = 0; f >= 1ll << i&&a; i++) {
				if (f & 1ll << i) {
					if (buf[i].first == 1) {
						buf[i].second.first |= mf;
					}
					else {
						buf.push_back(make_pair(1, pii(buf[i].second.first | mf, buf[i].second.second)));
						buf[i].first--;
						for (auto&a : buf)if (a.second.first & 1ll << i)a.second.first |= 1ll << buf.size()-1;
						buf[i].second.first |= 1 << i;
					}
					a--;
				}
			}
			if (a) {
				buf.push_back(make_pair(a, pll(mf, buf.size())));
			}
		}
		ll ans = 0;
		for (auto &a : buf)ans += a.first;
		fa = min(fa, ans);
	} while (next_permutation(ALL(in)));
	cout << fa << endl;
}
### Prompt

Develop a solution in CPP to the problem described below:

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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
using pll = pair<ll, ll>;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vpii = vector<pii>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
vector<pair<ll, pll>> buf;
pll m;
void dfs(int f,int pos,int cnt,ll s) {
	if (buf.size() == pos) {
		m = max(m, pll(cnt,s));
		return;
	}
	if (buf.size() - pos + cnt <= m.first)return;
	if (!(f&buf[pos].second.first))dfs(f | 1<<pos, pos + 1, cnt + 1, s | 1ll << pos);
	dfs(f, pos + 1, cnt, s);
}
int main() {
	int n;
	cin >> n;
	vi in(n);
	for (auto &a : in)cin >> a;
	sort(ALL(in));
	ll fa = 1ll << 60;
	do{
		buf.clear();
		rep(i, n) {
			int a = in[i];
			m = pii();
			dfs(0, 0, 0, 0);
			ll f = m.second;
			ll s = 0;
			int k = 0;
			int mf = 0;
			for (int i = 0; 1ll << i <= f; i++)if (f & 1ll << i) if (buf[i].first > 1)mf |= 1ll << (buf.size() + k++); else mf |= 1ll << i;
			if (a > m.first)mf |= 1 << buf.size() + k;
			int l = 0;
			for (int i = 0; f >= 1ll << i&&a; i++) {
				if (f & 1ll << i) {
					if (buf[i].first == 1) {
						buf[i].second.first |= mf;
					}
					else {
						buf.push_back(make_pair(1, pii(buf[i].second.first | mf, buf[i].second.second)));
						buf[i].first--;
						for (auto&a : buf)if (a.second.first & 1ll << i)a.second.first |= 1ll << buf.size()-1;
						buf[i].second.first |= 1 << i;
					}
					a--;
				}
			}
			if (a) {
				buf.push_back(make_pair(a, pll(mf, buf.size())));
			}
		}
		ll ans = 0;
		for (auto &a : buf)ans += a.first;
		fa = min(fa, ans);
	} while (next_permutation(ALL(in)));
	cout << fa << endl;
}
```