#include <stdio.h>
void answer(int count) {
}
#define Y_SIZE (300)
#define X_SIZE (300)
int H; // ホーム画面縦の区画数
int W; // ホーム画面横の区画数
int array[Y_SIZE][X_SIZE]; // ホーム画面の配置
int vert_len[Y_SIZE][X_SIZE]; // 縦方向の区画の長さ
int hori_len[Y_SIZE][X_SIZE]; // 横方向の区画の長さ
int cache[Y_SIZE][X_SIZE]; // 答えのキャッシュ
int resolve_hori(S, T)
int S; // ウィジェットの縦サイズ
int T; // ウィジェットの横サイズ
{
int count, len;
int x, y;
count = 0;
for (y = 0; y <= H - S; y++) {
for (x = 0; x < W;) {
if (hori_len[y][x] >= T) {
for (len = 0; vert_len[y][x + len] >= S && len < hori_len[y][x]; len++);
if (len >= T) {
count += len - T + 1;
}
x += len + 1;
} else if (hori_len[y][x] >= 0) {
x += hori_len[y][x] + 1;
} else {
x -= hori_len[y][x];
}
}
}
return count;
}
int resolve_vert(S, T)
int S; // ウィジェットの縦サイズ
int T; // ウィジェットの横サイズ
{
int count, len;
int x, y;
count = 0;
for (x = 0; x <= W - T; x++) {
for (y = 0; y < H;) {
if (vert_len[y][x] >= S) {
for (len = 0; hori_len[y + len][x] >= T && len < vert_len[y][x]; len++);
if (len >= S) {
count += len - S + 1;
}
y += len + 1;
} else if (vert_len[y][x] >= 0) {
y += vert_len[y][x] + 1;
} else {
y -= vert_len[y][x];
}
}
}
return count;
}
void resolve(S, T)
int S; // ウィジェットの縦サイズ
int T; // ウィジェットの横サイズ
{
if (cache[S - 1][T - 1] < 0) {
if (S < T) {
cache[S - 1][T - 1] = resolve_hori(S, T);
} else {
cache[S - 1][T - 1] = resolve_vert(S, T);
}
}
answer(cache[S - 1][T - 1]);
}
int main(void) {
char str[305];
int N, s, t;
int x, y, i;
int len;
for (y = 0; y < H; y++) {
for (x = 0; x < W; x++) {
array[y][x] = (int)(str[x] - '0');
}
}
for (x = 0; x < W; x++) {
len = 0;
for (y = H - 1; y >= 0; y--) {
if (array[y][x]) {
if (len > 0) {
len = 0;
}
len--;
} else {
if (len < 0) {
len = 0;
}
len++;
}
vert_len[y][x] = len;
}
}
for (y = 0; y < H; y++) {
len = 0;
for (x = W - 1; x >= 0; x--) {
if (array[y][x]) {
if (len > 0) {
len = 0;
}
len--;
} else {
if (len < 0) {
len = 0;
}
len++;
}
hori_len[y][x] = len;
}
}
for (y = 0; y < H; y++) {
for (x = 0; x < W; x++) {
cache[y][x] = -1;
}
}
for (i = 0; i < N; i++) {
resolve(s, t);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIGFuc3dlcihpbnQgY291bnQpIHsKCXByaW50ZigiJWRcbiIsIGNvdW50KTsKfQoKI2RlZmluZSBZX1NJWkUgKDMwMCkKI2RlZmluZSBYX1NJWkUgKDMwMCkKCmludCBIOyAvLyDjg5vjg7zjg6DnlLvpnaLnuKbjga7ljLrnlLvmlbAKaW50IFc7IC8vIOODm+ODvOODoOeUu+mdouaoquOBruWMuueUu+aVsAppbnQgYXJyYXlbWV9TSVpFXVtYX1NJWkVdOyAvLyDjg5vjg7zjg6DnlLvpnaLjga7phY3nva4KaW50IHZlcnRfbGVuW1lfU0laRV1bWF9TSVpFXTsgLy8g57im5pa55ZCR44Gu5Yy655S744Gu6ZW344GVCmludCBob3JpX2xlbltZX1NJWkVdW1hfU0laRV07IC8vIOaoquaWueWQkeOBruWMuueUu+OBrumVt+OBlQppbnQgY2FjaGVbWV9TSVpFXVtYX1NJWkVdOyAvLyDnrZTjgYjjga7jgq3jg6Pjg4Pjgrfjg6UKCmludCByZXNvbHZlX2hvcmkoUywgVCkKCWludCBTOyAvLyDjgqbjgqPjgrjjgqfjg4Pjg4jjga7nuKbjgrXjgqTjgroKCWludCBUOyAvLyDjgqbjgqPjgrjjgqfjg4Pjg4jjga7mqKrjgrXjgqTjgroKewoJaW50IGNvdW50LCBsZW47CglpbnQgeCwgeTsKCQoJY291bnQgPSAwOwoJZm9yICh5ID0gMDsgeSA8PSBIIC0gUzsgeSsrKSB7CgkJZ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