QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 512 MB Puntuación total: 100

#17796. Filling with Z-shape

Estadísticas

There is an $m \times n$ grid, with coordinates starting from 0. Initially, every cell is filled with $-1$.

An operation consists of selecting a "Z-shape" region (as shown in the image, which can be rotated and flipped) and changing the sign of the numbers in those cells.

Given $m$ and $n$, determine if there exists a sequence of operations that changes all numbers in the grid to $1$.

If no such sequence of operations exists, output Impossible!.

Z-shape and its rotations/flips

Input

The input contains two integers $m, n$ ($2 \le m, n \le 2 \times 10^5$, $4 \le mn \le 2 \times 10^5$), representing the number of rows and columns of the grid.

Output

If a solution exists, output the sequence of operations: the first line should contain the number of operations $r$ ($0 \le r \le 10^6$), followed by $r$ lines, each containing 8 integers representing the coordinates of the four cells of the "Z-shape" (in the order $x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4$, where the order of the four points is arbitrary). If no solution exists, output Impossible!. If there are multiple solutions, any one is acceptable.

It can be proven that if a valid solution exists, there must exist a valid solution such that $0 \le r \le 10^6$.

Examples

Input 1

2 4

Output 1

4
0 0 0 1 1 1 1 2
1 0 1 1 0 1 0 2
1 3 0 1 1 2 0 2
1 1 1 2 0 2 0 3

Input 2

2 5

Output 2

Impossible!

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.