#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
template<typename T,typename Transformer>
struct Convolution2D{
  using Matrix = vector< vector<T> >;
  const Transformer tran;
  Convolution2D(Transformer tran):tran(tran){}

  void transpose(Matrix &as){
    int n=as.size(),m=as[0].size();
    Matrix cs(as);
    as.assign(m,vector<T>(n));
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        as[j][i]=cs[i][j];
  }

  void transform(Matrix &as,bool f){
    for(int t=0;t<2;t++){
      for(auto &a:as) tran(a,f);
      transpose(as);
    }
  }

  template<typename Mul>
  Matrix multiply(Matrix as,Matrix bs,Mul mul){
    int nt=as.size()+bs.size()-1;
    int mt=as[0].size()+bs[0].size()-1;
    int n=1,m=1;
    while(n<nt) n<<=1;
    while(m<mt) m<<=1;
    as.resize(n);bs.resize(n);
    for(int i=0;i<n;i++){
      as[i].resize(m,T());
      bs[i].resize(m,T());
    }
    transform(as,0);transform(bs,0);
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        as[i][j]=mul(as[i][j],bs[i][j]);
    transform(as,1);
    return as;
  }
};
//END CUT HERE

constexpr int bmds(int x){
  const int v[] = {1012924417, 985661441, 998244353,
                   897581057, 645922817};
  return v[x];
}
constexpr int brts(int x){
  const int v[] = {5, 3, 3, 3, 3};
  return v[x];
}


template<int X>
struct NTT{
  static constexpr int md = bmds(X);
  static constexpr int rt = brts(X);

  inline int add(int a,int b){
    a+=b;
    if(a>=md) a-=md;
    return a;
  }

  inline int mul(int a,int b){
    return 1LL*a*b%md;
  }

  inline int pow(int a,int b){
    int res=1;
    while(b){
      if(b&1) res=mul(res,a);
      a=mul(a,a);
      b>>=1;
    }
    return res;
  }

  inline int inv(int x){
    return pow(x,md-2);
  }

  vector<vector<int> > rts,rrts;

  void ensure_base(int n){
    if((int)rts.size()>=n) return;
    rts.resize(n);rrts.resize(n);
    for(int i=1;i<n;i<<=1){
      if(!rts[i].empty()) continue;
      int w=pow(rt,(md-1)/(i<<1));
      int rw=inv(w);
      rts[i].resize(i);rrts[i].resize(i);
      rts[i][0]=1;rrts[i][0]=1;
      for(int k=1;k<i;k++){
        rts[i][k]=mul(rts[i][k-1],w);
        rrts[i][k]=mul(rrts[i][k-1],rw);
      }
    }
  }

  void ntt(vector<int> &a,bool f,int n=-1){
    if(n==-1) n=a.size();
    assert((n&(n-1))==0);
    ensure_base(n);

    for(int i=0,j=1;j+1<n;j++){
      for(int k=n>>1;k>(i^=k);k>>=1);
      if(i>j) swap(a[i],a[j]);
    }

    for(int i=1;i<n;i<<=1){
      for(int j=0;j<n;j+=i*2){
        for(int k=0;k<i;k++){
          int z=mul(a[i+j+k],f?rrts[i][k]:rts[i][k]);
          a[i+j+k]=add(a[j+k],md-z);
          a[j+k]=add(a[j+k],z);
        }
      }
    }

    if(f){
      int tmp=inv(n);
      for(int i=0;i<n;i++) a[i]=mul(a[i],tmp);
    }
  }
};

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  using ll = long long;
  using D = double;

  int n;
  cin>>n;

  vector< vector<int> > as(n,vector<int>(n));
  auto bs(as);

  int cnt=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>as[i][j];
      bs[n-(i+1)][n-(j+1)]=as[i][j];
      cnt+=as[i][j];
    }
  }

  NTT<1> ntt1;
  NTT<2> ntt2;
  auto tran1=[&](auto &as,bool f){ntt1.ntt(as,f);};
  auto tran2=[&](auto &as,bool f){ntt2.ntt(as,f);};

  Convolution2D<int, decltype(tran1)> conv1(tran1);
  Convolution2D<int, decltype(tran2)> conv2(tran2);
  auto mul1=[&](auto a,auto b){return (ll)a*b%ntt1.md;};
  auto mul2=[&](auto a,auto b){return (ll)a*b%ntt2.md;};

  auto cs1=conv1.multiply(as,bs,mul1);
  auto cs2=conv2.multiply(as,bs,mul2);

  D dom=(D)cnt*(cnt-1)/2;
  D sum=0;
  map<ll, ll> num;
  const int S = 10000;

  auto calc=
    [&](ll a,ll b){
      const ll r01 = ntt2.inv(ntt1.md);
      b = (b - a) * r01 % ntt2.md;
      if (b < 0) b += ntt2.md;
      a = (a + b * ntt1.md);
      return a;
    };

  for(int i=0;i<(int)cs1.size();i++){
    for(int j=0;j<(int)cs1[i].size();j++){
      ll dd=(ll)(i-(n-1))*(i-(n-1))+(ll)(j-(n-1))*(j-(n-1));
      ll cc=calc(cs1[i][j],cs2[i][j]);
      if(dd==0) cc-=cnt;
      if(cc==0) continue;
      num[dd]+=cc;
      sum+=sqrt(dd)*cc;
      if((int)num.size()>S) num.erase(--num.end());
    }
  }

  cout<<sum/dom/2<<endl;
  for(auto p:num)
    cout<<p.first<<" "<<p.second/2<<"\n";
  cout<<flush;
  return 0;
}



Measured memory_bytes: 77216