PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000234. Đếm hình chữ nhật toàn số 0 (Count All-Zero Rectangles)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm hình chữ nhật toàn số 0 (Count All-Zero Rectangles)

Count All-Zero Rectangles

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an n×mn\times m binary matrix, count nonempty axis-aligned subrectangles consisting entirely of zeros. Rectangles with different boundaries are distinct.

Input

The first line contains n,mn,m, followed by nn rows of mm space-separated binary integers.

Output

Print the number of all-zero rectangles.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤81\le n,m\le 8; ai,j∈{0,1}a_{i,j}\in\{0,1\}.
  • Subtask 2 (30 points): 1≤n,m≤601\le n,m\le 60; ai,j∈{0,1}a_{i,j}\in\{0,1\}; all cells are zero.
  • Subtask 3 (50 points): 1≤n,m≤601\le n,m\le 60; ai,j∈{0,1}a_{i,j}\in\{0,1\}.

Example 1

Input

2 3
0 0 1
0 0 0

Output

12

Explanation

There are five single cells, three horizontal length-two segments, one horizontal length-three segment, two vertical length-two segments and one 2-by-2 rectangle.

Example 2

Input

1 2
1 1

Output

0

Explanation

There is no zero cell.