#include<iostream>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 1001;


int compute(int x,int y,int n){
  double z = sqrt(n-(double)x*x-(double)y*y);
  if (isnan(z))return 0;
  if ( fabs(z-(n-(double)x*x-(double)y*y))<1e-10)return (int)z;
  else return (int)ceil(z);
}

int height[N][N];
int th[N+1][N+1];

void estimate(int n,int tn){
  rep(i,tn)rep(j,tn)height[i][j]=0;
  rep(y,tn+1){
    rep(x,tn+1)th[y][x]=compute(x,y,n);
  }
  rep(y,tn){
    rep(x,tn){
      int p=0;
      height[y][x]=max(max(th[y][x],th[y+1][x]),
		       max(th[y+1][x],th[y+1][x+1]));
    }
  }
}

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

void dfs(int n,int y,int x,int d,bool &xzero,bool &yzero){
  if (y==-1||x==-1||y==n||x==n||height[y][x] != d)return;
  height[y][x]=0;
  if(x==0)xzero=true;
  if(y==0)yzero=true;
  rep(i,4)dfs(n,y+dy[i],x+dx[i],d,xzero,yzero);
}

int solve(int n){
  int ret=0;
  rep(i,n){
    rep(j,n){
      if (height[i][j] != 0){
	bool xzero=false,yzero=false;
	int tmp=1;
	dfs(n,i,j,height[i][j],xzero,yzero);
	if (xzero&&yzero);
	else if (xzero||yzero)tmp*=2;
	else tmp*=4;
	ret+=tmp;
      }
    }
  }
  return ret*6;
}

int main(){
  int n;
  while(cin>>n && n){
    int tn = (int)(ceil(sqrt(n)));
    estimate(n,tn);
    cout << solve(tn) << endl;
  }
  return false;
}
### Prompt

Please formulate a Cpp solution to 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<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 1001;


int compute(int x,int y,int n){
  double z = sqrt(n-(double)x*x-(double)y*y);
  if (isnan(z))return 0;
  if ( fabs(z-(n-(double)x*x-(double)y*y))<1e-10)return (int)z;
  else return (int)ceil(z);
}

int height[N][N];
int th[N+1][N+1];

void estimate(int n,int tn){
  rep(i,tn)rep(j,tn)height[i][j]=0;
  rep(y,tn+1){
    rep(x,tn+1)th[y][x]=compute(x,y,n);
  }
  rep(y,tn){
    rep(x,tn){
      int p=0;
      height[y][x]=max(max(th[y][x],th[y+1][x]),
		       max(th[y+1][x],th[y+1][x+1]));
    }
  }
}

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

void dfs(int n,int y,int x,int d,bool &xzero,bool &yzero){
  if (y==-1||x==-1||y==n||x==n||height[y][x] != d)return;
  height[y][x]=0;
  if(x==0)xzero=true;
  if(y==0)yzero=true;
  rep(i,4)dfs(n,y+dy[i],x+dx[i],d,xzero,yzero);
}

int solve(int n){
  int ret=0;
  rep(i,n){
    rep(j,n){
      if (height[i][j] != 0){
	bool xzero=false,yzero=false;
	int tmp=1;
	dfs(n,i,j,height[i][j],xzero,yzero);
	if (xzero&&yzero);
	else if (xzero||yzero)tmp*=2;
	else tmp*=4;
	ret+=tmp;
      }
    }
  }
  return ret*6;
}

int main(){
  int n;
  while(cin>>n && n){
    int tn = (int)(ceil(sqrt(n)));
    estimate(n,tn);
    cout << solve(tn) << endl;
  }
  return false;
}
```