#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int n,m,ans=0;
int a[101][101];
char b[101][101];
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
if(b[i][j]=='@'){
a[i][j]=1;
ans++;
}
}
}
cin>>m;
for(int t=1;t<m;t++)
for(int i=1;i<n;i++)
for(int j=1;j<n;j++)
if(a[i][j]=t)
for(int y=0;y<=2;y+=2){
if(b[i-1+y][j]=='*'){
ans++;
b[i-1+y][j]=='@';
a[i-1+y][j]==t+1;
if(b[i-1+y][j]=='*'){
ans++;
b[i][j-1+y]=='@';
a[i][j-1+y]==t+1;
}
}
}
cout<<ans;
return 0;
}