#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
short int a[1010][1010],n,ans;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&a[i][j]);
if(a[i][j]==0) a[i][j]=-100;
}
}
for(int i=1,x,y;i<=5;i++){
scanf("%d%d",&x,&y);
a[x][y]-=2;
if(x-1>=1)a[x-1][y]--;
if(x+1<=n)a[x+1][y]--;
if(y-1>=1)a[x][y-1]--;
if(y+1<=n)a[x][y+1]--;
if(x-1>=1&&y-1>=1)a[x-1][y-1]--;
if(x+1<=n&&y+1<=n)a[x+1][y+1]--;
if(x-1>=1&&y+1<=n)a[x-1][y+1]--;
if(x+1<=n&&y-1>=1)a[x+1][y-1]--;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]<=0&&a[i][j]>-100){
ans++;
}
}
}
printf("%d\n",ans);
return 0;
}