P2040 Turn On All the Lights

Background

pmshz is playing a small puzzle game (yì zhì; jokingly "ruò zhì"). The goal is to turn on all nine lights. This game has stumped pmshz.

Description

These lights behave in a peculiar (annoying) way: pressing a light will flip the on/off state of that light and its four neighboring lights. Your task is to tell pmshz how to turn all the lights on. For example ```plain 0 1 1 1 0 0 1 0 1 ``` Pressing the center light $(2,2)$ becomes ```plain 0 0 1 0 1 1 1 1 1 ``` Pressing the top-left light $(1,1)$ becomes ```plain 1 1 1 1 1 1 1 1 1 ``` Goal achieved. The minimum number of steps is $2$.

Input Format

$9$ numbers given in a $3\times3$ layout, with exactly one space between adjacent numbers, representing the initial on/off state of the lights ($0$ means off, $1$ means on).

Output Format

A single integer, the minimum number of presses required to turn on all the lights.

Explanation/Hint

How easy this problem is depends on how you think about it. Translated by ChatGPT 5