#include <bits/stdc++.h>
#define ll unsigned int//long long
#define INF 999999999
#define N (1<<17)
#define M 1000000007
#define C 250000
using namespace std;
ll ans = 0;
ll v[50][50];
ll m[50][50][250000];
ll m2[50][50][250000];
const inline ll sum (const ll x1, const ll x2, const ll y1, const ll y2) {
ll s = v[y2][x2];
if (x1) s -= v[y2][x1-1];
if (y1) s -= v[y1-1][x2];
if (x1 && y1) s += v[y1-1][x1-1];
return s;
}
int main () {
cin.sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
for (int y = 0; y < n; y++) {
for (int x = 0; x <n; x++) {
cin>>v[y][x];
if (x) v[y][x] += v[y][x - 1];
}
}
for(int y = 1; y < n; y++) {
for (int x = 0; x < n; x++) {
v[y][x] += v[y - 1][x];
}
}
for (ll y = 0; y < n; y++) {
for (ll x = 0; x <n; x++) {
for (ll y1 = 0; y1 <= y; y1++) {
for (ll x1 = 0; x1 <= x; x1++) {
m[x1][y1][sum(x1, x, y1, y)) % C]++;
m2[x1][y + 1][sum(x1, x, y1, y)) % C]++;
ans += m[x + 1][y + 1][sum(x1, x, y1, y)) % C];
ans += m2[x + 1][y1][sum(x1, x, y1, y)) % C];
}
}
}
}
cout<<ans<<endl;
}