logo AlgoBeat OnlineJudge
登录 注册

#215768. [JAG 2023 Summer Camp #2] Fraises dans une boîte

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

A box is divided into grids with rows and columns. Some squares contain strawberries.

The state of the box is denoted by , and means that the square in the -th row and -th column contains one strawberry. If , the square in the -th row and -th column is empty.

Tomoe devised the following method to distinguish between these strawberries.

  • Let be defined as the sum of for all integer pairs satisfying .
  • Let be defined as the sum of for all integer pairs satisfying .
  • If the square in the -th row and -th column contains a strawberry, label the strawberry with the tuple .

This method could result in multiple strawberries having the same label, and the strawberries could not be distinguished. Therefore, she decided to add some strawberries before labeling them.

More formally, for such that , we operated any number of times greater than .

What is the minimum number of strawberries that must be added to label all the strawberries differently?

输入格式

The input satisfies the following constraints.

  • All inputs consist of integers.

输出格式

Output the answer in one line. Add a new line at the end of the output.

样例

样例输入 1

3 2
1 0
0 1
0 1

样例输出 1

1

样例输入 2

4 4
0 1 1 1
1 1 1 0
1 0 1 1
1 0 1 0

样例输出 2

2

样例输入 3

5 5
0 0 1 0 1
0 1 0 1 0
0 0 1 0 1
0 1 0 1 0
0 0 1 0 1

样例输出 3

8

样例输入 4

1 1
0

样例输出 4

0

数据范围与提示

In Sample Input 1, Tomoe can achieve the condition by placing a strawberry in the upper right square.