1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include "message.h"
#include "dzialka.h"

using namespace std;

const int N_MAX = 3500;//75000;
const int M_MAX = 3500;//75000;

int T[N_MAX+1][M_MAX+1];
int S[N_MAX+1][M_MAX+1];
/*
int GetFieldHeight() {
	int n;
	scanf("%d", &n);
	return n;
}

int GetFieldWidth() {
	int m;
	scanf("%d", &m);
	return m;
}

int IsUsableCell(int r, int c) {
	int x;
	scanf("%d", &x);
	return x;
}*/

int IsUsable(int x1, int y1, int x2, int y2) {
	int sum = S[x2][y2] - S[x1-1][y2] - S[x2][y1 - 1] + S[x1 - 1][y1 - 1];
	return sum == (x2 - x1 + 1) * (y2 - y1 + 1);
}

int main() {
	if (MyNodeId() != 0) return 0;
	int n = GetFieldHeight();
	int m = GetFieldWidth();
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			T[i][j] = IsUsableCell(i-1, j-1);
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + T[i][j];
		}
	}
	long long int result = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			for (int k = i; k <= n; ++k) {
				if(!IsUsable(i, j, k, j)) break;
				for (int l = j; l <= m && IsUsable(i, j, k, l); ++l) {
					result++;
				}
			}
		}
	}
	printf("%lld\n", result);
	return 0;
}