Partition to pairs
Space archaeologists discovered on the planet in the neighbouring star system n ancient artefacts, which they numbered from 1 to n. Each artefact has k different parameters, each parameter is characterised by an integer. The artefact i has the parameters a[i,1]
, a[i,2]
, ... a[i,k]
. It turned out that the first parameters for all artefacts are different: for all i ≠ j, a[i,1]
≠ a[j,1]
is satisfied, while other parameters for the artefacts may coincide.
Scientists also discovered a text according to which, in order to activate artefacts, they must be specially paired and combined. The partition of artefacts is correct if for each t from 1 to k you can choose such a number b[t]
that it lies on the interval between the values of t-th parameter of artefacts of each pair. That is, artefacts i and j form a pair, if holds the condition a[i,t]
≤ b[t]
≤ a[j,t]
or the condition a[i,t]
≥ b[t]
≥ a[j,t]
.
Now scientists want to find out if the text is correctly decrypted. To do this, you need to check whether there is a correct splitting of artefacts into pairs. Each artefact must enter exactly one pair in the split.
Write a program that, according to the description of the parameters of the artefacts, determines whether it is possible to split them into pairs so that for each parameter there is a value lying between the values of this parameter of the artefacts of each pair, and in the case of a positive answer displays such partition.
Input
First line contains integers n and k (2 ≤ n ≤ 2 * 10^5
, n is even, 1 ≤ k ≤ 7) - number of artefacts and number of parameters. Each of the next n lines contains k integers a[i,1]
, a[i,2]
, ..., a[i,k]
- the parameters of artefacts (-10^9
≤ a[i,j]
≤ 10^9
, all values of a[i,1]
are different).
Output
Print "NO" if the required pairing does not exist.
Otherwise, print "YES" in the first line. Then print n / 2 lines, in each line print two numbers - the numbers of artefacts that make a pair. Each artefact must be displayed exactly once.
If there are several valid pairs of artefacts, output any of them.