Directional Resemblance
Vectors have their directions and two vectors make an angle between them.
Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle.
Input
The input is a sequence of datasets. A dataset specifies a set of three-dimensional vectors, some of which are directly given in the dataset and the others are generated by the procedure described below.
Each dataset is formatted as follows.
m n S W
x_1 y_1 z_1
x_2 y_2 z_2
...
x_m y_m z_m
The first line contains four integers m, n, S, and W.
The integer m is the number of vectors whose three components are directly specified in the dataset. Starting from the second line, m lines have the three components of m vectors. The i-th line of which indicates the vector v_{i }= (x_i, y_i, z_i). All the vector components are positive integers less than or equal to 100.
The integer n is the number of vectors generated by the following procedure.
int g = S;
for (int i=m+1; i<=m+n; i++) {
x[i] = (g/7) %100 + 1;
y[i] = (g/700) %100 + 1;
z[i] = (g/70000)%100 + 1;
if( g%2 == 0 ) { g = (g/2); }
else { g = (g/2) ^ W; }
}
For i = m+1, ..., m+n, the i-th vector v_i of the set has three components x[i], y[i], and z[i] generated by this procedure.
Here, values of S and W are the parameters S and W given in the first line of the dataset. You may assume 1 ≤ S ≤ 10^9 and 1 ≤ W ≤ 10^9.
The total number of vectors satisfies 2 ≤ m+n ≤ 12×10^4. Note that exactly the same vector may be specified twice or more in a single dataset.
A line containing four zeros indicates the end of the input. The total of m+n for all the datasets in the input never exceeds 16×10^5.
Output
For each dataset, output the pair of vectors among the specified set with the smallest non-zero angle in between. It is assured that there are at least two vectors having different directions.
Vectors should be indicated by their three components. The output for a pair of vectors v_a and v_b should be formatted in a line as follows.
x_a y_a z_a x_b y_b z_b
Two vectors (x_a, y_a, z_a) and (x_b, y_b, z_b) are ordered in the dictionary order, that is, v_a < v_b if x_a < x_b, or if x_{a }= x_{b }and y_a < y_b, or if x_a = x_b, y_a = y_b and z_a < z_b. When a vector pair is output, the smaller vector in this order should be output first.
If more than one pair makes the equal smallest angle, the pair that is the smallest among them in the dictionary order between vector pairs should be output. The pair (v_i, v_j) is smaller than the pair (v_k, v_l) if v_i < v_k, or if v_{i }= v_{k }and v_j < v_l.