#include <iostream>
using namespace std;
void GiveValue(int L,int **Vessel,int **Same);
void Turn(int L,int **Vessel,int **Same);
bool Judge(int L,int **Vessel);
int main(){
int **Vessel,**Same,m=0,L;
cin>>L;
Vessel=new int*[L];
for (int i=0;i<L;i++)
Vessel[i]=new int[L];
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
cin>>Vessel[i][j]; }}
Same=new int*[L];
for (int i=0;i<L;i++)
Same[i]=new int[L];
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
Same[i][j]=0; }
}
GiveValue(L,Vessel,Same);
do
{Turn(L,Vessel,Same);
GiveValue(L,Vessel,Same);
m+=1;}
while (Judge(L,Vessel));
return m;
for(int i=0;i<L;i++){
delete[]Vessel[i];
}
delete[]Vessel;}
void GiveValue(int L,int **Vessel,int **Same){
for (int i=0;i<L;i++){
for (int j=0;j<L;j++) {
Same[i][j]=Vessel[i][j]; }
}
}
void Turn(int L,int **Vessel,int **Same){
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
if (Vessel[i][j]==0){
if ((Vessel[i-1][j]==1)||(Vessel[i+1][j]==1)||(Vessel[i][j-1]==1)||(Vessel[i][j+1]==1)) Same[i][j]=1; }
}
}
}
bool Judge(int L,int **Vessel){
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
if (Vessel[i][j]==0){
return true;
break; }
}
}
return false;}
using namespace std;
void GiveValue(int L,int **Vessel,int **Same);
void Turn(int L,int **Vessel,int **Same);
bool Judge(int L,int **Vessel);
int main(){
int **Vessel,**Same,m=0,L;
cin>>L;
Vessel=new int*[L];
for (int i=0;i<L;i++)
Vessel[i]=new int[L];
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
cin>>Vessel[i][j]; }}
Same=new int*[L];
for (int i=0;i<L;i++)
Same[i]=new int[L];
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
Same[i][j]=0; }
}
GiveValue(L,Vessel,Same);
do
{Turn(L,Vessel,Same);
GiveValue(L,Vessel,Same);
m+=1;}
while (Judge(L,Vessel));
return m;
for(int i=0;i<L;i++){
delete[]Vessel[i];
}
delete[]Vessel;}
void GiveValue(int L,int **Vessel,int **Same){
for (int i=0;i<L;i++){
for (int j=0;j<L;j++) {
Same[i][j]=Vessel[i][j]; }
}
}
void Turn(int L,int **Vessel,int **Same){
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
if (Vessel[i][j]==0){
if ((Vessel[i-1][j]==1)||(Vessel[i+1][j]==1)||(Vessel[i][j-1]==1)||(Vessel[i][j+1]==1)) Same[i][j]=1; }
}
}
}
bool Judge(int L,int **Vessel){
for (int i=0;i<L;i++){
for (int j=0;j<L;j++){
if (Vessel[i][j]==0){
return true;
break; }
}
}
return false;}
