Rectangular Country
Limits: 2 sec., 256 MiB
President P is trying hard to sort the things out in his country. However he can not do it because of intelectual capability limitations. Thus he came up with a neat plan of simplifying the country. In particular the country now has a rectangular shape on the world map.
Unfortunately it didn’t help much as the president was still suffering from a lack of intelect. Then prime minister Y decided to move further and and simplify each country region in the same manner. In order to make rectangular country regions he needs to count regions which are not yet rectangles on the map. Could you help prime minister?
Input
The first line contains to integers separated by a single space N and M which are the height and the width of the contry on the world map. Each of the following N lines contains M integers separated by single spaces. Each integer denotes a region identifier the given country unit belongs to.
Output
Print the number of country regions which are not rectangles on the map.
Constraints
\(1 \le \mathbf{N}, \mathbf{M} \le 1000\),
country region identifiers are integers between 1 and 1000000, inclusive.
Samples
Input (stdin) | Output (stdout) |
---|---|
3 3 1 1 1 4 3 2 3 3 2 | 1 |
Submit a solution
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|