#include<iostream>
#include<set>
#include<cmath>
#include<queue>
using namespace std;
typedef pair<int,int> pi;
#define MAX 1024
const double eps = 1.0e-14;
static const int di [] = {1,0,-1,0};
static const int dj [] = {0,1,0,-1};
inline int ceilSqrt(int n){
  if(n<0)return 0;
  return (int)ceil(sqrt((double)n)-eps);
}

inline bool inside(pi p, int rmax){
  return 0<=p.first&&0<=p.second&&p.second<rmax&&p.first<rmax;
}

int main()
{
  while(true){
    static int Height[MAX][MAX];
    static bool vis[MAX][MAX];
    for(int i = 0; i < MAX; ++ i){
      for(int j = 0; j < MAX; ++j ){
	vis[i][j]=false;
	Height[i][j]=0;
      }
    }
    long long int ans = 0;
    long long int N;
    int rmax;
    cin >> N;
    if( N == 0 )break;

    rmax = ceilSqrt(N);
    queue<pi> q;
    q.push(pi(0,0));
    vis[0][0]=true;
    while(!q.empty()){
      pi now = q.front();q.pop();
      //cout << " NOW : " << now.first << ' ' << now.second << endl;
      Height[now.first][now.second] = ceilSqrt( N - (now.first)*(now.first) - (now.second)*(now.second) );
      if( Height[now.first][now.second] == 0 ) continue;
      for(int i = 0; i < sizeof(di)/sizeof(*di); ++i){
	pi next( now.first + di[i], now.second + dj[i] );
	if( !vis[next.first][next.second] && inside( next, rmax ) ){
	  vis[ next.first ][ next.second ] = true;
	  q.push( next );
	}
      }
    }

    for(int i = 0; i < MAX; ++i){
      for(int j = 0; j < MAX; ++j){
	vis[i][j]=false;
      }
    }
    
    //cout << " -------------------------------- " << endl;
    for(int i = 0; i < rmax; ++i){
      for(int j = 0; j < rmax; ++j){
	//if( N<120 )cout << Height[i][j];
	if( !vis[i][j] && Height[i][j] > 0 ){
	  bool i0=false,j0=false;
	  vis[i][j]=true;
	  q.push( pi(i,j) );
	  while(!q.empty()){
	    pi now = q.front();q.pop();
	    i0 |= now.first == 0;
	    j0 |= now.second == 0;
	    for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
	      pi next(now.first+di[k], now.second+dj[k] );
	      if( !vis[next.first][next.second] && Height[i][j] == Height[next.first][next.second] &&
		  inside( next, rmax ) ){
		vis[next.first][next.second]=true;
		q.push(next);
	      }
	    }
	  }
	  ans += (i0&&j0) ? 1 : ( (i0||j0) ? 2 : 4);
	}
      }
      //if( N < 120 ) cout << endl;
    }
    cout <<6LL*ans<<endl;
  }
  return 0;
}
### Prompt

Create a solution in Cpp for the following problem:

Let J(n) be a three-dimensional body that

* is a union of unit cubes whose all vertices lie on integer coordinates,
* contains all points that are closer than the distance of √n to the origin, and
* is the smallest of all such bodies.



The figure below shows how J(1), J(2), and J(3) look.

<image>

Figure 1: Jaggie Spheres for n = 1, 2, 3

Your task is to calculate how many faces J(n) have. Here, we define two square belong to the same face if they are parallel and share an edge, but don’t if they share just a vertex.



Input

The input consists of multiple data sets, each of which comes with a single line containing an integer n (1 ≤ n ≤ 1000000). The end of input is indicated by n = 0.

Output

For each data set, print the number of faces J(n) have.

Example

Input

1
2
3
4
0


Output

6
30
30
6

### Response

```cpp
#include<iostream>
#include<set>
#include<cmath>
#include<queue>
using namespace std;
typedef pair<int,int> pi;
#define MAX 1024
const double eps = 1.0e-14;
static const int di [] = {1,0,-1,0};
static const int dj [] = {0,1,0,-1};
inline int ceilSqrt(int n){
  if(n<0)return 0;
  return (int)ceil(sqrt((double)n)-eps);
}

inline bool inside(pi p, int rmax){
  return 0<=p.first&&0<=p.second&&p.second<rmax&&p.first<rmax;
}

int main()
{
  while(true){
    static int Height[MAX][MAX];
    static bool vis[MAX][MAX];
    for(int i = 0; i < MAX; ++ i){
      for(int j = 0; j < MAX; ++j ){
	vis[i][j]=false;
	Height[i][j]=0;
      }
    }
    long long int ans = 0;
    long long int N;
    int rmax;
    cin >> N;
    if( N == 0 )break;

    rmax = ceilSqrt(N);
    queue<pi> q;
    q.push(pi(0,0));
    vis[0][0]=true;
    while(!q.empty()){
      pi now = q.front();q.pop();
      //cout << " NOW : " << now.first << ' ' << now.second << endl;
      Height[now.first][now.second] = ceilSqrt( N - (now.first)*(now.first) - (now.second)*(now.second) );
      if( Height[now.first][now.second] == 0 ) continue;
      for(int i = 0; i < sizeof(di)/sizeof(*di); ++i){
	pi next( now.first + di[i], now.second + dj[i] );
	if( !vis[next.first][next.second] && inside( next, rmax ) ){
	  vis[ next.first ][ next.second ] = true;
	  q.push( next );
	}
      }
    }

    for(int i = 0; i < MAX; ++i){
      for(int j = 0; j < MAX; ++j){
	vis[i][j]=false;
      }
    }
    
    //cout << " -------------------------------- " << endl;
    for(int i = 0; i < rmax; ++i){
      for(int j = 0; j < rmax; ++j){
	//if( N<120 )cout << Height[i][j];
	if( !vis[i][j] && Height[i][j] > 0 ){
	  bool i0=false,j0=false;
	  vis[i][j]=true;
	  q.push( pi(i,j) );
	  while(!q.empty()){
	    pi now = q.front();q.pop();
	    i0 |= now.first == 0;
	    j0 |= now.second == 0;
	    for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
	      pi next(now.first+di[k], now.second+dj[k] );
	      if( !vis[next.first][next.second] && Height[i][j] == Height[next.first][next.second] &&
		  inside( next, rmax ) ){
		vis[next.first][next.second]=true;
		q.push(next);
	      }
	    }
	  }
	  ans += (i0&&j0) ? 1 : ( (i0||j0) ? 2 : 4);
	}
      }
      //if( N < 120 ) cout << endl;
    }
    cout <<6LL*ans<<endl;
  }
  return 0;
}
```