#include <bits/stdc++.h>
#define ll short//long long
#define INF 999999999
#define N (1<<17)
#define M 1000000007
#define C 12133
using namespace std;
ll ans = 0;
ll v[52][52];
ll m[52][52][C];
unordered_map<ll, int> e;
vector<ll> foo;
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 () {
srand(time(0));
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];
//v[y][x] = 1;
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++) {
ll s = sum(x1, x, y1, y);
if (!e[s]) e[s] = 1, foo.push_back(s);
}
}
}
}
random_shuffle(foo.begin(), foo.end());
for (int i = 0; i < foo.size(); i++) e[foo[i]] = i;
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++) {
ll s = e[sum(x1, x, y1, y)] % C;
m[y1][x1][s]++;
}
}
}
}
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++) {
ll s = e[sum(x1, x, y1, y)] % C;
ans += m[y + 1][x + 1][s];
}
}
}
}
m.clear();
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++) {
ll s = e[sum(x1, x, y1, y)] % C;
m[y + 1][x1][s]++;
}
}
}
}
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++) {
ll s = e[sum(x1, x, y1, y)] % C;
ans += m[y1][x + 1][s];
}
}
}
}
cout<<ans<<endl;
}