시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 256 MB 0 0 0 0.000%

문제

A $d$-dimensional collection is a set of vectors such that:

  • Each coordinate of each vector in the set is a non-negative integer number.
  • Let a vector $v = (v_1, \ldots, v_d)$ belong to the set. Then every vector $u = (u_1, \ldots, u_d)$ such that all $u_i$ are non-negative integers and $u$ does not exceed $v$ coordinate-wise (that is, for every index $i$ from $1$ to $d$ the inequality $0 \leq u_i \leq v_i$ must hold) must belong to the set as well.

For example, $\{(0, 0), (0, 1), (1, 0)\}$ and $\{(0, 0), (1, 0), (2, 0), (3, 0)\}$ are $2$-dimensional collections, while $\{(0, 1), (1, 0), (1, 1)\}$, $\{(0, 0), (-1, 0)\}$, and $\{(0, 0), (0, \frac{1}{2}), (0, 1)\}$ are not.

You have to store two identical $d$-dimensional collections, each of size $n$. In order to do that, you gathered $n$ identical $d$-dimensional containers each of which has a capacity given by the capacity vector $c = (c_1, \ldots, c_d)$. You decided to choose a container for each vector from each collection in such a way that every container would contain exactly one vector from the first collection and exactly one vector from the second collection. However, if two vectors $v = (v_1, \ldots, v_d)$ and $u = (u_1, \ldots, u_d)$ are placed in the same container, it must be verified that $v_i + u_i \leq c_i$ for every $i$; that is, the vector $v + u$ must not exceed the capacity vector $c$ coordinate-wise.

It is also guaranteed that each vector from each collection fits in any container by itself; that is, each vector $v$ of each collection does not exceed the capacity vector $c$ coordinate-wise.

Finding an arrangement to place all those vectors in containers turned out to be hard, so you decided to write a program that will solve this problem.

입력

The first line of input contains two space-separated positive integers $n$ and $d$ ($1 \leq n \cdot d \leq 10^5$) --- the size and the dimension of each collection.

The second line of input contains $d$ space-separated integers $c_1$, $\ldots$, $c_d$ ($0 \leq c_i \leq 10^9$).

Next $n$ lines of input contain description of the collections; $i$-th of these lines contains $d$ space-separated integers $v_{i 1}$, $\ldots$, $v_{i d}$ ($0 \leq v_{i j} \leq 10^9$) --- coordinates of $i$-th vector in the collection. It is guaranteed that the described set of vectors is indeed a $d$-dimensional collection according to the definition above, and $v_{i j} \leq c_j$.

출력

Output $n$ lines, with two space-separated integers in each --- the numbers of vectors from the first and the second collection respectively that must be put in the $i$-th container. The numeration of vectors in the input is 1-based. Every vector from every collection must be assigned to exactly one container.

If there is more than one possible arrangement, output any one of them. It is guaranteed that there is at least one arrangement that satisfies all the requirements.

예제 입력 1

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

예제 출력 1

1 4
2 3
3 2
4 1

예제 입력 2

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

예제 출력 2

1 4
2 2
3 1
4 3