#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

int main(){
	static int isqrt[1000001]; // isqrt[a] := ceil(sqrt(a))
	rep(a,1001) isqrt[a*a]=a;
	for(int a=999999;a>0;a--) if(isqrt[a]==0) isqrt[a]=isqrt[a+1];

	for(int n;scanf("%d",&n),n;){
		int n2=(int)ceil(sqrt(n));

		// 上から見た面
		const int O=n2; // offset
		static int h[2000][2000];
		rep(x,n2) rep(y,n2) {
			int z2=n-(x*x+y*y);
			if(z2<=0) h[x+O][y+O]=-1;
			else      h[x+O][y+O]=isqrt[z2];
		}
		// 左上 1/4 だけ高さを決めれば、残りは対称性からわかる
		rep(x,n2) rep(y,n2) h[O-x-1][y+O]=h[O-x-1][O-y-1]=h[x+O][O-y-1]=h[x+O][y+O];

		// painting
		int cnt=0;
		static bool vis[2000][2000];
		for(int x=-n2;x<n2;x++) for(int y=-n2;y<n2;y++) vis[x+O][y+O]=false;
		for(int x=-n2;x<n2;x++) for(int y=-n2;y<n2;y++) {
			if(vis[x+O][y+O] || h[x+O][y+O]==-1) continue;
			vis[x+O][y+O]=true;

			static queue< pair<int,int> > Q;
			Q.push(make_pair(x,y));
			while(!Q.empty()){
				int xx=Q.front().first,yy=Q.front().second; Q.pop();
				rep(k,4){
					int xxx=xx+dx[k],yyy=yy+dy[k];
					if(-n2<=xxx && xxx<n2 && -n2<=yyy && yyy<n2
					&& !vis[xxx+O][yyy+O] && h[xxx+O][yyy+O]==h[x+O][y+O]){
						vis[xxx+O][yyy+O]=true;
						Q.push(make_pair(xxx,yyy));
					}
				}
			}

			cnt++;
		}

		printf("%d\n",6*cnt);
	}

	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<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

int main(){
	static int isqrt[1000001]; // isqrt[a] := ceil(sqrt(a))
	rep(a,1001) isqrt[a*a]=a;
	for(int a=999999;a>0;a--) if(isqrt[a]==0) isqrt[a]=isqrt[a+1];

	for(int n;scanf("%d",&n),n;){
		int n2=(int)ceil(sqrt(n));

		// 上から見た面
		const int O=n2; // offset
		static int h[2000][2000];
		rep(x,n2) rep(y,n2) {
			int z2=n-(x*x+y*y);
			if(z2<=0) h[x+O][y+O]=-1;
			else      h[x+O][y+O]=isqrt[z2];
		}
		// 左上 1/4 だけ高さを決めれば、残りは対称性からわかる
		rep(x,n2) rep(y,n2) h[O-x-1][y+O]=h[O-x-1][O-y-1]=h[x+O][O-y-1]=h[x+O][y+O];

		// painting
		int cnt=0;
		static bool vis[2000][2000];
		for(int x=-n2;x<n2;x++) for(int y=-n2;y<n2;y++) vis[x+O][y+O]=false;
		for(int x=-n2;x<n2;x++) for(int y=-n2;y<n2;y++) {
			if(vis[x+O][y+O] || h[x+O][y+O]==-1) continue;
			vis[x+O][y+O]=true;

			static queue< pair<int,int> > Q;
			Q.push(make_pair(x,y));
			while(!Q.empty()){
				int xx=Q.front().first,yy=Q.front().second; Q.pop();
				rep(k,4){
					int xxx=xx+dx[k],yyy=yy+dy[k];
					if(-n2<=xxx && xxx<n2 && -n2<=yyy && yyy<n2
					&& !vis[xxx+O][yyy+O] && h[xxx+O][yyy+O]==h[x+O][y+O]){
						vis[xxx+O][yyy+O]=true;
						Q.push(make_pair(xxx,yyy));
					}
				}
			}

			cnt++;
		}

		printf("%d\n",6*cnt);
	}

	return 0;
}
```