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

#BS0000107. Diện tích hình chữ nhật bao trọn các điểm đen (Smallest Rectangle Enclosing Black Pixels)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Diện tích hình chữ nhật bao trọn các điểm đen (Smallest Rectangle Enclosing Black Pixels)

Smallest Rectangle Enclosing Black Pixels

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an m×nm\times n image of 0 (white) and 1 (black) pixels, all black pixels are four-neighbor connected. A known black pixel has zero-based coordinate (x,y)(x,y). Return the area (number of grid cells) of the smallest axis-aligned rectangle that contains every black pixel.

Input

The first line contains m,n,x,ym,n,x,y. Each of the next mm lines is a string of exactly nn characters 0 or 1.

Output

Print one integer, the area of the smallest rectangle containing every black pixel.

Subtasks

  • Subtask 1 (20 points): 1≤m,n≤101\le m,n\le 10; 0≤x<m0\le x<m, 0≤y<n0\le y<n; each image entry is 0 or 1, the chosen pixel is black, and all black pixels are four-neighbor connected.
  • Subtask 2 (30 points): 1≤m,n≤301\le m,n\le 30; 0≤x<m0\le x<m, 0≤y<n0\le y<n; each image entry is 0 or 1, the chosen pixel is black, and all black pixels are four-neighbor connected.
  • Subtask 3 (50 points): 1≤m,n≤1001\le m,n\le 100; 0≤x<m0\le x<m, 0≤y<n0\le y<n; each image entry is 0 or 1, the chosen pixel is black, and all black pixels are four-neighbor connected.

Examples

Input

3 4 0 2
0010
0110
0100

Output

6

Explanation

The black coordinates are (0,2),(1,1),(1,2),(2,1)(0,2),(1,1),(1,2),(2,1). The topmost and bottommost rows are 0,20,2, giving height 33. The leftmost and rightmost columns are 1,21,2, giving width 22. The minimal bounding rectangle has area 3⋅2=63\cdot2=6.