An urban myth says that Peter the Great wanted a rectangular grid of channels on Kotlin island, where the town of Kronstadt stands today, like the one on Vasilyevskiy island.
Engineers (allegedly) brought the tsar this mathematical model. The island is a rectangular grid h cells high and w cells wide, and every cell is dry land at the start. The technology of the day allowed them to dig a channel across the whole island, and one dig turns an entire row or an entire column into water. A cell that is already water stays water.
Two dry cells are joined when they share a side. A connected component is a maximal set of dry cells linked by such steps. Propose a plan of the island whose dry land has exactly n connected components.