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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//#include "stdafx.h"
#include "dzialka.h"
#include "message.h"

#include <cassert>
#include <iostream>
#include <istream>
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <cstdlib>
#include <memory>
#include <ctime>
#include <bitset>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
using namespace std;

int height;
int width;
unsigned long long cnt;

int **tab;
int **linesH;

void calcLines() {
	for (int r = 0; r < height; r++) {
		int curr = 0;
		for (int c = width - 1; c >= 0; c--) {
			if (tab[r][c] == 0) {
				curr = 0;
			}
			else {
				curr++;
			}
			linesH[r][c] = curr;
		}
	}
}

//begin
unsigned long long calc2(int r, int c) {
	unsigned long long sum = 0;
	unsigned long long szer = 75001;
	int wys = 0;
	for (int i = r; i < height; i++) {
		wys++;

		unsigned long long w = linesH[i][c];
		szer = std::min(szer, w);

		if (szer == 0) {
			break;
		}

		unsigned long long add = szer;
		sum += add;
	}
	return sum;
}

void readFinal() {

	height = GetFieldHeight();
	width = GetFieldWidth();

	//setup
	tab = new int*[height];
	for (int i = 0; i < height; ++i) {
		tab[i] = new int[width];
	}

	//prepare
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			int val = IsUsableCell(i, j) ? 1 : 0;
			tab[i][j] = val;
		}
	}
}

void readTemp() {
	cin >> width >> height;
	string str;
	//setup
	tab = new int*[height];
	for (int i = 0; i < height; ++i) {
		tab[i] = new int[width];
	}

	char sign;

	for (int r = 0; r < height; r++) {
		cin >> str;

		for (int c = 0; c < width; c++) {
			if (str[c] == '0') {
				tab[r][c] = 0;
			}
			else {
				tab[r][c] = 1;
			}
		}
	}	
}

int main()
{
	if (MyNodeId() > 0)
		return 0;

	readFinal();
	//readTemp();

	linesH = new int*[height];
	for (int i = 0; i < height; ++i) {
		linesH[i] = new int[width];
	}

	calcLines();

	cnt = 0;
	for (int r1 = 0; r1 < height; r1++) {
		for (int c1 = 0; c1 < width; c1++) {
			if (tab[r1][c1] == 0) continue;
			unsigned long long sum = calc2(r1, c1);
			cnt += sum;

		}
	}

	//clean up
	for (int i = 0; i < height; ++i) {
		delete[] tab[i];
	}
	delete[] tab;

	for (int i = 0; i < height; ++i) {
		delete[] linesH[i];
	}
	delete[] linesH;
	
	cout << cnt << endl;

	return 0;
}