#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;

#define sz(X) ((int)(X.size()))
#define all(x) x.begin(),x.end()
#define clr(x,c) memset(x,c,sizeof(x))
#define rep(i,s,e) for(int i=s;i<e;i++)

#define maxn 510

bool isIn(int cx, int cy, int x, int y, int r) {
	return (cx-x)*(cx-x) + (cy-y)*(cy-y) <= r*r;
}

bool test1(int x1, int y1, int x2, int y2, int r, int n = 53) { //is intersect?
	rep(i, 0, n+1) rep(j, 0, n+1) {
		if(isIn(x1, y1, i, j, r) && isIn(x2, y2, i, j, r)) {
			//printf("test1: i = %d, j = %d\n", i, j);
			return true;
		}
	}
	return false;
}

bool fast_test(int x1, int y1, int x2, int y2, int r) {
	return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < r*r*2 + 1;
}

int max_sqrt[maxn * maxn];//max_sqrt[j] means max x that x*x<=j

int num[maxn][maxn];
int sum[maxn][maxn];
int cir[maxn][maxn];

struct DD{
	int max_sum, ways;
	void print() {
		printf("max = %d, ways = %d\n", max_sum, ways);
	}
}ddl[maxn][maxn], ddr[maxn][maxn];

void update(DD &dd, DD tmp) {
	if(tmp.max_sum == 0)
		return;
	if(tmp.max_sum > dd.max_sum) {
		dd = tmp;
	} else if(tmp.max_sum == dd.max_sum) {
		dd.ways += tmp.ways;
	}
}

int min_ydis[maxn];

int cnt[55][55];
DD brute_force(int n, int m, int r) {

	DD ans;
	ans.max_sum = 0;
	ans.ways = 0;

	rep(x1, r+1, n-r+1) rep(y1, r+1, m-r+1) {
		rep(x2, x1, n-r+1) rep(y2, r+1, m-r+1) {
			if(x1==x2 && y1>=y2) continue;
			if(cir[x1][y1] + cir[x2][y2] < ans.max_sum) continue;
			clr(cnt, 0);
			bool fail = false;
			DD tmp;
			tmp.max_sum = 0;
			rep(i, 1, n+1) rep(j, 1, m+1) {
				int q = 0;
				if(isIn(x1, y1, i, j, r)) {
					q ++;
					tmp.max_sum += num[i][j];
				}
				if(isIn(x2, y2, i, j, r)) {
					q ++;
					tmp.max_sum += num[i][j];
				}
				if(q == 2) {
					fail = true;
					goto end;
				}
			}
end:;
			if(fail) continue;
			tmp.ways = 1;
			update(ans, tmp);
		}
	}
	return ans;
}

int main() {
	srand(time(NULL));
	for(int i=1, j=1;i<maxn;i++) {
		while(j<i*i && j<maxn*maxn) {
			max_sqrt[j] = i-1;
			j++;
		}
	}
	int n, m, r;

	while(scanf("%d %d %d", &n, &m, &r) != EOF) {
// 	while(true) {
// 		n = 50; m = 50; int r = 14;

		clr(min_ydis, 0);
		for(int xdis=0;xdis<n+1;xdis++) {
			rep(i, 0, xdis+1) rep(j, 0, m+1) {
				if(isIn(0, 0, i, j, r)) {
					int tx = xdis - i;
					if(r*r-tx*tx < 0) continue;
					min_ydis[xdis] = max(min_ydis[xdis], max_sqrt[r*r-tx*tx]+j+1);
				}
			}
			if(test1(0, 0, xdis, min_ydis[xdis], r)){
				assert(false);
			}
		}
		clr(sum, 0);
		rep(i, 1, n+1) rep(j, 1, m+1) {
			scanf("%d", num[i]+j);
			//num[i][j] = rand()%5 + 1;
			sum[i][j] = sum[i][j-1] + num[i][j];
		}
		clr(cir, 0);
		rep(i, r+1, n-r+1) rep(j, r+1, m-r+1) {
			rep(xi, i-r, i+r+1) {
				int len = max_sqrt[r*r - (xi-i)*(xi-i)];
				cir[i][j] += sum[xi][j+len] - sum[xi][j-len-1];
			}
		}
		clr(ddl, 0);
		clr(ddr, 0);
		rep(i, 1, n+1) {
			rep(j, 1, m+1) {
				ddl[i][j] = ddl[i][j-1];
				DD tmp;
				tmp.max_sum = cir[i][j];
				tmp.ways = 1;
				update(ddl[i][j], tmp);
			}
			for(int j=m;j>=1;j--) {
				ddr[i][j] = ddr[i][j+1];
				DD tmp;
				tmp.max_sum = cir[i][j];
				tmp.ways = 1;
				update(ddr[i][j], tmp);
			}
		}

		//DD bbb = brute_force(n, m, r);
		DD ans;
		ans.max_sum = 0;
		ans.ways = 0;
		rep(i, r+1, n-r+1) rep(j, r+1, m-r+1) {
			//printf("i = %d, j = %d\n", i, j);
			DD dd;
			dd.max_sum = 0; dd.ways = 0;
			rep(xi, i, n-r+1) {
				int ydis = min_ydis[abs(i-xi)];
				if(ydis == 0) {
					update(dd, ddl[xi][m]);
				} else {
					if(xi!=i && j-ydis >= 0)
						update(dd, ddl[xi][j-ydis]);
					if(j+ydis <= m)
						update(dd, ddr[xi][j+ydis]);
				}
			}
			if(dd.max_sum && dd.ways)
				dd.max_sum += cir[i][j];
			//printf("max = %d, ways = %d\n", dd.max_sum, dd.ways);
			update(ans, dd);
		}
		printf("%d %d\n", ans.max_sum, ans.ways);
// 		if(ans.max_sum != bbb.max_sum || ans.ways != bbb.ways) {
//
// 			rep(i, 1, n+1) rep(j, 1, m+1) printf("%d%c", num[i][j], (j==m)?'\n':' ');
// 			printf("n = %d, m = %d, r = %d\n", n, m, r);
// 			ans.print();
// 			bbb.print();
// 			break;
// 		}
	}
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;

#define sz(X) ((int)(X.size()))
#define all(x) x.begin(),x.end()
#define clr(x,c) memset(x,c,sizeof(x))
#define rep(i,s,e) for(int i=s;i<e;i++)

#define maxn 510

bool isIn(int cx, int cy, int x, int y, int r) {
	return (cx-x)*(cx-x) + (cy-y)*(cy-y) <= r*r;
}

bool test1(int x1, int y1, int x2, int y2, int r, int n = 53) { //is intersect?
	rep(i, 0, n+1) rep(j, 0, n+1) {
		if(isIn(x1, y1, i, j, r) && isIn(x2, y2, i, j, r)) {
			//printf("test1: i = %d, j = %d\n", i, j);
			return true;
		}
	}
	return false;
}

bool fast_test(int x1, int y1, int x2, int y2, int r) {
	return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < r*r*2 + 1;
}

int max_sqrt[maxn * maxn];//max_sqrt[j] means max x that x*x<=j

int num[maxn][maxn];
int sum[maxn][maxn];
int cir[maxn][maxn];

struct DD{
	int max_sum, ways;
	void print() {
		printf("max = %d, ways = %d\n", max_sum, ways);
	}
}ddl[maxn][maxn], ddr[maxn][maxn];

void update(DD &dd, DD tmp) {
	if(tmp.max_sum == 0)
		return;
	if(tmp.max_sum > dd.max_sum) {
		dd = tmp;
	} else if(tmp.max_sum == dd.max_sum) {
		dd.ways += tmp.ways;
	}
}

int min_ydis[maxn];

DD brute_force(int n, int m, int r) {

	DD ans;
	ans.max_sum = 0;
	ans.ways = 0;
	rep(x1, 1, n+1) rep(y1, 1, m+1) {
		if(cir[x1][y1] == 0) continue;
		rep(x2, x1, n+1) rep(y2, 1, m+1) {
			if(cir[x2][y2]==0) continue;
			if(x1==x2 && y1>=y2) continue;
			if(test1(x1, y1, x2, y2, r)) continue;
			DD tmp;
			tmp.max_sum = cir[x1][y1] + cir[x2][y2];
			tmp.ways = 1;
			update(ans, tmp);
// 			if(cir[x1][y1] + cir[x2][y2] == 19) {
// 				printf("x1 = %d, y1 = %d, x2 = %d, y2 = %d\n", x1, y1, x2, y2);
// 			}
		}
	}
	if(ans.max_sum == 0) ans.ways = 0;
	return ans;
}

int main() {
	for(int i=1, j=1;i<maxn;i++) {
		while(j<i*i && j<maxn*maxn) {
			max_sqrt[j] = i-1;
			j++;
		}
	}
	int n, m, r;

	while(scanf("%d %d %d", &n, &m, &r) != EOF) {
// 	while(true) {
// 		n = rand()%50 + 1; m = rand()%50 + 1; int r = rand()%20;

		clr(min_ydis, 0);
		for(int xdis=0;xdis<maxn;xdis++) {
			rep(i, 0, xdis+1) rep(j, 0, maxn) {
				if(isIn(0, 0, i, j, r)) {
					int tx = xdis - i;
					if(r*r-tx*tx < 0) continue;
					min_ydis[xdis] = max(min_ydis[xdis], max_sqrt[r*r-tx*tx]+j+1);
				}
			}
		}
		clr(sum, 0);
		rep(i, 1, n+1) rep(j, 1, m+1) {
			scanf("%d", num[i]+j);
			//num[i][j] = rand()%50 + 1;
			sum[i][j] = sum[i][j-1] + num[i][j];
		}
		clr(cir, 0);
		rep(i, r+1, n-r+1) rep(j, r+1, m-r+1) {
			rep(xi, i-r, i+r+1) {
				int len = max_sqrt[r*r - (xi-i)*(xi-i)];
				cir[i][j] += sum[xi][j+len] - sum[xi][j-len-1];
			}
		}
		clr(ddl, 0);
		clr(ddr, 0);
		rep(i, 1, n+1) {
			rep(j, 1, m+1) {
				ddl[i][j] = ddl[i][j-1];
				DD tmp;
				tmp.max_sum = cir[i][j];
				tmp.ways = 1;
				update(ddl[i][j], tmp);
			}
			for(int j=m;j>=1;j--) {
				ddr[i][j] = ddr[i][j+1];
				DD tmp;
				tmp.max_sum = cir[i][j];
				tmp.ways = 1;
				update(ddr[i][j], tmp);
			}
		}

		//DD bbb = brute_force(n, m, r);
		DD ans;
		ans.max_sum = 0;
		ans.ways = 0;
		rep(i, r+1, n-r+1) rep(j, r+1, m-r+1) {
			//printf("i = %d, j = %d\n", i, j);
			DD dd;
			dd.max_sum = 0; dd.ways = 0;
			rep(xi, i, n-r+1) {
				int ydis = min_ydis[abs(i-xi)];
				if(ydis == 0) {
					update(dd, ddl[xi][m]);
				} else {
					if(xi!=i && j-ydis >= 0)
						update(dd, ddl[xi][j-ydis]);
					if(j+ydis <= m)
						update(dd, ddr[xi][j+ydis]);
				}
			}
			if(dd.max_sum == 0) {
				dd.ways = 0;
			}
			if(dd.ways)
				dd.max_sum += cir[i][j];
			//printf("max = %d, ways = %d\n", dd.max_sum, dd.ways);
			update(ans, dd);
		}
		printf("%d %d\n", ans.max_sum, ans.ways);
// 		if(ans.max_sum != bbb.max_sum || ans.ways != bbb.ways) {
//
// 			rep(i, 1, n+1) rep(j, 1, m+1) printf("%d%c", num[i][j], (j==m)?'\n':' ');
// 			printf("n = %d, m = %d, r = %d\n", n, m, r);
// 			ans.print();
// 			bbb.print();
// 			break;
// 		}
	}
}


#include <algorithm>
#include <cstdio>
#include <cmath>
#define sqr(x) ((x)*(x))
using namespace std;
const int N=510;
int n,m,r,i,j,k,x,y,ans,nn[N],diff[N],s[N][N],c[N][N],f[N][N],g[N][N],h[N][N];
long long cnt,gg[N][N],hh[N][N];
int main() {
    scanf("%d%d%d",&n,&m,&r);
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++) scanf("%d",&c[i][j]);
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
            for (x=1;x<=n;x++)
                if (r*r>=sqr(x-i)) {
                    int t=sqrt(r*r-sqr(x-i)+0.5);
                    nn[x-i]=t;
                    s[x][max(j-t,0)]+=c[i][j];
                    if (j+t<m-r) s[x][j+t+1]-=c[i][j];
                }
    for (i=r+1;i<=n-r;i++)
        for (j=0;j<=m-r;j++) {
            f[i][j]=f[i][j-1]+s[i][j];
            if (g[i][j]==g[i-1][j]) gg[i][j]=gg[i-1][j]+1;
            else gg[i][j]=1;
            g[i][j]=max(g[i-1][j],f[i][j]);
        }
    for (i=r+1;i<=n-r;i++)
        for (j=m-r;j>r;j--) {
            if (h[i][j]==h[i-1][j]) hh[i][j]=hh[i-1][j]+1;
            else hh[i][j]=1;
            h[i][j]=max(h[i][j],h[i][j+1]);
        }
    for(i=0;i<=r*2;++i) {
        int tmp=0;
        for (j=0;j<=r;++j) {
            if (j>r||j<i-r) continue;
            tmp=max(tmp,nn[j]+1+nn[abs(i-j)]);
        }
        diff[i]=tmp;
    }
    for(i=r+1;i<=n-r;++i) {
        for(j=r+1;j<=m-r;++j) {
            for(int ii=r+1;ii<=n-r;++ii) {
                int tmp;
                if(ii-i-1>=2*r||i-ii-1>=2*r) {
                    tmp=f[i][j]+gg[ii][m-r];
                    if (tmp==ans) cnt+=gg[ii][m-r];
                    else if(tmp>ans) {
                        ans=tmp;
                        cnt=hh[ii][m-r];
                    }
                    continue;
                }
                int tmpii=abs(i-ii),tmpjj=diff[tmpii],jj=j-tmpjj;
                if (jj>=r+1) {
                    tmp=f[i][j]+g[ii][jj];
                    if (tmp==ans) cnt+=gg[ii][jj];
                    else if(tmp>ans) {
                        ans=tmp;
                        cnt=gg[ii][jj];
                    }
                }
                jj=j+tmpjj;
                if (jj<=m-r) {
                    tmp=f[i][j]+h[ii][jj];
                    if (tmp==ans) cnt+=hh[ii][jj];
                    else if (tmp>ans){
                        ans=tmp;
                        cnt=hh[ii][jj];
                    }
                }
            }
        }
    }
    printf("%d %I64d\n",ans,cnt);
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <cmath>
#define sqr(x) ((x)*(x))
using namespace std;
const int N=510;
int n,m,r,i,j,k,x,y,ans,nn[N],diff[N],s[N][N],c[N][N],f[N][N],g[N][N],h[N][N];
long long cnt,gg[N][N],hh[N][N];
int main() {
	scanf("%d%d%d",&n,&m,&r);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++) scanf("%d",&c[i][j]);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			for (x=1;x<=n;x++)
				if (r*r>=sqr(x-i)) {
					int t=sqrt(r*r-sqr(x-i)+0.5);
					nn[x-i]=t;
					s[x][max(j-t,0)]+=c[i][j];
					if (j+t<m-r) s[x][j+t+1]-=c[i][j];
				}
	for (i=r+1;i<=n-r;i++)
		for (j=0;j<=m-r;j++)
			f[i][j]=f[i][j-1]+s[i][j];
	for (i=r+1;i<=n-r;i++)
		for (j=r+1;j<=m-r;j++) {
			gg[i][j]=gg[i][j-1];
			if (f[i][j]==g[i][j-1]) gg[i][j]++;
			if (f[i][j]>g[i][j-1]) gg[i][j]=1;
			g[i][j]=max(g[i][j-1],f[i][j]);
		}
	for (i=r+1;i<=n-r;i++)
		for (j=m-r;j>r;j--) {
			hh[i][j]=hh[i][j+1];
			if (f[i][j]==h[i][j+1]) hh[i][j]++;
			if (f[i][j]>h[i][j+1]) hh[i][j]=1;
			h[i][j]=max(h[i][j+1],f[i][j]);
		}
	for(i=0;i<=r*2;++i) {
		int tmp=0;
		for (j=0;j<=r;++j) {
			if (j>r||j<i-r) continue;
			tmp=max(tmp,nn[j]+1+nn[abs(i-j)]);
		}
		diff[i]=tmp;
	}
	for(i=r+1;i<=n-r;++i) {
		for(j=r+1;j<=m-r;++j) {
			for(int ii=r+1;ii<=n-r;++ii) {
				int tmp;
				if(ii-i-1>=2*r||i-ii-1>=2*r) {
					tmp=f[i][j]+g[ii][m-r];
					if (tmp==ans) cnt+=gg[ii][m-r];
					else if(tmp>ans) {
						ans=tmp;
						cnt=gg[ii][m-r];
					}
					continue;
				}
				int tmpii=abs(i-ii),tmpjj=diff[tmpii],jj=j-tmpjj;
				if (jj>=r+1) {
					tmp=f[i][j]+g[ii][jj];
					if (tmp==ans) cnt+=gg[ii][jj];
					else if(tmp>ans) {
						ans=tmp;
						cnt=gg[ii][jj];
					}
				}
				jj=j+tmpjj;
				if (jj<=m-r) {
					tmp=f[i][j]+h[ii][jj];
					if (tmp==ans) cnt+=hh[ii][jj];
					else if (tmp>ans){
						ans=tmp;
						cnt=hh[ii][jj];
					}
				}
			}
		}
	}
	printf("%d %I64d\n",ans,cnt/2ll);
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cmath>
#define sqr(x) ((x)*(x))
using namespace std;
const int N=510;
int n,m,r,i,j,k,x,y,ans,cnt,s[N][N],c[N][N],f[N][N];
struct P{int x,y,f;} a[N*N];
bool cmp(P a,P b) {return a.f>b.f;}
bool check(int x,int y,int x0,int y0) {return sqr(x-x0)+sqr(y-y0)<=r*r;}
bool check2(int x1,int y1,int x2,int y2) {
	int x=(x1+x2)/2,y=(y1+y2)/2;
	if (check(x,y,x1,y1)&&check(x,y,x2,y2)) return false;
	if (check(x+1,y,x1,y1)&&check(x+1,y,x2,y2)) return false;
	if (check(x,y+1,x1,y1)&&check(x,y+1,x2,y2)) return false;
	if (check(x+1,y+1,x1,y1)&&check(x+1,y+1,x2,y2)) return false;
	return true;
}
int main() {
	scanf("%d%d%d",&n,&m,&r);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++) scanf("%d",&c[i][j]);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			for (x=1;x<=n;x++)
				if (r*r>=sqr(x-i)) {
					int t=sqrt(r*r-sqr(x-i)+0.5);
					s[x][max(j-t,0)]+=c[i][j];
					if (j+t<m-r) s[x][j+t+1]-=c[i][j];
				}
	for (i=r+1;i<=n-r;i++)
		for (j=0;j<=m-r;j++) {
			f[i][j]=f[i][j-1]+s[i][j];
			if (j>r) {
				a[k].x=i;a[k].y=j;
				a[k++].f=f[i][j];
			}
		}
	sort(a,a+k,cmp);
	int t=k-1;
	for (i=0;i<t;i++)
		for (j=t;j>i;j--)
			if (check2(a[i].x,a[i].y,a[j].x,a[j].y)) {
				if (a[i].f+a[j].f==ans) cnt++;
				else if (a[i].f+a[j].f>ans) {ans=a[i].f+a[j].f;cnt=1;}
				if (a[t].f>a[j].f) t=j;
			}
	printf("%d %d\n",ans,cnt);
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cmath>
#define sqr(x) ((x)*(x))
using namespace std;
const int N=510;
int n,m,r,i,j,k,x,y,ans,nn[N],diff[N],s[N][N],c[N][N],f[N][N],g[N][N],h[N][N];
long long cnt,gg[N][N],hh[N][N];
int main() {
	scanf("%d%d%d",&n,&m,&r);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++) scanf("%d",&c[i][j]);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			for (x=1;x<=n;x++)
				if (r*r>=sqr(x-i)) {
					int t=sqrt(r*r-sqr(x-i)+0.5);
					nn[x-i]=t;
					s[x][max(j-t,0)]+=c[i][j];
					if (j+t<m-r) s[x][j+t+1]-=c[i][j];
				}
	for (i=r+1;i<=n-r;i++)
		for (j=0;j<=m-r;j++) {
			f[i][j]=f[i][j-1]+s[i][j];
			if (f[i][j]==g[i][j-1]) gg[i][j]=gg[i][j-1]+1;
			else gg[i][j]=1;
			g[i][j]=max(g[i][j-1],f[i][j]);
		}
	for (i=r+1;i<=n-r;i++)
		for (j=m-r;j>r;j--) {
			if (f[i][j]==h[i][j-1]) hh[i][j]=hh[i][j-1]+1;
			else hh[i][j]=1;
			h[i][j]=max(h[i][j-1],f[i][j]);
		}
	for(i=0;i<=r*2;++i) {
		int tmp=0;
		for (j=0;j<=r;++j) {
			if (j>r||j<i-r) continue;
			tmp=max(tmp,nn[j]+1+nn[abs(i-j)]);
		}
		diff[i]=tmp;
	}
	for(i=r+1;i<=n-r;++i) {
		for(j=r+1;j<=m-r;++j) {
			for(int ii=r+1;ii<=n-r;++ii) {
				int tmp;
				if(ii-i-1>=2*r||i-ii-1>=2*r) {
					tmp=f[i][j]+gg[ii][m-r];
					if (tmp==ans) cnt+=gg[ii][m-r];
					else if(tmp>ans) {
						ans=tmp;
						cnt=hh[ii][m-r];
					}
					continue;
				}
				int tmpii=abs(i-ii),tmpjj=diff[tmpii],jj=j-tmpjj;
				if (jj>=r+1) {
					tmp=f[i][j]+g[ii][jj];
					if (tmp==ans) cnt+=gg[ii][jj];
					else if(tmp>ans) {
						ans=tmp;
						cnt=gg[ii][jj];
					}
				}
				jj=j+tmpjj;
				if (jj<=m-r) {
					tmp=f[i][j]+h[ii][jj];
					if (tmp==ans) cnt+=hh[ii][jj];
					else if (tmp>ans){
						ans=tmp;
						cnt=hh[ii][jj];
					}
				}
			}
		}
	}
	printf("%d %I64d\n",ans,cnt);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define fi first
#define se second
#define pii pair < int, int >
#define plli pair < ll, int >
#define pllll pair < ll, ll >
#define mp make_pair
#define pb push_back
#define scan1(_x) scanf("%d", &(_x))
#define scan2(_x,_y) scanf("%d%d", &(_x), &(_y))
#define FOR(_i,_a,_b) for(int (_i) = (_a); (_i) < (_b); (_i)++)
#define me(_M,_v) memset((_M), (_v), sizeof (_M))
#define MAXN 502
#define MOD 1000000007
#define oo (1<<30)
#define EPS 1e-10

using namespace std;

int R, C, r;
int M[MAXN][MAXN], F[MAXN], I[MAXN], AC[MAXN][MAXN];
int S[MAXN][MAXN], MXI[MAXN][MAXN], MXD[MAXN][MAXN], CMXI[MAXN][MAXN], CMXD[MAXN][MAXN];

bool ISeg(pii a, pii b){ return (a.fi - b.fi)*(a.se - b.fi) <= 0 || (b.fi - a.se)*(b.se - a.se) <= 0; }

bool Intersec(pii a){
    for(int i = max(0,a.fi - r); i <= r; i++)
        if( ISeg( mp(1 - F[i], F[i] - 1), mp(a.se - F[a.fi-i] + 1, a.se + F[a.fi-i] - 1)) ) return 1;
    return 0;
}

ll ans = 0, cnt = 0;

void update(int sum, ll cant){
    if( cant == 0 ) return;
    if( sum > ans ){
        ans = sum;
        cnt = cant;
    } else if( sum == ans ) cnt += cant;
}

int main(){
    scanf("%d%d%d", &R, &C, &r);
    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            scanf("%d", &M[i][j]);

    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            AC[i][j+1] = AC[i][j] + M[i][j];

    for(int i = r; i >= 0; i--){
        F[i] = F[i+1];
        while( F[i]*F[i] + i*i <= r*r ) F[i]++;
    }

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++)
            for(int k = i-r; k <= i+r; k++)
                S[i][j] += (AC[k][j + F[abs(k-i)]] - AC[k][j - F[abs(k-i)] + 1]);

    FOR(i,0,R){
        MXI[i][r] = S[i][r];
        CMXI[i][r] = 1;
        FOR(j,r+1,C)
            if( S[i][j] > MXI[i][j-1] ){
                MXI[i][j] = S[i][j];
                CMXI[i][j] = 1;
            } else {
                MXI[i][j] = MXI[i][j-1];
                CMXI[i][j] = CMXI[i][j-1];
                if( S[i][j] == MXI[i][j] ) CMXI[i][j]++;
            }

        MXD[i][C-1-r] = S[i][C-1-r];
        CMXD[i][C-1-r] = 1;
        for(int j = C-2-r; j >= 0; j--)
            if( S[i][j] > MXD[i][j+1] ){
                MXD[i][j] = S[i][j];
                CMXD[i][j] = 1;
            } else {
                MXD[i][j] = MXD[i][j+1];
                CMXD[i][j] = CMXD[i][j+1];
                if( S[i][j] == MXD[i][j] ) CMXD[i][j]++;
            }
    }

    for(int i = 2*r; i >= 0; i--){
        I[i] = I[i+1];
        while( Intersec(mp(i,I[i])) ) I[i]++;
    }

    /*FOR(i,0,2*r+1)
        cout << I[i] << " ";
    puts("");*/

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++){
            for(int k = r; k + r < R; k++)
                if( !I[abs(k-i)] ) update(S[i][j] + MXI[k][C-1], CMXI[k][C-1]);
                else {
                    if( j - I[abs(k-i)] >= r ) update(S[i][j] + MXI[k][j - I[abs(k-i)]], CMXI[k][j - I[abs(k-i)]]);
                    if( j + I[abs(k-i)] < C-r ) update(S[i][j] + MXD[k][j + I[abs(k-i)]], CMXD[k][j + I[abs(k-i)]]);
                }
        }

    cout << ans << " " << cnt/2 << endl;
}


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <utility>
#include <cstring>
#include <sstream>
#include <string>
#include<cassert>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#define fi first
#define se second

using namespace std;

int R, C, r;
int M[501][501], F[300], AC[502][502];
int S[501][501];
pair < int , pair < int , int > > A[250001];
int t = 0;

int X[3], Y[3], cx, cy;

bool Intersec(pair < int , int > &a, pair < int , int > &b) {
   cx = cy = 0;
   X[cx++] = (a.fi + b.fi)/2;
   X[cx++] = X[cx-1] + 1;
   Y[cy++] = (a.se + b.se)/2;
   Y[cy++] = Y[cy-1] + 1;
   for(int i = 0; i < cx; i++)
      for(int j = 0; j < cy; j++)
         if( (X[i]-a.fi)*(X[i]-a.fi) + (Y[j]-a.se)*(Y[j]-a.se) <= r &&
            (X[i]-b.fi)*(X[i]-b.fi) + (Y[j]-b.se)*(Y[j]-b.se) <= r )
               return true;

   return false;
}

int main(){
   scanf("%d%d%d", &R, &C, &r);
   for(int i = 0; i < R; i++)
      for(int j = 0; j < C; j++)
         scanf("%d", &M[i][j]);

   for(int i = 0; i < R; i++)
      for(int j = 0; j < C; j++)
         AC[i][j+1] = AC[i][j] + M[i][j];

   for(int i = r; i >= 0; i--){
      F[i] = F[i+1];
      while( F[i]*F[i] + i*i <= r*r ) F[i]++;
   }
   /*
   pair < int , int > a = make_pair(0,0), b;
   r = 9;
   for(int i = 0; i <= 6; i++){
      b = make_pair(i,0);
      while( Intersec(a,b) ) b.se++;
      cout << i << " " << b.se << endl;
   }*/

   /*for(int i = 0; i <= r; i++)
      cout << F[i] << " ";*/

   for(int i = r; i + r < R; i++)
      for(int j = r; j + r < C; j++){
            for(int k = i-r; k <= i+r; k++)
               S[i][j] += AC[k][j + F[abs(k-i)]] - AC[k][j - F[abs(k-i) + 1]];
            A[t++] = make_pair(S[i][j],make_pair(i,j));
         }

   sort( A, A + t);
   r = r*r;
   int ans = 0, cnt = 0;
   for(int i = t-1; i >= 0; i--)
      for(int j = i-1; j >= 0 && A[i].first + A[j].first >= ans; j--)
         if( !Intersec(A[i].second, A[j].second) ){
            if( A[i].first + A[j].first > ans ){
               ans = A[i].first + A[j].first;
               cnt = 1;
            } else cnt++;
         }
   cout << ans << " " << cnt << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define fi first
#define se second
#define pii pair < int, int >
#define plli pair < ll, int >
#define pllll pair < ll, ll >
#define mp make_pair
#define pb push_back
#define scan1(_x) scanf("%d", &(_x))
#define scan2(_x,_y) scanf("%d%d", &(_x), &(_y))
#define FOR(_i,_a,_b) for(int (_i) = (_a); (_i) < (_b); (_i)++)
#define me(_M,_v) memset((_M), (_v), sizeof (_M))
#define MAXN 502
#define MOD 1000000007
#define oo (1<<30)
#define EPS 1e-10

using namespace std;

int R, C, r;
int M[MAXN][MAXN], F[MAXN], I[MAXN], AC[MAXN][MAXN];
int S[MAXN][MAXN], MXI[MAXN][MAXN], MXD[MAXN][MAXN], CMXI[MAXN][MAXN], CMXD[MAXN][MAXN];

int X[3], Y[3], cx, cy;
bool Intersec(pii a, pii b){
    cx = cy = 0;
    X[cx++] = (a.fi + b.fi)/2;
    X[cx++] = X[cx-1] + 1;
    Y[cy++] = (a.se + b.se)/2;
    Y[cy++] = Y[cy-1] + 1;
    for(int i = 0; i < cx; i++)
        for(int j = 0; j < cy; j++)
            if( (X[i]-a.fi)*(X[i]-a.fi) + (Y[j]-a.se)*(Y[j]-a.se) <= r*r &&
                (X[i]-b.fi)*(X[i]-b.fi) + (Y[j]-b.se)*(Y[j]-b.se) <= r*r )
                    return true;

   return false;
}

ll ans = 0, cnt = 0;

void update(int sum, ll cant){
    if( cant == 0 ) return;
    if( sum > ans ){
        ans = sum;
        cnt = cant;
    } else if( sum == ans ) cnt += cant;
}

int main(){
    scanf("%d%d%d", &R, &C, &r);
    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            scanf("%d", &M[i][j]);

    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            AC[i][j+1] = AC[i][j] + M[i][j];

    for(int i = r; i >= 0; i--){
        F[i] = F[i+1];
        while( F[i]*F[i] + i*i <= r*r ) F[i]++;
    }

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++)
            for(int k = i-r; k <= i+r; k++)
                S[i][j] += AC[k][j + F[abs(k-i)]] - AC[k][j - F[abs(k-i) + 1]];

    FOR(i,0,R){
        MXI[i][r] = S[i][r];
        CMXI[i][r] = 1;
        FOR(j,r+1,C)
            if( S[i][j] > MXI[i][j-1] ){
                MXI[i][j] = S[i][j];
                CMXI[i][j] = 1;
            } else {
                MXI[i][j] = MXI[i][j-1];
                CMXI[i][j] = CMXI[i][j-1];
                if( S[i][j] == MXI[i][j] ) CMXI[i][j]++;
            }

        MXD[i][C-1-r] = S[i][C-1-r];
        CMXD[i][C-1-r] = 1;
        for(int j = C-2-r; j >= 0; j--)
            if( S[i][j] > MXD[i][j+1] ){
                MXD[i][j] = S[i][j];
                CMXD[i][j] = 1;
            } else {
                MXD[i][j] = MXD[i][j+1];
                CMXD[i][j] = CMXD[i][j+1];
                if( S[i][j] == MXD[i][j] ) CMXD[i][j]++;
            }
    }

    for(int i = 2*r; i >= 0; i--){
        I[i] = I[i+1];
        while( Intersec(mp(1,1),mp(i+1,I[i]+1)) ) I[i]++;
    }

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++){
            for(int k = r; k + r  < R; k++)
                if( !I[abs(k-i)] ) update(S[i][j] + MXI[k][C-1], CMXI[k][C-1]);
                else {
                    if( j - I[abs(k-i)] >= r ) update(S[i][j] + MXI[k][j - I[abs(k-i)]], CMXI[k][j - I[abs(k-i)]]);
                    if( j + I[abs(k-i)] < C-r ) update(S[i][j] + MXD[k][j + I[abs(k-i)]], CMXD[k][j + I[abs(k-i)]]);
                }
        }

    cout << ans << " " << cnt/2 << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define fi first
#define se second
#define pii pair < int, int >
#define plli pair < ll, int >
#define pllll pair < ll, ll >
#define mp make_pair
#define pb push_back
#define scan1(_x) scanf("%d", &(_x))
#define scan2(_x,_y) scanf("%d%d", &(_x), &(_y))
#define FOR(_i,_a,_b) for(int (_i) = (_a); (_i) < (_b); (_i)++)
#define me(_M,_v) memset((_M), (_v), sizeof (_M))
#define MAXN 502
#define MOD 1000000007
#define oo (1<<30)
#define EPS 1e-10

using namespace std;

int R, C, r;
int M[MAXN][MAXN], F[MAXN], I[MAXN], AC[MAXN][MAXN];
int S[MAXN][MAXN], MXI[MAXN][MAXN], MXD[MAXN][MAXN], CMXI[MAXN][MAXN], CMXD[MAXN][MAXN];

int X[3], Y[3], cx, cy;
bool Intersec(pii a, pii b){
    cx = cy = 0;
    X[cx++] = (a.fi + b.fi)/2;
    X[cx++] = X[cx-1] + 1;
    Y[cy++] = (a.se + b.se)/2;
    Y[cy++] = Y[cy-1] + 1;
    for(int i = 0; i < cx; i++)
        for(int j = 0; j < cy; j++)
            if( (X[i]-a.fi)*(X[i]-a.fi) + (Y[j]-a.se)*(Y[j]-a.se) <= r*r &&
                (X[i]-b.fi)*(X[i]-b.fi) + (Y[j]-b.se)*(Y[j]-b.se) <= r*r )
                    return true;

    return false;
}

ll ans = 0, cnt = 0;

void update(int sum, ll cant){
    if( cant == 0 ) return;
    if( sum > ans ){
        ans = sum;
        cnt = cant;
    } else if( sum == ans ) cnt += cant;
}

int main(){
    scanf("%d%d%d", &R, &C, &r);
    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            scanf("%d", &M[i][j]);

    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            AC[i][j+1] = AC[i][j] + M[i][j];

    for(int i = r; i >= 0; i--){
        F[i] = F[i+1];
        while( F[i]*F[i] + i*i <= r*r ) F[i]++;
    }

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++)
            for(int k = i-r; k <= i+r; k++)
                S[i][j] += (AC[k][j + F[abs(k-i)]] - AC[k][j - F[abs(k-i)] + 1]);

    FOR(i,0,R){
        MXI[i][r] = S[i][r];
        CMXI[i][r] = 1;
        FOR(j,r+1,C)
            if( S[i][j] > MXI[i][j-1] ){
                MXI[i][j] = S[i][j];
                CMXI[i][j] = 1;
            } else {
                MXI[i][j] = MXI[i][j-1];
                CMXI[i][j] = CMXI[i][j-1];
                if( S[i][j] == MXI[i][j] ) CMXI[i][j]++;
            }

        MXD[i][C-1-r] = S[i][C-1-r];
        CMXD[i][C-1-r] = 1;
        for(int j = C-2-r; j >= 0; j--)
            if( S[i][j] > MXD[i][j+1] ){
                MXD[i][j] = S[i][j];
                CMXD[i][j] = 1;
            } else {
                MXD[i][j] = MXD[i][j+1];
                CMXD[i][j] = CMXD[i][j+1];
                if( S[i][j] == MXD[i][j] ) CMXD[i][j]++;
            }
    }

    for(int i = 2*r; i >= 0; i--){
        I[i] = I[i+1];
        while( Intersec(mp(1,1),mp(i+1,I[i]+1)) ) I[i]++;
    }

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++){
            for(int k = r; k + r < R; k++)
                if( !I[abs(k-i)] ) update(S[i][j] + MXI[k][C-1], CMXI[k][C-1]);
                else {
                    if( j - I[abs(k-i)] >= r ) update(S[i][j] + MXI[k][j - I[abs(k-i)]], CMXI[k][j - I[abs(k-i)]]);
                    if( j + I[abs(k-i)] < C-r ) update(S[i][j] + MXD[k][j + I[abs(k-i)]], CMXD[k][j + I[abs(k-i)]]);
                }
        }

    cout << ans << " " << cnt/2 << endl;
}


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <utility>
#include <cstring>
#include <sstream>
#include <string>
#include<cassert>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#define fi first
#define se second

using namespace std;

int R, C, r;
int M[501][501], F[300], AC[502][502];
int S[501][501];
pair < int , pair < int , int > > A[250001];
int t = 0;

int X[3], Y[3], cx, cy;

bool Intersec(pair < int , int > &a, pair < int , int > &b) {
   cx = cy = 0;
   X[cx++] = (a.fi + b.fi)/2;
   if( (abs(a.fi - b.fi)&1) ) X[cx++] = X[cx-1] + 1;
   Y[cy++] = (a.se + b.se)/2;
   if( (abs(a.se - b.se)&1) ) Y[cy++] = Y[cy-1] + 1;
   for(int i = 0; i < cx; i++)
      for(int j = 0; j < cy; j++)
         if( (X[i]-a.fi)*(X[i]-a.fi) + (Y[j]-a.se)*(Y[j]-a.se) <= r &&
            (X[i]-b.fi)*(X[i]-b.fi) + (Y[j]-b.se)*(Y[j]-b.se) <= r )
               return true;

   return false;
}

int main(){
   scanf("%d%d%d", &R, &C, &r);
   for(int i = 0; i < R; i++)
      for(int j = 0; j < C; j++)
         scanf("%d", &M[i][j]);

   for(int i = 0; i < R; i++)
      for(int j = 0; j < C; j++)
         AC[i][j+1] = AC[i][j] + M[i][j];

   for(int i = r; i >= 0; i--){
      F[i] = F[i+1];
      while( F[i]*F[i] + i*i <= r*r ) F[i]++;
   }

   for(int i = r; i + r < R; i++)
      for(int j = r; j + r < C; j++){
            for(int k = i-r; k <= i+r; k++)
               S[i][j] += AC[k][j + F[abs(k-i)]] - AC[k][j - F[abs(k-i) + 1]];
            A[t++] = make_pair(S[i][j],make_pair(i,j));
         }
   /*
   for(int i = 0; i < R; i++){
      for(int j = 0; j < C; j++)
         cout << S[i][j] << " ";
      puts("");
   }*/

   sort( A, A + t);
   r = r*r;
   int ans = 0, cnt = 0;
   for(int i = t-1; i >= 0; i--)
      for(int j = i-1; j >= 0 && A[i].first + A[j].first >= ans; j--)
         if( !Intersec(A[i].second, A[j].second) ){
            if( A[i].first + A[j].first > ans ){
               ans = A[i].first + A[j].first;
               cnt = 1;
            } else cnt++;
            /*if( ans == 74 )
            cout << A[i].se.fi << " " << A[i].se.se << " " << A[j].se.fi << " " << A[j].se.se << " " << A[i].fi + A[j].fi << endl;
            */
         }
   cout << ans << " " << cnt << endl;
}


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <utility>
#include <cstring>
#include <sstream>
#include <string>
#include<cassert>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#define fi first
#define se second

using namespace std;

int R, C, r;
int M[501][501], F[300], AC[502][502];
int S[501][501];
pair < int , pair < int , int > > A[250001];
int t = 0;

int X[3], Y[3], cx, cy;

bool Intersec(pair < int , int > &a, pair < int , int > &b) {
   cx = cy = 0;
   X[cx++] = (a.first + b.first)/2;
   if( (abs(a.first - b.first)&1) ) X[cx++] = X[cx] + 1;
   Y[cy++] = (a.second + b.second)/2;
   if( (abs(a.second - b.second)&1) ) Y[cy++] = Y[cy] + 1;
   for(int i = 0; i < cx; i++)
      for(int j = 0; j < cy; j++)
         if( (X[i]-a.fi)*(X[i]-a.fi) + (Y[j]-a.se)*(Y[j]-a.se) <= r &&
            (X[i]-b.fi)*(X[i]-b.fi) + (Y[j]-b.se)*(Y[j]-b.se) <= r )
               return true;

   return false;
}

int main(){
   scanf("%d%d%d", &R, &C, &r);
   for(int i = 0; i < R; i++)
      for(int j = 0; j < C; j++)
         scanf("%d", &M[i][j]);

   for(int i = 0; i < R; i++)
      for(int j = 0; j < C; j++)
         AC[i][j+1] = AC[i][j] + M[i][j];

   for(int i = r; i >= 0; i--){
      F[i] = F[i+1];
      while( F[i]*F[i] + i*i <= r*r ) F[i]++;
   }

   for(int i = r; i + r < R; i++)
      for(int j = r; j + r < C; j++){
            for(int k = i-r; k <= i+r; k++)
               S[i][j] += AC[k][j + F[abs(k-i)]] - AC[k][j - F[abs(k-i) + 1]];
            A[t++] = make_pair(S[i][j],make_pair(i,j));
         }

   sort( A, A + t);
   r = r*r;
   int ans = 0, cnt = 0;
   for(int i = t-1; i >= 0; i--)
      for(int j = i-1; j >= 0 && A[i].first + A[j].first >= ans; j--)
         if( !Intersec(A[i].second, A[j].second) ){
            if( A[i].first + A[j].first > ans ){
               ans = A[i].first + A[j].first;
               cnt = 1;
            } else cnt++;
         }

   cout << ans << " " << cnt << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define fi first
#define se second
#define pii pair < int, int >
#define plli pair < ll, int >
#define pllll pair < ll, ll >
#define mp make_pair
#define pb push_back
#define scan1(_x) scanf("%d", &(_x))
#define scan2(_x,_y) scanf("%d%d", &(_x), &(_y))
#define FOR(_i,_a,_b) for(int (_i) = (_a); (_i) < (_b); (_i)++)
#define me(_M,_v) memset((_M), (_v), sizeof (_M))
#define MAXN 502
#define MOD 1000000007
#define oo (1<<30)
#define EPS 1e-10

using namespace std;

int R, C, r;
int M[MAXN][MAXN], F[MAXN], I[MAXN], AC[MAXN][MAXN];
int S[MAXN][MAXN], MXI[MAXN][MAXN], MXD[MAXN][MAXN], CMXI[MAXN][MAXN], CMXD[MAXN][MAXN];

int X[3], Y[3], cx, cy;
bool Intersec(pii a, pii b){
    cx = cy = 0;
    X[cx++] = (a.fi + b.fi)/2;
    X[cx++] = X[cx-1] + 1;
    X[cx++] = X[cx-1] - 2;
    Y[cy++] = (a.se + b.se)/2;
    Y[cy++] = Y[cy-1] + 1;
    Y[cy++] = Y[cy-1] - 2;
    for(int i = 0; i < cx; i++)
        for(int j = 0; j < cy; j++)
            if( (X[i]-a.fi)*(X[i]-a.fi) + (Y[j]-a.se)*(Y[j]-a.se) <= r*r &&
                (X[i]-b.fi)*(X[i]-b.fi) + (Y[j]-b.se)*(Y[j]-b.se) <= r*r )
                    return true;

    return false;
}

ll ans = 0, cnt = 0;

void update(int sum, ll cant){
    if( cant == 0 ) return;
    if( sum > ans ){
        ans = sum;
        cnt = cant;
    } else if( sum == ans ) cnt += cant;
}

int main(){
    scanf("%d%d%d", &R, &C, &r);
    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            scanf("%d", &M[i][j]);

    for(int i = 0; i < R; i++)
        for(int j = 0; j < C; j++)
            AC[i][j+1] = AC[i][j] + M[i][j];

    for(int i = r; i >= 0; i--){
        F[i] = F[i+1];
        while( F[i]*F[i] + i*i <= r*r ) F[i]++;
    }

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++)
            for(int k = i-r; k <= i+r; k++)
                S[i][j] += (AC[k][j + F[abs(k-i)]] - AC[k][j - F[abs(k-i)] + 1]);

    FOR(i,0,R){
        MXI[i][r] = S[i][r];
        CMXI[i][r] = 1;
        FOR(j,r+1,C)
            if( S[i][j] > MXI[i][j-1] ){
                MXI[i][j] = S[i][j];
                CMXI[i][j] = 1;
            } else {
                MXI[i][j] = MXI[i][j-1];
                CMXI[i][j] = CMXI[i][j-1];
                if( S[i][j] == MXI[i][j] ) CMXI[i][j]++;
            }

        MXD[i][C-1-r] = S[i][C-1-r];
        CMXD[i][C-1-r] = 1;
        for(int j = C-2-r; j >= 0; j--)
            if( S[i][j] > MXD[i][j+1] ){
                MXD[i][j] = S[i][j];
                CMXD[i][j] = 1;
            } else {
                MXD[i][j] = MXD[i][j+1];
                CMXD[i][j] = CMXD[i][j+1];
                if( S[i][j] == MXD[i][j] ) CMXD[i][j]++;
            }
    }

    for(int i = 2*r; i >= 0; i--){
        I[i] = I[i+1];
        while( Intersec(mp(1,1),mp(i+1,I[i]+1)) ) I[i]++;
    }

    /*FOR(i,0,2*r+1)
        cout << I[i] << " ";
    puts("");*/

    for(int i = r; i + r < R; i++)
        for(int j = r; j + r < C; j++){
            for(int k = r; k + r < R; k++)
                if( !I[abs(k-i)] ) update(S[i][j] + MXI[k][C-1], CMXI[k][C-1]);
                else {
                    if( j - I[abs(k-i)] >= r ) update(S[i][j] + MXI[k][j - I[abs(k-i)]], CMXI[k][j - I[abs(k-i)]]);
                    if( j + I[abs(k-i)] < C-r ) update(S[i][j] + MXD[k][j + I[abs(k-i)]], CMXD[k][j + I[abs(k-i)]]);
                }
        }

    cout << ans << " " << cnt/2 << endl;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
#include<string>
#include<iostream>
#include<set>
#include<vector>
using namespace std;

int M[510],MM[510],r;

int jud1(int x,int y)
{
    return x*x+y*y<=r*r;
}
int jud2(int x,int y)
{
    int i;
    for(i=0;i<=r;i++)if(jud1(i-x,M[i]-y))
	return 1;
    return 0;
}
int numl[510][510],numr[510][510];
int ml[510][510],mr[510][510];
int a[510][510],s[510][510];

void upd(int &n,int &num,int k,int kk)
{
    if(n<k)
	n=k,num=kk;
    else if(n==k)
	num+=kk;
}
int main()
{
    int n,m,i,j,k;

    scanf("%d%d%d",&n,&m,&r);
    r=min(r,500);

    for(i=0;i<=r;i++)
    {
	for(j=0;j<=r;j++)if(jud1(i,j))
	    M[i]=j;
	else
	    break;
    }

    for(i=0,j=r+r;i<=min(r+r,500);i++)
    {
	while(!jud2(i,j))
	    j--;
	MM[i]=j;
    }

    for(i=1;i<=n;i++)
    {
	for(j=1;j<=m;j++)
	    scanf("%d",&a[i][j]),s[i][j]=s[i][j-1]+a[i][j];
    }
    memset(ml,-1,sizeof(ml));
    memset(mr,-1,sizeof(mr));

    for(i=r+1;i+r<=n;i++)
    {
	for(j=r+1;j+r<=m;j++)
	{
	    int t=0;
	    for(int d=0;d<=r&&i-d>=1;d++)
		t+=s[i-d][min(j+M[d],m)]-s[i-d][max(j-M[d]-1,0)];
	    for(int d=1;d<=r&&i+d<=n;d++)
		t+=s[i+d][min(j+M[d],m)]-s[i+d][max(j-M[d]-1,0)];
	    ml[i][j]=mr[i][j]=a[i][j]=t;
	    numl[i][j]=numr[i][j]=1;
	}
    }
    for(i=r+1;i+r<=n;i++)
    {
	for(j=2+r;j+r<=m;j++)
	{
	    if(ml[i][j]==ml[i][j-1])
		numl[i][j]=numl[i][j-1]+1;
	    else if(ml[i][j]<ml[i][j-1])
		ml[i][j]=ml[i][j-1],numl[i][j]=numl[i][j-1];
	}
	for(j=m-1-r;j>=1+r;j--)
	{
	    if(mr[i][j]==mr[i][j+1])
		numr[i][j]+=numr[i][j+1];
	    else if(mr[i][j]<mr[i][j+1])
		mr[i][j]=mr[i][j+1],numr[i][j]=numr[i][j+1];
	}
    }
    int ans=0,num=0;

    for(i=1+r;i+r<=n;i++)
    {
	for(j=1+r;j+r<=m;j++)
	{
	    int ma=-1,nn=0;

	    for(int d=r+1;d+r<=n;d++)
	    {
		if(abs(d-i)>r+r)
		    upd(ma,nn,ml[d][m-r],numl[d][m-r]);
		else
		{
		    k=abs(d-i);
		    if(j-MM[k]-1>=1+r)
			upd(ma,nn,ml[d][j-MM[k]-1],numl[d][j-MM[k]-1]);
		    if(j+MM[k]<m-r)
			upd(ma,nn,mr[d][j+MM[k]+1],numr[d][j+MM[k]+1]);
		}
	    }
	    if(ma<0)
		continue;
	    upd(ans,num,ma+a[i][j],nn);
	}
    }
    printf("%d %d\n",ans,num/2);
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
#include<string>
#include<iostream>
#include<set>
#include<vector>
using namespace std;

int M[510],MM[510],r;

int jud1(int x,int y)
{
    return x*x+y*y<=r*r;
}
int jud2(int x,int y)
{
    int i;
    for(i=0;i<=r;i++)if(jud1(i-x,M[i]-y))
	return 1;
    return 0;
}
int numl[510][510],numr[510][510];
int ml[510][510],mr[510][510];
int a[510][510],s[510][510];

void upd(int &n,int &num,int k,int kk)
{
    if(n<k)
	n=k,num=kk;
    else if(n==k)
	num+=kk;
}
int main()
{
    int n,m,i,j,k;

    scanf("%d%d%d",&n,&m,&r);
    r=min(r,500);

    for(i=0;i<=r;i++)
    {
	for(j=0;j<=r;j++)if(jud1(i,j))
	    M[i]=j;
	else
	    break;
    }

    for(i=0,j=r+r;i<=min(r+r,500);i++)
    {
	while(!jud2(i,j))
	    j--;
	MM[i]=j;
    }

    for(i=1;i<=n;i++)
    {
	for(j=1;j<=m;j++)
	    scanf("%d",&a[i][j]),s[i][j]=s[i][j-1]+a[i][j];
    }
    memset(ml,-1,sizeof(ml));
    memset(mr,-1,sizeof(mr));

    for(i=r+1;i+r<=n;i++)
    {
	for(j=r+1;j+r<=m;j++)
	{
	    int t=0;
	    for(int d=0;d<=r&&i-d>=1;d++)
		t+=s[i-d][min(j+M[d],m)]-s[i-d][max(j-M[d]-1,0)];
	    for(int d=1;d<=r&&i+d<=n;d++)
		t+=s[i+d][min(j+M[d],m)]-s[i+d][max(j-M[d]-1,0)];
	    ml[i][j]=mr[i][j]=a[i][j]=t;
	    numl[i][j]=numr[i][j]=1;
	}
    }
    for(i=r+1;i+r<=n;i++)
    {
	for(j=2+r;j+r<=m;j++)
	{
	    if(ml[i][j]==ml[i][j-1])
		numl[i][j]=numl[i][j-1]+1;
	    else if(ml[i][j]<ml[i][j-1])
		ml[i][j]=ml[i][j-1],numl[i][j]=numl[i][j-1];
	}
	for(j=m-1-r;j>=1+r;j--)
	{
	    if(mr[i][j]==mr[i][j+1])
		numr[i][j]+=numr[i][j+1];
	    else if(mr[i][j]<mr[i][j+1])
		mr[i][j]=mr[i][j+1],numr[i][j]=numr[i][j+1];
	}
    }
    int ans=0;
    long long num=0;

    for(i=1+r;i+r<=n;i++)
    {
	for(j=1+r;j+r<=m;j++)
	{
	    int ma=-1,nn=0;

	    for(int d=r+1;d+r<=n;d++)
	    {
		if(abs(d-i)>r+r)
		    upd(ma,nn,ml[d][m-r],numl[d][m-r]);
		else
		{
		    k=abs(d-i);
		    if(j-MM[k]-1>=1+r)
			upd(ma,nn,ml[d][j-MM[k]-1],numl[d][j-MM[k]-1]);
		    if(j+MM[k]<m-r)
			upd(ma,nn,mr[d][j+MM[k]+1],numr[d][j+MM[k]+1]);
		}
	    }
	    if(ma<0)
		continue;
	    if(ans==ma+a[i][j])
		num+=nn;
	    else if(ans<ma+a[i][j])
		ans=ma+a[i][j],num=nn;
	}
    }
    printf("%d %I64d\n",ans,num/2);
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
#include<string>
#include<iostream>
#include<set>
#include<vector>
using namespace std;

int M[510],MM[510],r;

int jud1(int x,int y)
{
    return x*x+y*y<=r*r;
}
int jud2(int x,int y)
{
    int i;
    for(i=0;i<=r;i++)if(jud1(i-x,M[i]-y))
	return 1;
    return 0;
}
int ml[510][510],mr[510][510];
int a[510][510],s[510][510];

void upd(int &n,int &num,int k,int kk)
{
    if(n<k)
	n=k,num=1;
    else if(n==k)
	num+=kk;
}
int main()
{
    int n,m,i,j,k;

    scanf("%d%d%d",&n,&m,&r);
    r=min(r,500);

    for(i=0;i<=r;i++)
    {
	for(j=0;j<=r;j++)if(jud1(i,j))
	    M[i]=j;
	else
	    break;
    }

    for(i=0,j=r+r;i<=min(r+r,500);i++)
    {
	while(!jud2(i,j))
	    j--;
	MM[i]=j;
    }

    for(i=1;i<=n;i++)
    {
	for(j=1;j<=m;j++)
	    scanf("%d",&a[i][j]),s[i][j]=s[i][j-1]+a[i][j];
    }
    memset(ml,-1,sizeof(ml));
    memset(mr,-1,sizeof(mr));

    for(i=r+1;i+r<=n;i++)
    {
	for(j=r+1;j+r<=m;j++)
	{
	    int t=0;
	    for(int d=0;d<=r&&i-d>=1;d++)
		t+=s[i-d][min(j+M[d],m)]-s[i-d][max(j-M[d]-1,0)];
	    for(int d=1;d<=r&&i+d<=n;d++)
		t+=s[i+d][min(j+M[d],m)]-s[i+d][max(j-M[d]-1,0)];
	    ml[i][j]=mr[i][j]=a[i][j]=t;
	}
    }
    for(i=1;i<=n;i++)
    {
	for(j=2;j<=m;j++)
	    ml[i][j]=max(ml[i][j],ml[i][j-1]);
	for(j=m-1;j>=1;j--)
	    mr[i][j]=max(mr[i][j],mr[i][j+1]);
    }
    int ans=0,num=0;

    for(i=1+r;i+r<=n;i++)
    {
	for(j=1+r;j+r<=m;j++)
	{
	    int ma=-1,nn=0;

	    for(int d=r+1;d+r<=n;d++)
	    {
		if(abs(d-i)>r+r)
		    upd(ma,nn,ml[d][m],1);
		else
		{
		    k=abs(d-i);
		    if(j-MM[k]-1>=1)
			upd(ma,nn,ml[d][j-MM[k]-1],1);
		    if(j+MM[k]<m)
			upd(ma,nn,mr[d][j+MM[k]+1],1);
		}
	    }
	    if(ma<0)
		continue;
	    upd(ans,num,ma+a[i][j],nn);
	}
    }
    printf("%d %d\n",ans,num/2);
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long LL;
const int MOD = 1000000007;
const int N = 505;
int n , m , r , a[N][N] , l[N][N] , num[N][N];
int dif[N] , Left_Max[N][N] , Left_Cnt[N][N] , Right_Max[N][N] , Right_Cnt[N][N];
LL update (LL &a , LL &b , LL c , LL d) {
    if (c > a) {
        a = c;
        b = d;
    }
    else if (c == a) {
        b += d;
    }
}
int main () {
    #ifndef ONLINE_JUDGE
        freopen ("input.txt" , "r" , stdin);
        // freopen ("output.txt" , "w" , stdout);
    #endif
    scanf ("%d %d %d" , &n , &m , &r);
    for (int i = 1 ; i <= n ; i ++) {
        for (int j = 1 ; j <= m ; j ++) {
            scanf ("%d" , &a[i][j]);
            l[i][j] = l[i][j - 1] + a[i][j];
        }
    }
    for (int i = r + 1 ; i <= n - r ; i ++) {
        for (int j = r + 1 ; j <= m - r ; j ++) {
            num[i][j] = 0;
            for (int k = -r ; k <= r ; k ++) {
                int len = sqrt (r * r - k * k);
                num[i][j] += l[i - k][j + len] - l[i - k][j - len - 1];
            }
            // cout << i << " " << j << " " << num[i][j] << endl;
        }
    }
    for (int i = r + 1 ; i <= n - r ; i ++) {
        for (int j = r + 1 ; j <= m - r ; j ++) {
            if (num[i][j] > Left_Max[i][j - 1]) {
                Left_Max[i][j] = num[i][j];
                Left_Cnt[i][j] ++;
            }
            else if (num[i][j] == Left_Max[i][j - 1]) {
                Left_Max[i][j] = Left_Max[i][j - 1];
                Left_Cnt[i][j] = Left_Cnt[i][j - 1] + 1;
            }
            else {
                Left_Max[i][j] = Left_Max[i][j - 1];
                Left_Cnt[i][j] = Left_Cnt[i][j - 1];
            }
        }
    }
    for (int i = r + 1 ; i <= n - r ; i ++) {
        for (int j = m - r ; j >= r + 1 ; j --) {
            if (num[i][j] > Right_Max[i][j + 1]) {
                Right_Max[i][j] = num[i][j];
                Right_Cnt[i][j] ++;
            }
            else if (num[i][j] == Right_Max[i][j + 1]) {
                Right_Max[i][j] = Right_Max[i][j + 1];
                Right_Cnt[i][j] = Right_Cnt[i][j + 1] + 1;
            }
            else {
                Right_Max[i][j] = Right_Max[i][j + 1];
                Right_Cnt[i][j] = Right_Cnt[i][j + 1];
            }
        }
    }
    // the difference of row is i
    for (int i = 0 ; i <= 2 * r ; i ++) {
        #define gao(m) ((int)sqrt(r * r - (m) * (m)))
        int mindif = 0;
        for (int j = 0 ; j <= r ; j ++) {
            mindif = max (mindif , gao (j) + 1 + gao (abs (i - j)));
        }
        // least difference of col
        dif[i] = mindif;
        // cout << dif[i] << endl;
    }
    LL ans = 0 , ret = 0;
    for (int i = r + 1 ; i <= n - r ; i ++) {
        for (int j = r + 1 ; j <= m - r ; j ++) {
            for (int k = r + 1 ; k <= n - r ; k ++) {
                if (abs (k - i) > 2 * r) {
                    LL val = num[i][j] + Left_Max[k][m - r] , cnt = Left_Cnt[k][m - r];
                    update (ans , ret , val , cnt);
                    // cout << i << " " << j << " " << k << " " << val << " " << cnt << endl;
                }
                else {
                    int Left = j - dif[abs (k - i)] , Right = j + dif[abs (k - i)];
                    // cout << Left << " " << Right << endl;
                    LL val = num[i][j] + Left_Max[k][Left] , cnt = Left_Cnt[k][Left];
                    update (ans , ret , val , cnt);
                    // cout << i << " " << j << " " << k << " " << val << " " << cnt << endl;
                    val = num[i][j] + Right_Max[k][Right] , cnt = Right_Cnt[k][Right];
                    update (ans , ret , val , cnt);
                    // cout << i << " " << j << " " << k << " " << val << " " << cnt << endl;
                }
            }
        }
    }
    if (ret / 2 == 0) ans = 0;
    printf ("%I64d %I64d\n" , ans , ret / 2);
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxn = 505;
const int Maxm = 2 * Maxn;

int n, m, r;
int x[Maxn], ox[Maxm];
int sum[Maxn][Maxn];
int my[Maxn][Maxn];
int has[Maxn][Maxn], cnt[Maxn][Maxn];
int res1;
ll res2;

int main()
{
	scanf("%d %d %d", &n, &m, &r);
	int cur = r;
	for (int i = 0; i <= r; i++) {
		while (i * i + cur * cur > r * r) cur--;
		x[i] = cur;
	}
	for (int i = 0; i <= r + r; i++)
		for (int j = max(i - r, 0); j <= min(i, r); j++)
			ox[i] = max(ox[i], x[j] + x[i - j] + 1);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			scanf("%d", &sum[i][j]); sum[i][j] += sum[i][j - 1];
		}
	for (int i = r + 1; i <= n - r; i++)
		for (int j = r + 1; j <= m - r; j++) {
			for (int k = 0; k <= r; k++) {
				my[i][j] += sum[i - k][j + x[k]] - sum[i - k][j - x[k] - 1];
				if (k) my[i][j] += sum[i + k][j + x[k]] - sum[i + k][j - x[k] - 1];
			}
			has[i][j] = has[i][j - 1]; cnt[i][j] = cnt[i][j - 1];
			if (my[i][j] > has[i][j]) { has[i][j] = my[i][j]; cnt[i][j] = 0; }
			if (my[i][j] == has[i][j]) cnt[i][j]++;
		}
	for (int i = r + 1; i <= n - r; i++)
		for (int j = r + 1; j <= m - r; j++)
			for (int k = r + 1; k <= n - r; k++)
				if (abs(i - k) > r + r) {
					if (my[i][j] + has[k][m] >= res1) {
						if (my[i][j] + has[k][m] > res1) { res1 = my[i][j] + has[k][m]; res2 = 0; }
						res2 += cnt[k][m];
					}
				} else {
					int col = j - ox[abs(i - k)];
					if (col > r && my[i][j] + has[k][col] >= res1) {
						if (my[i][j] + has[k][col] > res1) { res1 = my[i][j] + has[k][col]; res2 = 0; }
						res2 += 2 * cnt[k][col];
					}
				}
	printf("%d %I64d\n", res1, res2 / 2);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxn = 505;
const int Maxm = 2 * Maxn;

int n, m, r;
int x[Maxn], ox[Maxm];
int sum[Maxn][Maxn];
int my[Maxn][Maxn];
int has[Maxn][Maxn], cnt[Maxn][Maxn];
int res1;
ll res2;

int main()
{
	scanf("%d %d %d", &n, &m, &r);
	int cur = r;
	for (int i = 0; i <= r; i++) {
		while (i * i + cur * cur > r * r) cur--;
		x[i] = cur;
	}
	for (int i = 0; i <= r + r; i++)
		for (int j = max(i - r, 0); j <= min(i, r); j++)
			ox[i] = max(ox[i], x[j] + x[i - j] + 1);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			scanf("%d", &sum[i][j]); sum[i][j] += sum[i][j - 1];
		}
	for (int i = r + 1; i <= n - r; i++)
		for (int j = r + 1; j <= m - r; j++) {
			for (int k = 0; k <= r; k++) {
				my[i][j] += sum[i - k][j + x[k]] - sum[i - k][j - x[k] - 1];
				if (k) my[i][j] += sum[i + k][j + x[k]] - sum[i + k][j - x[k] - 1];
			}
			has[i][j] = has[i][j - 1]; cnt[i][j] = cnt[i][j - 1];
			if (my[i][j] > has[i][j]) { has[i][j] = my[i][j]; cnt[i][j] = 0; }
			if (my[i][j] == has[i][j]) cnt[i][j]++;
		}
	for (int i = r + 1; i <= n - r; i++)
		for (int j = r + 1; j <= m - r; j++)
			for (int k = r + 1; k <= n - r; k++)
				if (abs(i - k) > r + r) {
					if (my[i][j] + has[k][m - r] >= res1) {
						if (my[i][j] + has[k][m - r] > res1) { res1 = my[i][j] + has[k][m - r]; res2 = 0; }
						res2 += cnt[k][m - r];
					}
				} else {
					int col = j - ox[abs(i - k)];
					if (col > r && my[i][j] + has[k][col] >= res1) {
						if (my[i][j] + has[k][col] > res1) { res1 = my[i][j] + has[k][col]; res2 = 0; }
						res2 += 2 * cnt[k][col];
					}
				}
	printf("%d %I64d\n", res1, res2 / 2);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxn = 505;
const int Maxm = 2 * Maxn;

int n, m, r;
int x[Maxn], ox[Maxm];
int sum[Maxn][Maxn];
int my[Maxn][Maxn];
int has[Maxn][Maxn], cnt[Maxn][Maxn];
int res1;
ll res2;

int main()
{
	scanf("%d %d %d", &n, &m, &r);
	int cur = r;
	for (int i = 0; i <= r; i++) {
		while (i * i + cur * cur > r * r) cur--;
		x[i] = cur;
	}
	for (int i = 0; i <= r + r; i++)
		for (int j = max(i - r, 0); j <= min(i, r); j++)
			ox[i] = max(ox[i], x[j] + x[i - j] + 1);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			scanf("%d", &sum[i][j]); sum[i][j] += sum[i][j - 1];
		}
	for (int i = r + 1; i <= n - r; i++)
		for (int j = r + 1; j <= m - r; j++) {
			for (int k = 0; k <= r; k++) {
				my[i][j] += sum[i - k][j + x[k]] - sum[i - k][j - x[k] - 1];
				if (k) my[i][j] += sum[i + k][j + x[k]] - sum[i + k][j - x[k] - 1];
			}
			has[i][j] = has[i][j - 1]; cnt[i][j] = cnt[i][j - 1];
			if (my[i][j] > has[i][j]) { has[i][j] = my[i][j]; cnt[i][j] = 0; }
			if (my[i][j] == has[i][j]) cnt[i][j]++;
		}
	for (int i = r + 1; i <= n - r; i++)
		for (int j = r + 1; j <= m - r; j++)
			for (int k = r + 1; k <= n - r; k++)
				if (abs(i - k) > r + r && my[i][j] + has[k][m] >= res1) {
					if (my[i][j] + has[k][m] > res1) { res1 = my[i][j] + has[k][m]; res2 = 0; }
					res2 += cnt[k][m];
				} else {
					int col = j - ox[abs(i - k)];
					if (col > r && my[i][j] + has[k][col] >= res1) {
						if (my[i][j] + has[k][col] > res1) { res1 = my[i][j] + has[k][col]; res2 = 0; }
						res2 += 2 * cnt[k][col];
					}
				}
	printf("%d %I64d\n", res1, res2 / 2);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll INF = (1LL << 55);
typedef pair<int, int> point;
#define r first
#define c second

#define SQ(x) ((x)*(x))

int N, M, R;
vector<point> circle;
int circlerow[1010];
bool plane[1010][1010];
int minrow[1010];

void get_circle()
{
  for(int i = 0; i < 1010; i++)
    for(int j = 0; j < 1010; j++)
      plane[i][j] = (SQ(i-505) + SQ(j-505) <= SQ(R));
  for(int i = 1; i < 1009; i++)
    for(int j = 1; j < 1009; j++)
    {
      if(plane[i][j] && !(plane[i+1][j] && plane[i-1][j] && plane[i][j+1] && plane[i][j-1])) circle.push_back(point(i-505, j-505));
    }

  for(int i = 0; i <= R; i++) circlerow[i] = 0;
  for(int i = 0; i < circle.size(); i++)
  {
    int r = circle[i].r, c = circle[i].c;
    if(r >= 0 && c >= 0) circlerow[r] = max(circlerow[r], c);
  }
}
bool test(int r, int c)
{
  for(int i = 0; i < circle.size(); i++)
  {
    if(SQ(circle[i].r - r) + SQ(circle[i].c - c) <= SQ(R)) return false;
  }
  return true;
}
void get_minrows()
{
  for(int r = 0; r < 1010; r++)
  {
    int low = -1, high = 1010;
    while(low + 1 < high)
    {
      int mid = (low+high)/2;
      if(test(r, mid)) high = mid;
      else low = mid;
    }
    minrow[r] = high;
  }
}

ll A[505][505];
ll sumleft[505][505]; // <---o
ll circlesum[505][505];

typedef pair<ll, ll> counter;

counter Max(counter a, counter b)
{
  if(a.first < b.first) return b;
  if(a.first > b.first) return a;
  if(a.first == b.first) return counter(a.first, a.second+b.second);
}
counter maxleft[505][505];
counter maxright[505][505];
counter numleft[505][505];

inline ll seg(int r, int cl, int cr)
{
  return sumleft[r][cr] - sumleft[r][cl-1];
}

ll get_circle_sum(int row, int col)
{
  ll total = 0;
  for(int dr = -R; dr <= R; dr++)
  {
    total += seg(row+dr, col-circlerow[abs(dr)], col+circlerow[abs(dr)]);
  }
  return total;
}

int main()
{
  cin >> N >> M >> R;
  get_circle();
  //for(int i = 0; i < circle.size(); i++) cout << circle[i].x << ' ' << circle[i].y << endl;
  //for(int i = 0; i <= 3; i++) cout << circlerow[i] << ' ';
  get_minrows();
  //for(int i = 0; i < 11; i++) cout << i << ' ' << minrow[i] << endl;
  for(int i = 1; i <= N; i++)
    for(int j = 1; j <= M; j++)
      cin >> A[i][j];
  for(int r = 1; r <= N; r++)
  {
    sumleft[r][0] = 0;
    for(int c = 1; c <= M; c++) sumleft[r][c] = sumleft[r][c-1] + A[r][c];
  }
  for(int r = 1; r <= N; r++)
    for(int c = 1; c <= M; c++)
      circlesum[r][c] = -INF;
  for(int r = R+1; r <= N-R; r++)
    for(int c = R+1; c <= M-R; c++)
      circlesum[r][c] = get_circle_sum(r, c);
  for(int r = 1; r <= N; r++)
  {
    maxleft[r][0] = counter(-INF, 1);
    for(int c = 1; c <= M; c++)
      maxleft[r][c] = Max(maxleft[r][c-1], counter(circlesum[r][c], 1));
    maxright[r][M+1] = counter(-INF, 1);
    for(int c = M; c >= 1; c--)
      maxright[r][c] = Max(maxright[r][c+1], counter(circlesum[r][c], 1));
  }
  //for(int r = 1; r <= N; r++) for(int c = 1; c <= M; c++) cout << r << ' ' << c << ' ' << maxleft[r][c].first << ' ' << maxleft[r][c].second << endl;
  //for(int r = 1; r <= N; r++) for(int c = 1; c <= M; c++) cout << r << ' ' << c << ' ' << maxright[r][c].first << ' ' << maxright[r][c].second << endl;
  counter ans = counter(-INF, 1);
  for(int r = R+1; r <= N-R; r++)
    for(int c = R+1; c <= M-R; c++)
    {
      counter best = counter(-INF, 1);
      for(int r2 = R+1; r2 <= N-R; r2++)
      {
        int dc = minrow[abs(r2-r)];
        if(dc == 0) // take whole row
        {
          best = Max(best, maxleft[r2][M]);
        }
        else
        {
          if(c-dc >= 1) best = Max(best, maxleft[r2][c-dc]);
          if(c+dc <= M) best = Max(best, maxright[r2][c+dc]);
        }
        //cout << c-dc << ' ' << c+dc << "   ";
      }
      //cout << r << ' ' << c << ' ' << circlesum[r][c] << ' ' << best.first << ' ' << best.second << endl;
      best.first += circlesum[r][c];
      ans = Max(ans, best);
    }
  if(ans.first <= 0) cout << "0 0\n";
  else cout << ans.first << ' ' << ans.second/2 << endl;
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>

typedef long long LL;
using namespace std;

const int N = 511;

int v[N][N],s[N][N],d[N],nx[N],sum[N][N],mxl[N][N],mxlc[N][N],mxr[N][N],mxrc[N][N];

int main() {
	int m,n,r;
	while(scanf("%d%d%d",&m,&n,&r)+1) {
		for(int i=1; i<=m; i++) {
			s[i][0]=0;
			for(int j=1; j<=n; j++) {
				scanf("%d",&v[i][j]);
				s[i][j]=s[i][j-1]+v[i][j];
			}
		}
		for(int i=0; i<=r; i++) {
			int j=0;
			for(; j<=r; j++)
				if(i*i+j*j>r*r)
					break;
			d[i]=j-1;
		}
		for(int i=0; i<2*r+1; i++) {
			int now=0;
			for(int j=0; j<=r&&j<=i; j++) {
				if(i-j>r) continue;
				now=max(now,d[j]+d[i-j]+1);
			}
			nx[i]=now;
		}
		for(int i=r+1; i<=m-r; i++) {
			mxl[i][r]=0;
			mxlc[i][r]=0;
			mxr[i][n-r+1]=0;
			mxrc[i][n-r+1]=0;
			for(int j=r+1; j<=n-r; j++) {
				sum[i][j]=0;
				for(int k=-r; k<=r; k++) {
					sum[i][j]+=s[i+k][j+d[abs(k)]]-s[i+k][j-d[abs(k)]-1];
				}
				if(sum[i][j]>mxl[i][j-1]) {
					mxl[i][j]=sum[i][j];
					mxlc[i][j]=1;
				} else if(sum[i][j]==mxl[i][j-1]) {
					mxl[i][j]=mxl[i][j-1];
					mxlc[i][j]=mxlc[i][j-1]+1;
				} else {
					mxl[i][j]=mxl[i][j-1];
					mxlc[i][j]=mxlc[i][j-1];
				}
			}
			for(int j=n-r; j>=r+1; j--) {
				if(sum[i][j]>mxr[i][j+1]) {
					mxr[i][j]=sum[i][j];
					mxrc[i][j]=1;
				} else if(sum[i][j]==mxr[i][j+1]) {
					mxr[i][j]=mxr[i][j+1];
					mxrc[i][j]=mxrc[i][j+1]+1;
				} else {
					mxr[i][j]=mxr[i][j+1];
					mxrc[i][j]=mxrc[i][j+1];
				}
			}
		}
		LL ret=0,rc=0;
		for(int i=r+1; i<=m-r; i++) {
			for(int j=r+1; j<=n-r; j++) {
				for(int k=r+1; k<=m-r; k++) {
					int now;
					if(abs(k-i)>2*r) {
						now=sum[i][j]+mxr[k][r+1];
						if(ret<now) {
							ret=now;
							rc=mxrc[k][r+1];
						} else if(ret==now) {
							rc+=mxrc[k][r+1];
						}
					} else {
						int y=j+nx[abs(k-i)];
						if(y<=n-r) {
							now=sum[i][j]+mxr[k][y];
							if(ret<now) {
								ret=now;
								rc=mxrc[k][y];
							} else if(ret==now) {
								rc+=mxrc[k][y];
							}
						}
						y=j-nx[abs(k-i)];
						if(y>=r+1) {
							now=sum[i][j]+mxl[k][y];
							if(ret<now) {
								ret=now;
								rc=mxlc[k][y];
							} else if(ret==now) {
								rc+=mxlc[k][y];
							}
						}
					}
				}
			}
		}
		cout<<ret<<" "<<rc/2<<endl;
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>

typedef long long LL;
using namespace std;

const int N = 511;

int v[N][N],s[N][N],d[N],nx[N],sum[N][N],mxl[N][N],mxlc[N][N],mxr[N][N],mxrc[N][N];

int main() {
	int m,n,r;
	while(scanf("%d%d%d",&m,&n,&r)+1) {
		for(int i=1; i<=m; i++) {
			s[i][0]=0;
			for(int j=1; j<=n; j++) {
				scanf("%d",&v[i][j]);
				s[i][j]=s[i][j-1]+v[i][j];
			}
		}
		for(int i=0; i<=r; i++) {
			int j=0;
			for(; j<=r; j++)
				if(i*i+j*j>r*r)
					break;
			d[i]=j-1;
		}
		for(int i=0; i<2*r+1; i++) {
			int now=0;
			for(int j=0; j<=r&&j<=i; j++) {
				if(i-j>r) continue;
				now=max(now,d[j]+d[i-j]+1);
			}
			nx[i]=now;
		}
		for(int i=r+1; i<=m-r; i++) {
			mxl[i][r]=0;
			mxlc[i][r]=0;
			mxr[i][n-r+1]=0;
			mxrc[i][n-r+1]=0;
			for(int j=r+1; j<=n-r; j++) {
				sum[i][j]=0;
				for(int k=-r; k<=r; k++) {
					sum[i][j]+=s[i+k][j+d[abs(k)]]-s[i+k][j-d[abs(k)]-1];
				}
				if(sum[i][j]>mxl[i][j-1]) {
					mxl[i][j]=sum[i][j];
					mxlc[i][j]=1;
				} else if(sum[i][j]==mxl[i][j-1]) {
					mxl[i][j]=mxl[i][j-1];
					mxlc[i][j]=mxlc[i][j-1]+1;
				} else {
					mxl[i][j]=mxl[i][j-1];
					mxlc[i][j]=mxlc[i][j-1];
				}
			}
			for(int j=n-r; j>=r+1; j--) {
				if(sum[i][j]>mxr[i][j+1]) {
					mxr[i][j]=sum[i][j];
					mxrc[i][j]=1;
				} else if(sum[i][j]==mxr[i][j+1]) {
					mxr[i][j]=mxr[i][j+1];
					mxrc[i][j]=mxrc[i][j+1]+1;
				} else {
					mxr[i][j]=mxr[i][j+1];
					mxrc[i][j]=mxrc[i][j+1];
				}
			}
		}
		LL ret=0,rc=0;
		for(int i=r+1; i<=m-r; i++) {
			for(int j=r+1; j<=n-r; j++) {
				for(int k=i; k<=m-r; k++) {
					int now;
					if(k-i>2*r) {
						now=sum[i][j]+mxr[k][1];
						if(ret<now) {
							ret=now;
							rc=mxrc[k][1];
						} else if(ret==now) {
							rc+=mxrc[k][1];
						}
					} else {
						int y=j+nx[k-i];
						if(y<=n-r) {
							now=sum[i][j]+mxr[k][y];
							if(ret<now) {
								ret=now;
								rc=mxrc[k][y];
							} else if(ret==now) {
								rc+=mxrc[k][y];
							}
						}
						if(k==i) continue;
						y=j-nx[k-i];
						if(y>=r+1) {
							now=sum[i][j]+mxl[k][y];
							if(ret<now) {
								ret=now;
								rc=mxlc[k][y];
							} else if(ret==now) {
								rc+=mxlc[k][y];
							}
						}
					}
				}
			}
		}
		cout<<ret<<" "<<rc<<endl;
	}
	return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-6;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
}

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n)
{
	pre(i,r+1);

    rep(j,r+1,m)
    {
		best=-inf;ff=0;bool mark;
		rep(d,1,n)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-5;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)
	{
		st[i1]=0;
		while(st[i1]<m&&st[i1]+1<=m&&sqr(i1-x)+sqr(st[i1]+1-y)<=sqr(2*r))st[i1]++;
	}
	/*
	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
	*/
}

int main()
{
	//freopen("p5.in","r",stdin);
    //freopen("p5.out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)if(j+d>=1&&j+d<=m)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n-r)
{
	pre(i,r+1);

    rep(j,r+1,m-r)
    {
		best=-inf;ff=0;bool mark;
		rep(d,r+1,n-r)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;

				upmin(tmp,m-r);
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-6;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
}

int main()
{
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)if(j+d>=1&&j+d<=m)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n-r)
{
	pre(i,r+1);

    rep(j,r+1,m-r)
    {
		best=-inf;ff=0;bool mark;
		rep(d,1,n)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-5;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)
	{
		st[i1]=0;
		while(st[i1]<m&&st[i1]+1<=m&&sqr(i1-x)+sqr(st[i1]+1-y)>sqr(2*r))st[i1]++;
	}
	/*
	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
	*/
}

int main()
{
	//freopen("p5.in","r",stdin);
    //freopen("p5.out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)if(j+d>=1&&j+d<=m)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n-r)
{
	pre(i,r+1);

    rep(j,r+1,m-r)
    {
		best=-inf;ff=0;bool mark;
		rep(d,r+1,n-r)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;

				upmin(tmp,m-r);
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)));
			upmin(st[i2],j1-h-1);
		}
	}
}

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)
		{
			h=int(sqrt(sqr(r)-sqr(d)));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n)
{
	pre(i,r+1);

    rep(j,r+1,m)
    {
		best=-inf;ff=0;bool mark;
		rep(d,1,n)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;
				swap(st[d],tmp);mark=1;
			}
			else mark=0;
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)));
			upmin(st[i2],max(0,j1-h-1));
		}
	}
}

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)
		{
			h=int(sqrt(sqr(r)-sqr(d)));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n)
{
	pre(i,r+1);

    rep(j,r+1,m)
    {
		best=-inf;ff=0;bool mark;
		rep(d,1,n)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;
				swap(st[d],tmp);mark=1;
			}
			else mark=0;
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)));
			upmin(st[i2],j1-h-1);
		}
	}
}

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)
		{
			h=int(sqrt(sqr(r)-sqr(d)));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=max(G[i][j-1],s[i][j]);gg[i][j]=1;
		if(s[i][j]==G[i][j-1])gg[i][j]+=gg[i][j-1];
	}

    ans=-inf;
    int best;

rep(i,r+1,n)
{
	pre(i,r+1);
    rep(j,r+1,m)
    {
		best=-inf;ff=0;
		rep(d,1,n)
		{
			if(st[d]==j&&d>i)st[d]--;

			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(st[d]==j&&d>i)st[d]++;

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-5;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
}

int main()
{
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)if(j+d>=1&&j+d<=m)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n-r)
{
	pre(i,r+1);

    rep(j,r+1,m-r)
    {
		best=-inf;ff=0;bool mark;
		rep(d,r+1,n-r)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;

				upmin(tmp,m-r);
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-6;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
}

int main()
{
    //freopen("p5.in","r",stdin);
    //freopen("p5.out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)if(j+d>=1&&j+d<=m)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n-2*r)
{
	pre(i,r+1);

    rep(j,r+1,m-2*r)
    {
		best=-inf;ff=0;bool mark;
		rep(d,1,n)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-6;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)st[i1]=m;

	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
}

int main()
{
    //freopen("p5.in","r",stdin);
    //freopen("p5.out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)if(j+d>=1&&j+d<=m)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n-r)
{
	pre(i,r+1);

    rep(j,r+1,m-r)
    {
		best=-inf;ff=0;bool mark;
		rep(d,r+1,n-r)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;

				upmin(tmp,m-r);
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
const real eps=1e-5;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

const int inf=1000000000;
int n,m,r,i,j,k,l,d,p,g,h,xx,yy,ans,tot,ff;
int a[510][510],s[510][510],sum[510][510],G[510][510],gg[510][510];
int sx[510],sy[510],st[510];

int gets(int i1,int i2,int j)
{
	if(j>m)return 0;

	if(i1<1)i1=1;
	if(i2>n)i2=n;
	return sum[i2][j]-sum[i1-1][j];
}

void pre(int x,int y)
{
	int i1,j1,i2,h;

	rep(i1,1,n)
	{
		st[i1]=-r;
		while(st[i1]<m&&st[i1]+1<=m&&sqr(i1-x)+sqr(st[i1]+1-y)>sqr(2*r))st[i1]++;
	}
	/*
	rep(i1,1,n)
	{
		rep(j1,1,m)if(sqr(i1-x)+sqr(j1-y)<=sqr(r))break;

		if(j1<=m)
		rep(i2,1,n)
		if(sqr(i1-i2)<=sqr(r))
		{
			h=int(sqrt(sqr(r)-sqr(i1-i2)+eps));
			upmin(st[i2],j1-h-1);
		}
	}
	*/
}

int main()
{
	//freopen("p5.in","r",stdin);
    //freopen("p5.out","w",stdout);
    read(n);read(m);read(r);
    rep(i,1,n)rep(j,1,m)read(a[i][j]);

    rep(i,1,n)rep(j,1,m)sum[i][j]=sum[i-1][j]+a[i][j];

    CL(s,200);
    rep(i,r+1,n-r)rep(j,r+1,m-r)
    {
		s[i][j]=0;
		rep(d,-r,r)if(j+d>=1&&j+d<=m)
		{
			h=int(sqrt(sqr(r)-sqr(d)+eps));
			s[i][j]+=gets(i-h,i+h,j+d);
		}
	}
	CL(G,200);
    rep(i,1,n)rep(j,1,m)
    {
		G[i][j]=G[i][j-1];gg[i][j]=gg[i][j-1];
		if(s[i][j]>G[i][j])G[i][j]=s[i][j],gg[i][j]=1;
		else if(s[i][j]==G[i][j])gg[i][j]++;
	}

    ans=-inf;
    int best;

rep(i,r+1,n-r)
{
	pre(i,r+1);

    rep(j,r+1,m-r)
    {
		best=-inf;ff=0;bool mark;
		rep(d,r+1,n-r)
		{
			int tmp;
			if(st[d]>=j)
			{
				if(d<i)tmp=j;else tmp=j-1;

				upmin(tmp,m-r);
				swap(st[d],tmp);mark=1;
			}
			else mark=0;

			if(st[d]>0)
			if(G[d][st[d]]>best)best=G[d][st[d]],ff=gg[d][st[d]];
			else if(G[d][st[d]]==best)ff+=gg[d][st[d]];

			if(mark)swap(st[d],tmp);

		}
		rep(d,1,n)st[d]=min(m,st[d]+1);

	//	printf("%d %d:%d\n",i,j,ff);
		if(s[i][j]+best>ans)ans=s[i][j]+best,tot=ff;
		else if(s[i][j]+best==ans)tot+=ff;
	}
}

	if(ans<0){printf("0 0\n");return 0;}

	printf("%d %d\n",ans,tot);

    scanf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t,F;
int n;
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		if(n%14<=6 && n%14!=0){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		if(k % 14 >= 1 && k % 14 <= 6 && k > 15) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		if(k % 14 >= 1 && k % 14 <= 6 && k > 12) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		if(k % 14 >= 1 && k & 14 <= 6) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		long long k;
		cin >> k;
		if(k % 14 >= 1 && k % 14 <= 6 && k > 12) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		if(k % 14 >= 1 && k % 14 <= 6) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long mod = 14LL;
void solve(){
    long long n;
    scanf("%lld",&n);
    long long y = n % mod;
    if(y > 6LL) printf("NO\n");
    else printf("YES\n");
    return ;

}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }

}


#include<bits/stdc++.h>
using namespace std;
const long long mod = 14LL;
void solve(){
    long long n;
    scanf("%lld",&n);
    long long y = n % mod;
    if(y > 6LL && n >= 15LL) printf("NO\n");
    else printf("YES\n");
    return ;

}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }

}


#include<bits/stdc++.h>
using namespace std;
const long long mod = 14LL;
void solve(){
    long long n;
    scanf("%lld",&n);
    long long y = n % mod;
    if((y > 6LL && y > 0LL) || n < 15LL) printf("NO\n");
    else printf("YES\n");
    return ;

}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }

}


#include<bits/stdc++.h>
using namespace std;
const long long mod = 14LL;
void solve(){
    long long n;
    scanf("%lld",&n);
    long long y = n % mod;
    if((y > 6LL || y < 1LL) || n < 15LL) printf("NO\n");
    else printf("YES\n");
    return ;

}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }

}


#include<bits/stdc++.h>
using namespace std;
const long long mod = 14LL;
void solve(){
    long long n;
    scanf("%lld",&n);
    long long y = n % mod;
    if(y > 6LL || n < 15LL) printf("NO\n");
    else printf("YES\n");
    return ;

}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }

}


#include<bits/stdc++.h>
using namespace std;
const long long mod = 14LL;
void solve(){
    long long n;
    scanf("%lld",&n);
    long long y = n % mod;
    if(y > 6LL && n < 15LL) printf("NO\n");
    else printf("YES\n");
    return ;

}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }

}


#include <bits/stdc++.h>
using namespace std;
int xx[] = {0,0,-1,1}, yy[] = {-1,1,0,0};
#define fo(NAME, A, B) for (long long NAME = (A); NAME < (B); ++NAME)
#define fc(NAME, A, B) for (long long NAME = (A); NAME <= (B); ++NAME)
#define endl ((char) 10)
#define size(X) ((int) (X.size()))
using ll = long long;
using ppi = pair<int, int>;
using ppl = pair<ll, ll>;

/*

*/
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T--) {
        ll x;
        cin >> x;
        ll r = x%14;
        ll n = x/14;
        if(1 <= n && 1 <= r && r <= 6) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int xx[] = {0,0,-1,1}, yy[] = {-1,1,0,0};
#define fo(NAME, A, B) for (long long NAME = (A); NAME < (B); ++NAME)
#define fc(NAME, A, B) for (long long NAME = (A); NAME <= (B); ++NAME)
#define endl ((char) 10)
#define size(X) ((int) (X.size()))
using ll = long long;
using ppi = pair<int, int>;
using ppl = pair<ll, ll>;

/*

*/
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T--) {
        int x;
        cin >> x;
        int r = x%14;
        if(1 <= r && r <= 6) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int xx[] = {0,0,-1,1}, yy[] = {-1,1,0,0};
#define fo(NAME, A, B) for (long long NAME = (A); NAME < (B); ++NAME)
#define fc(NAME, A, B) for (long long NAME = (A); NAME <= (B); ++NAME)
#define endl ((char) 10)
#define size(X) ((int) (X.size()))
using ll = long long;
using ppi = pair<int, int>;
using ppl = pair<ll, ll>;

/*

*/
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T--) {
        int x;
        cin >> x;
        bool able = false;
        fc(f,8,13) {
            if((x-f)%14) {
                able = true;
                break;
            }
        }
        cout << (able ? "YES" : "NO") << ' ';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int xx[] = {0,0,-1,1}, yy[] = {-1,1,0,0};
#define fo(NAME, A, B) for (long long NAME = (A); NAME < (B); ++NAME)
#define fc(NAME, A, B) for (long long NAME = (A); NAME <= (B); ++NAME)
#define endl ((char) 10)
#define size(X) ((int) (X.size()))
using ll = long long;
using ppi = pair<int, int>;
using ppl = pair<ll, ll>;

/*

*/
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T--) {
        ll x;
        cin >> x;
        ll r = x%14;
        if(1 <= r && r <= 6) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ul unsigned long long
int main()
{
      int t;
      cin >> t;
      while(t--)
      {
		  unsigned long long int n;
		  cin >> n;
		  //scanf("%ulld", &n);

		  int k = n%14;
		  if(k >= 1 && k<=6)
		  cout<<"YES\n";
		  else cout<<"NO\n";
		}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ul unsigned long long
int main()
{
      int t;
      cin >> t;
      while(t--)
      {
		  unsigned long long int n;
		  cin >> n;

		  unsigned long long int k = n/14;

		  k = k- 1;
		  if(n >= (ul)(k*14+15) && n<= (ul)(k*14 + 20) )
		       cout<<"YES\n";
		   else cout<<"NO\n" ;
		}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ul unsigned long long
int main()
{
      int t;
      cin >> t;
      while(t--)
      {
		  unsigned long long int n;
		  cin >> n;
		  //scanf("%ulld", &n);

		  int k = n%14;
		  if(k >= 1 && k<=6 && n>14)
		  cout<<"YES\n";
		  else cout<<"NO\n";
		}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ul unsigned long long
int main()
{
      int t;
      cin >> t;
      while(t--)
      {
		  unsigned long long int n;
		  cin >> n;

		  long long int k = n/14;

		  k = k- 1;
		  if(n >= (ul)(k*14+15) && n<= (ul)(k*14 + 20) )
		       cout<<"YES\n";
		   else cout<<"NO\n" ;
		}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ul unsigned long long
int main()
{
      int t;
      cin >> t;
      while(t--)
      {
		  unsigned long long int n;
		  cin >> n;
		  //scanf("%ulld", &n);

		  int k = n%14;
		  if(k >= 1 && k<=6 && n>15)
		  cout<<"YES\n";
		  else cout<<"NO\n";
		}

}


#include<bits/stdc++.h>
using namespace std;

 int p;

int main()
{
  int n;
  cin>>n;
  while(n--)
  {
      int  t,d=0,r=0;
      cin>>t;
      r=t%14;
      if(t<14)
      r=7;
      if(r>6)
      cout<<"NO\n";
      else
      cout<<"YES\n";

  }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

 int p;

int main()
{
  int n;
  cin>>n;
  while(n--)
  {
      int  t,d=0,r=0;
      cin>>t;
      r=t%14;
      if(r>6)
      cout<<"NO\n";
      else
      cout<<"YES\n";

  }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

 int p;

int main()
{
  int n;
  cin>>n;
  while(n--)
  {
      int  t,d=0,r=0;
      cin>>t;
      r=t%14;
      if(t<=14)
      r=7;
      if(r>6)
      cout<<"NO\n";
      else
      cout<<"YES\n";

  }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

 int p;

int main()
{
  long long n;
  cin>>n;
  while(n--)
  {
      long long  t,d=0,r=0;
      cin>>t;
      r=t%14;
      if(t<14)
      r=7;
      if(r==0)
      r=7;
      if(r>6)
      cout<<"NO\n";
      else
      cout<<"YES\n";

  }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

 int p;

int main()
{
  int n;
  cin>>n;
  while(n--)
  {
      int  t,d=0,r=0;
      cin>>t;
      r=t%14;
      if(t<14)
      r=7;
      if(r==0)
      r=7;
      if(r>6)
      cout<<"NO\n";
      else
      cout<<"YES\n";

  }

    return 0;
}