Public Judge

pjudge

時間限制: 1 s 記憶體限制: 2048 MB 總分: 100

#21866. Red, Orange, Yellow, Green

统计

Given an $N \times M$ chessboard, initially, all positions on the board are empty.

Not a Little Blue Fish wants to perform several operations. Each operation is as follows:

  1. Choose an empty cell $(i, j)$.
  2. Let $x$ be the smallest positive integer that has not yet appeared in the row or column containing $(i, j)$.
  3. Fill the cell $(i, j)$ with the number $x$.

Not a Little Blue Fish wants you to perform a sequence of operations such that the number $X$ is filled into a cell for the first time at the very last operation. Additionally, Not a Little Blue Fish requires the total number of operations $Q$ to be exactly within the range $[L, R]$. You are asked to construct a possible sequence of operations or report that no such solution exists.

Input

The input consists of a single line containing five integers $N, M, X, L, R$.

Output

If no such solution exists, output a single integer -1.

Otherwise, output the first line containing an integer $Q$ ($L \le Q \le R$), representing the number of operations.

The next $Q$ lines each contain two integers $(i, j)$, describing each operation in order.

Examples

Input 1

7 10 7 10 100

Output 1

43
1 1
2 2
3 3
4 4
5 5
6 6
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
1 3
2 4
3 5
4 6
5 7
6 1
7 2
1 4
2 5
3 6
4 7
5 1
6 2
7 3
1 5
2 6
3 7
4 1
5 2
6 3
7 4
1 6
2 7
3 1
4 2
5 3
6 4
7 5
1 7

Subtasks

For all data, $1 \leq N, M \leq 500$, $1 \leq L \leq R \leq 10^9$, $1 \leq X \leq 10^9$.

Subtask 1 (6 points)

$N \leq 20$

$M \leq 20$

Subtask 2 (6 points)

$N \leq 2$

Subtask 3 (14 points)

$N \leq 5$

Subtask 4 (5 points)

$L = 1, R = 10^9$

Subtask 5 (23 points)

$L = 1$

Subtask 6 (25 points)

$N \neq M$

Subtask 7 (21 points)

No additional constraints.

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.