#include<iostream>
#include<algorithm>
#define re register
using namespace std;
int n,cnt_1,cnt_2;
char str[1010][1010];
int main(){
scanf("%d",&n);
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++) cin>>str[i][j];
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++)
if(str[i][j]=='1'){
if(str[i-1][j-1]=='1'&&str[i-1][j+1]=='1'&&str[i+1][j-1]=='1'&&str[i+1][j+1]=='1') cnt_1++;
else break;
}
for(re int i=1;i<=n;i++)
for(re int j=1;j<=n;j++)
if(str[i][j]=='1'&&str[i+1][j]=='1'&&str[i][j+1]=='1'&&str[i+1][j+1]=='1'){
if(str[i-1][j-1]=='1'&&str[i+2][j-1]=='1'&&str[i-1][j+2]=='1'&&str[i+2][j+2]=='1') cnt_2++;
else break;
}
printf("%d",cnt_1+cnt_2);
return 0;
}