karte (COCI CONTEST_#3)
Time limit: 1 seconds | Memory limit: 512 MB | Task type: batch
Algorithms: enumeration

![](_page_0_Picture_0.jpeg)

# Task Karte

On Vito's table, there are *N* red cards labeled with numbers from 1 to *N* and *M* blue cards labeled with numbers from 1 to *M*. Each pair of red and blue cards (*c, p*) (where *c* represents a red card and *p* a blue card) can create a *COMBO* move.

The strength of a deck of cards is defined as:

*strength* = (*number of COMBO moves*) − *X* · (*number of red cards*) − *Y* · (*number of blue cards*)

where the *number of COMBO moves* is the number of pairs (*c, p*) such that the red card *c* and the blue card *p* are in the chosen deck. Vito can include any card from the table in his deck. Help Vito find the value of the strongest deck he can build. Vito can also choose an empty deck of cards.

## Input Data

The first line contains 4 natural numbers *N, M, X, Y* (1 ≤ *N, M* ≤ 21, 0 ≤ *X, Y* ≤ 30).

In the next *N* lines, there is a sequence of *M* characters (0 or 1), where the *j*-th character indicates whether the *i*-th red card and the *j*-th blue card create a *COMBO* move.

## Output Data

In the first and only line, output the value of the strongest deck of cards that Vito can build.

## Scoring

| Subtask | Points | Constraints                |
|---------|--------|----------------------------|
| 1       | 18     | Y = 0                      |
| 2       | 11     | 1 ≤ N, M ≤ 9               |
| 3       | 24     | 1 ≤ N, M ≤ 15              |
| 4       | 17     | No additional constraints. |

## Sample Cases

| input               | input                        | input                        |
|---------------------|------------------------------|------------------------------|
| 2 2 0 0<br>11<br>10 | 3 3 1 0<br>111<br>111<br>000 | 3 3 1 1<br>111<br>101<br>011 |
| output              | output                       | output                       |
| 3                   | 4                            | 1                            |

Explanation of the first sample case: Vito will choose all the cards from the table, creating 3 COMBO moves.

Explanation of the second sample case: Vito will select the first 2 red cards and all 3 blue cards, creating 6 COMBO moves. The deck strength is 4 because Vito selected 2 red cards, so the number of COMBO moves, i.e., 6, is reduced by 2.

Starter code:

Grader code:

Setup script:

Evaluation script: