#include<cstdio>
using namespace std;
const int N=1005;
int n,a[N][N];
bool st[N][N];
bool high,low;
int dx[8]={0,-1,0,1,1,1,-1,-1},dy[8]={-1,0,1,0,1,-1,1,-1};
bool check(int x,int y){
if(x<1||x>n||y<1||y>n) return false;
return true;
}
void dfs(int x,int y){
if(st[x][y]==1) return;
st[x][y]=1;
for(int i=0;i<8;i++){
int xx=x+dx[i],yy=y+dy[i];
if(check(xx,yy)){
if(a[xx][yy]>a[x][y]) high=1;
else if(a[xx][yy]<a[x][y]) low=1;
if(!st[xx][yy]&&a[xx][yy]==a[x][y]) dfs(xx,yy);
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&a[i][j]);
}
}
int sg=0,sf=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(!st[i][j]){
high=0,low=0;
dfs(i,j);
if(high==1&&low==0) sg++;
else if(high==0&&low==1) sf++;
else if(high==0&&low==0) sg++,sf++;
}
}
}
printf("%d %d",sf,sg);
return 0;
}