#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_H = 10000000;
const int MAX_BITS = 1 << 24;
const int MAX_E2 = 1 << 25;

/* typedef */

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

struct BIT {
  int n;
  int bits[MAX_BITS];

  BIT() {}
  BIT(int _n) { init(_n); }
  
  void init(int _n) { n = _n; }

  int sum(int x) {
    int s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, int v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  void print(int m) {
    for (int i = 1; i <= m; i++) cout << sum(i) << ' ';
    cout << endl;
  }
};

/* global variables */

int hs[MAX_N], nums[MAX_H + 1];
BIT bit;

/* main */

int main() {
  int n;
  cin >> n;

  int max_h = 0;
  for (int i = 0; i < n; i++) {
    cin >> hs[i];
    nums[hs[i]]++;
    if (max_h < hs[i]) max_h = hs[i];
  }

  bit.init(max_h);
  for (int i = 0; i < n; i++) bit.add(max_h + 1 - hs[i], 1);
  //bit.print(max_h);

  int h0 = 0, h1 = max_h + 1;

  while (h0 + 1 < h1) {
    int h = (h0 + h1) / 2;
    if (bit.sum(max_h + 1 - h) < 4 * h) h1 = h;
    else h0 = h;
  }
  //cout << h1 << endl;

  ll count = 1LL + 2LL * h1 * (h1 - 1);

  ll sumh = bit.sum(max_h + 1 - h1);
  for (int h = h1; h <= max_h; h++) {
    count += sumh;
    sumh -= nums[h];
  }

  cout << count << endl;
  
  return 0;
}
### Prompt

Please formulate a CPP solution to the following problem:

Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B.

The territory of Country B is represented by a two-dimensional grid. The first place you occupy is a square on the 2D grid. Each of the soldiers you lead has h_i health. Each soldier can spend 1 health to move. Assuming that the current cell is (a, b), the movement destination is the four directions (a + 1, b), (a-1, b), (a, b + 1), (a, b-1). It is possible to choose. Soldiers will not be able to move from there when their health reaches zero. Any square passed by one or more soldiers can be occupied.

Your job is to find out how many squares you can occupy at most.
However, the size of this two-dimensional grid should be infinitely wide.



Input

The input is given in the following format.


n
h1
..
..
..
hn


Input meets the following constraints
1 ≤ n ≤ 500
1 ≤ hi ≤ 10,000,000

Output

Output the answer value on one line

Examples

Input

2
5
5


Output

11


Input

10
10
10
10
10
10
10
10
10
10
10


Output

93


Input

5
1
2
3
4
5


Output

15

### Response

```cpp
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_H = 10000000;
const int MAX_BITS = 1 << 24;
const int MAX_E2 = 1 << 25;

/* typedef */

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

struct BIT {
  int n;
  int bits[MAX_BITS];

  BIT() {}
  BIT(int _n) { init(_n); }
  
  void init(int _n) { n = _n; }

  int sum(int x) {
    int s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, int v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  void print(int m) {
    for (int i = 1; i <= m; i++) cout << sum(i) << ' ';
    cout << endl;
  }
};

/* global variables */

int hs[MAX_N], nums[MAX_H + 1];
BIT bit;

/* main */

int main() {
  int n;
  cin >> n;

  int max_h = 0;
  for (int i = 0; i < n; i++) {
    cin >> hs[i];
    nums[hs[i]]++;
    if (max_h < hs[i]) max_h = hs[i];
  }

  bit.init(max_h);
  for (int i = 0; i < n; i++) bit.add(max_h + 1 - hs[i], 1);
  //bit.print(max_h);

  int h0 = 0, h1 = max_h + 1;

  while (h0 + 1 < h1) {
    int h = (h0 + h1) / 2;
    if (bit.sum(max_h + 1 - h) < 4 * h) h1 = h;
    else h0 = h;
  }
  //cout << h1 << endl;

  ll count = 1LL + 2LL * h1 * (h1 - 1);

  ll sumh = bit.sum(max_h + 1 - h1);
  for (int h = h1; h <= max_h; h++) {
    count += sumh;
    sumh -= nums[h];
  }

  cout << count << endl;
  
  return 0;
}
```