#P10456. The Pilots Brothers: Following the Stripy Elephant - Refrigerator Quest

    ID: 12466 Type: Default 1000ms 256MiB

The Pilots Brothers: Following the Stripy Elephant - Refrigerator Quest

The Pilots Brothers: Following the Stripy Elephant - Refrigerator Quest

There is a 4x4 matrix representing 16 handles on a refrigerator. Each handle can be in one of two states: open (1) or closed (0). The refrigerator is considered open only when all handles are in the open state. You may flip a handle at any position \( [i, j] \) (with \( 1 \leq i, j \leq 4 \)). However, flipping the handle toggles the states of every handle in row \( i \) or column \( j \) (each affected exactly once), including the chosen handle.

The effect of a move at position \( (i, j) \) is as follows: for every cell \( (x, y) \) in the grid, if \( x = i \) or \( y = j \), then the state of \( (x, y) \) is toggled (that is, changed from 0 to 1 or from 1 to 0).

Your task is to determine the minimum number of handle flips required to open the refrigerator (i.e. to make all handles 1).

inputFormat

The input consists of 4 lines. Each line contains 4 space-separated integers. Each integer is 0 or 1 representing a handle (0 for closed, 1 for open).

outputFormat

Output a single integer: the minimum number of moves required to open the refrigerator.

sample

1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
0