Skyline Construction#8645

Skyline Construction

1 sekunda
128 megabajtov
Lahko

A modern metropolis is planning a major downtown reconstruction. The city has an exceptional construction system: when construction crews add floors to a building, the building grows by exactly that many floors. In other words, if a building has floors and you add floors to it, the building will have h + x floors.

The downtown area is organized as an n \times m grid, where each cell contains one skyscraper. The construction system has n + m tower cranes: one crane for each row and one for each column. Each construction operation uses one crane to add the same number of floors to all buildings along its row or column.

The city planner wants to transform the downtown skyline by performing construction operations. For each building, you know its current height (number of floors) and the desired height. Your task is to find a sequence of construction operations that transforms the skyline to match the desired configuration.

Vhod

The first line contains two integers and (1 \le n, m \le 1000) — the dimensions of the city grid.

Then lines follow, each containing integers a_{i,j} (1 \le a_{i,j} \le 10^9) — the current number of floors in each building.

Then more lines follow, each containing integers b_{i,j} (1 \le b_{i,j} \le 10^9) — the desired number of floors in each building.

Izhod

The first line should contain the number of operations (0 \le k \le 10^6), followed by lines describing the operations:

  • "" — Add floors to all buildings in row (1 \le r \le n, 1 \le x \le 10^9).

  • "" — Add floors to all buildings in column (1 \le c \le m, 1 \le x \le 10^9).

If it is impossible to transform the skyline to the desired configuration, output .

Primeri

Primer 1

Loading
Loading

Primer 2

Loading
Loading

Primer 3

Loading
Loading

Opomba

You don't need to minimize the number of operations, just ensure it doesn't exceed 10^6.