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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) ((x)==0?0:__builtin_popcount(x))

#define INF 1e16
#define mod 1000000007

int n;
int a[10],b[10],c[10];

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];

  int S=0;
  rep(T,1<<n){
    if(bcnt(T)<=1)continue;
    int pairnum=0;
    rep(i,n)rep(j,i){
      if(((T>>i)&1)&&((T>>j)&1)){
        b[pairnum]|=1<<S;
      }
      pairnum++;
    }
    rep(i,n)if((T>>i)&1)c[i]|=1<<S;
    S++;
  }
  ll res=INF;
  rep(T,1<<S){
    bool ok=true;
    rep(i,n*(n-1)/2){
      if(bcnt(T&b[i])>1){
        ok=false;
        break;
      }
    }
    if(!ok)continue;
    ll sum=0;
    rep(i,n){
      if(bcnt(T&c[i])>a[i]){
        ok=false;
        break;
      }
      sum+=a[i]-bcnt(T&c[i]);
    }
    if(!ok)continue;
    minch(res,sum+bcnt(T));
  }
  cout<<res<<endl;
  return 0;
}


### 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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) ((x)==0?0:__builtin_popcount(x))

#define INF 1e16
#define mod 1000000007

int n;
int a[10],b[10],c[10];

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];

  int S=0;
  rep(T,1<<n){
    if(bcnt(T)<=1)continue;
    int pairnum=0;
    rep(i,n)rep(j,i){
      if(((T>>i)&1)&&((T>>j)&1)){
        b[pairnum]|=1<<S;
      }
      pairnum++;
    }
    rep(i,n)if((T>>i)&1)c[i]|=1<<S;
    S++;
  }
  ll res=INF;
  rep(T,1<<S){
    bool ok=true;
    rep(i,n*(n-1)/2){
      if(bcnt(T&b[i])>1){
        ok=false;
        break;
      }
    }
    if(!ok)continue;
    ll sum=0;
    rep(i,n){
      if(bcnt(T&c[i])>a[i]){
        ok=false;
        break;
      }
      sum+=a[i]-bcnt(T&c[i]);
    }
    if(!ok)continue;
    minch(res,sum+bcnt(T));
  }
  cout<<res<<endl;
  return 0;
}


```