#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int ys[100][100];
int hb[100][100],hb1[100][100];
int a[100][100];
int ans;
int main(){
cin >> n >> m >> k;
for (int i=1;i<=m;i++){
for (int j=1;j<=m;j++){
a[i][j]=1;
}
}
for (int i=1;i<=m;i++){
for (int j=1;j<=m;j++){
cin >> hb[i][j];
hb1[i][j]=1;
}
}
for (int i=1;i<=k;i++){
for (int j=1;j<=k;j++){
cin >> ys[i][j];
}
}
for (int i=1;i<=m;i++){
for (int j=1;j<=m;j++){
if (hb1[i][j]==1){
a[i-1][j-1]=1;
a[i-1][j+1]=1;
a[i+1][j-1]=1;
a[i+1][j+1]=1;
a[i][j]=1;
a[i-1][j]=1;
a[i-2][j]=1;
a[i][j-1]=1;
a[i][j-2]=1;
a[i][j+1]=1;
a[i][j+2]=1;
a[i+1][j]=1;
a[i+2][j]=1;
}
}
}
ans=n*n;
for (int i=1;i<=m;i++){
for (int j=1;j<=m;j++){
if (a[i][j]==1) ans--;
}
}
cout << ans << endl;
}