#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

typedef long long lint;
typedef pair< lint, lint > pll;

int n;
vector< lint > a, lb, ub;
set< pll > used;
set< lint > adjs[5];

void dfs(int i, vector< lint >& res, vector< lint >& cur, int max_size, int max_depth) {
	if ((int)cur.size() == max_size || i == max_depth) {
		if (res.size() < cur.size()) res = cur;
		return;
	}
	
	bool poyo = true;
	
	for (lint v : cur) poyo &= !adjs[i].count(v);
	
	if (poyo) {
		for (lint v = lb[i]; v < ub[i] && v < lb[i] + 5; ++v) {
			bool ok = true;
		
			for (lint u : cur) ok &= !used.count(pll(u, v));
		
			if (ok) {
				cur.push_back(v);
				dfs(i + 1, res, cur, max_size, max_depth);
				cur.pop_back();
			}
		}
	}
	
	dfs(i + 1, res, cur, max_size, max_depth);
}

lint calc() {
	used.clear();
	for_(i,0,n) adjs[i].clear();
	
	lb.assign(n, 0);
	ub.assign(n, 0);
	
	for_(i,0,n) {
		vector< lint > vc, cur;
		
		dfs(0, vc, cur, a[i], i);
		
		//cout << a[i] << " " << vc.size();// << endl;
		
		if (i > 0) lb[i] = ub[i - 1];
		ub[i] = lb[i] + a[i] - vc.size();
		
		//cout << " " << lb[i] << " " << ub[i] << endl;
		
		for (lint u : vc) { adjs[i].insert(u); /*cout << u << " ";*/ }
		//cout << endl;
		
		for (lint u : vc) for (lint v : vc) {
			if (u == v) continue;
			used.insert(pll(u, v));
			used.insert(pll(v, u));
		}
	}
	
	//cout << "-----" << endl;
	
	return ub[n - 1];
}

int main() {
	cin >> n;
	a.assign(n, 0);
	for_(i,0,n) cin >> a[i];
	
	sort(a.begin(), a.end());// greater< lint >());
	
	lint ans = accumulate(a.begin(), a.end(), lint());
	
	do {
		ans = min(ans, calc());
	} while(next_permutation(a.begin(), a.end()));
	
	cout << ans << endl;
}
### Prompt

Your challenge is to write a cpp solution 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 <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

typedef long long lint;
typedef pair< lint, lint > pll;

int n;
vector< lint > a, lb, ub;
set< pll > used;
set< lint > adjs[5];

void dfs(int i, vector< lint >& res, vector< lint >& cur, int max_size, int max_depth) {
	if ((int)cur.size() == max_size || i == max_depth) {
		if (res.size() < cur.size()) res = cur;
		return;
	}
	
	bool poyo = true;
	
	for (lint v : cur) poyo &= !adjs[i].count(v);
	
	if (poyo) {
		for (lint v = lb[i]; v < ub[i] && v < lb[i] + 5; ++v) {
			bool ok = true;
		
			for (lint u : cur) ok &= !used.count(pll(u, v));
		
			if (ok) {
				cur.push_back(v);
				dfs(i + 1, res, cur, max_size, max_depth);
				cur.pop_back();
			}
		}
	}
	
	dfs(i + 1, res, cur, max_size, max_depth);
}

lint calc() {
	used.clear();
	for_(i,0,n) adjs[i].clear();
	
	lb.assign(n, 0);
	ub.assign(n, 0);
	
	for_(i,0,n) {
		vector< lint > vc, cur;
		
		dfs(0, vc, cur, a[i], i);
		
		//cout << a[i] << " " << vc.size();// << endl;
		
		if (i > 0) lb[i] = ub[i - 1];
		ub[i] = lb[i] + a[i] - vc.size();
		
		//cout << " " << lb[i] << " " << ub[i] << endl;
		
		for (lint u : vc) { adjs[i].insert(u); /*cout << u << " ";*/ }
		//cout << endl;
		
		for (lint u : vc) for (lint v : vc) {
			if (u == v) continue;
			used.insert(pll(u, v));
			used.insert(pll(v, u));
		}
	}
	
	//cout << "-----" << endl;
	
	return ub[n - 1];
}

int main() {
	cin >> n;
	a.assign(n, 0);
	for_(i,0,n) cin >> a[i];
	
	sort(a.begin(), a.end());// greater< lint >());
	
	lint ans = accumulate(a.begin(), a.end(), lint());
	
	do {
		ans = min(ans, calc());
	} while(next_permutation(a.begin(), a.end()));
	
	cout << ans << endl;
}
```