/*
#include <stdio.h>
int m, n, c1=0, c0=0;
int a[101][101]= {};
int b[101][101]= {};
typedef struct
{
int x;
int y;
} grid;
grid queue[10000];
int f=-1, r=-1;
void enq(int x, int y)
{
if(x<1||x>m||y<1||y>n)
return;
a[x][y]=!a[x][y];
r++;
queue[r].x=x;
queue[r].y=y;
}
{
f++;
return queue[f];
}
void copy()
{
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
a[i][j]=b[i][j];
}
}
void bfs(int x, int y, int color)
{
enq(x,y);
while(f!=r)
{
grid g = deq();
x=g.x;
y=g.y;
if(a[x][y+1]==color)
{
enq(x,y+1);
}
if(a[x][y-1]==color)
{
enq(x,y-1);
}
if(a[x+1][y]==color)
{
enq(x+1,y);
}
if(a[x-1][y]==color)
{
enq(x-1,y);
}
}
}
int main()
{
scanf("%d %d", &m, &n);
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%d", &a[i][j]);
b[i][j] = a[i][j];
}
}
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
{
if(a[i][j]==1)
{
bfs(i, j, 1);
c1++;
}
}
}
f=-1; r=-1;
copy();
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
{
if(a[i][j]==0)
{
bfs(i, j, 0);
c0++;
}
}
}
if(c0<c1) printf("%d\n", c0);
else printf("%d", c1);
}
*/
#include <stdio.h>
int n;
int a[26][26]={};
spot q[625][625]={];
typedef struct
{
int x;
int y;
}spot;
void enq(int x, int y)
{
if(x<1||x>n||y<1||y>n)
return;
r++;
queue[r].x=x;
queue[r].y=y;
}
void bfs(int x, int y)
{
enq(x,y);
while(f!=r)
{
spot t = deq();
x=t.x;
y=t.y;
if(a[x][y+1]==0)
{
enq(x,y+1);
}
if(a[x][y-1]==0)
{
enq(x,y-1);
}
if(a[x+1][y]==0)
{
enq(x+1,y);
}
if(a[x-1][y]==0)
{
enq(x-1,y);
}
}
}
int main()
{
spot g1, h1, g2, h2; //고돌이 고소미 위치, 고돌이 고소미 집
scanf("%d", &n);
scanf("%d %d %d %d %d %d %d %d", &g1.x, &g1.y, &h1.x, &h1.y, &g2.x, &g2.y, &h2.x, &h2.y);
for(int i=1; i<=n, i++)
{
for(int j=1; j<=n; j++)
scanf("%d", &a[i][j]);
}
}