Problem: F - Point Distance

Problem Statement

You work for invention center as a part time programmer. This center researches movement of protein molecules. It needs how molecules make clusters, so it will calculate distance of all pair molecules and will make a histogram. Molecules’ positions are given by a N x N grid map. Value C_{xy} of cell (x, y) in a grid map means that C_{xy} molecules are in the position (x, y).

You are given a grid map, please calculate histogram of all pair molecules.

Input

Input is formatted as follows.


N
C_{11} C_{12} ... C_{1N}
C_{21} C_{22} ... C_{2N}
...
C_{N1} C_{N2} ... C_{NN}


First line contains the grid map size N (1 \leq N \leq 1024). Each next N line contains N numbers. Each numbers C_{xy} (0 \leq C_{xy} \leq 9) means the number of molecule in position (x,y). There are at least 2 molecules.

Output

Output is formatted as follows.


D_{ave}
d_{1} c_{1}
d_{2} c_{2}
...
d_{m} c_{m}


Print D_{ave} which an average distance of all pair molecules on first line. Next, print histogram of all pair distance. Each line contains a distance d_i and the number of pair molecules c_i(0 \lt c_i). The distance d_i should be calculated by squared Euclidean distance and sorted as increasing order. If the number of different distance is more than 10,000, please show the first 10,000 lines. The answer may be printed with an arbitrary number of decimal digits, but may not contain an absolute or relative error greater than or equal to 10^{-8}.

Sample Input 1


2
1 0
0 1


Output for the Sample Input 1


1.4142135624
2 1


Sample Input 2


3
1 1 1
1 1 1
1 1 1


Output for the Sample Input 2


1.6349751825
1 12
2 8
4 6
5 8
8 2


Sample Input 3


5
0 1 2 3 4
5 6 7 8 9
1 2 3 2 1
0 0 0 0 0
0 0 0 0 1


Output for the Sample Input 3


1.8589994382
0 125
1 379
2 232
4 186
5 200
8 27
9 111
10 98
13 21
16 50
17 37
18 6
20 7
25 6






Example

Input

2
1 0
0 1


Output

1.4142135624
2 1

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i=(a);i<=(b);++i)
#define _rep(i,a,b) for(int i=(a);i>=(b);--i)

using namespace std;
typedef long long ll;

const int maxn=(1<<21)+3;
const double pi=acos(-1);

int _n;
int r[maxn<<1];
ll cnt[maxn];
struct cp{
	double x,y;
	cp(double _x=0.,double _y=0.):x(_x),y(_y){}
	cp operator+(const cp&R)const{return cp(x+R.x,y+R.y);}
	cp operator-(const cp&R)const{return cp(x-R.x,y-R.y);}
	cp operator*(const cp&R)const{return cp(x*R.x-y*R.y,y*R.x+x*R.y);}
}b[maxn<<1],c[maxn<<1];

void FFT(cp*f,int op){
	_for(i,0,_n-1)if(i<r[i])swap(f[i],f[r[i]]);
	for(int i=2;i<=_n;i<<=1){
		int len=i>>1;
		cp tmp(cos(pi/len),op*sin(pi/len));
		for(int j=0;j<_n;j+=i){
			cp t(1,0);
			_for(k,j,j+len-1){
				cp tt=t*f[len+k];
				f[len+k]=f[k]-tt,f[k]=f[k]+tt;
				t=t*tmp;
			}
		}
	}
	if(op==-1)_for(i,0,_n-1)f[i].x/=_n;
}

int main(){
//	freopen("in","r",stdin);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,sum=0,_m;cin>>n;
	const int P=(n-1)*(n<<1|1);
	_for(i,0,n-1){
		_for(j,0,n-1){
			int x;cin>>x;
			sum+=x;
			cnt[0]+=(x)*(x-1)>>1;
			int id=i*(n<<1)+j;
			b[P-id].x=x;
			c[id].x=x;
		}
	}
	
	for(_m=P<<1,_n=1;_n<=_m;_n<<=1);
	_for(i,0,_n-1)r[i]=r[i>>1]>>1|(i&1?_n>>1:0);
	FFT(b,1),FFT(c,1);
	_for(i,0,_n-1)b[i]=b[i]*c[i];
	FFT(b,-1);
	
	double ans=0.;
	_for(i,1,P){
		ll t=(ll)(b[P+i].x+.5);
		if(!t)continue;
		int x=(i/n+1)>>1,y=abs(i-(x*n<<1));
		ans+=sqrt((double)x*x+(double)y*y)*t;
		cnt[x*x+y*y]+=t;
	}
	ans/=(double)sum*(sum-1)/2;
	cout<<fixed<<setprecision(10)<<ans<<'\n';
	
	const int lim=(n-1)*(n-1)<<1;
	int tot=0;
	_for(i,0,lim)if(cnt[i]){
		if(++tot>10000)break;
		cout<<i<<' '<<cnt[i]<<'\n';
	}
return 0; }