\problemname{Being Solarly Systematic}

Professor Braino Mars is one of the top researchers in the field of solar system
creation.  He runs various simulations to test out his theories on planet
formation, but he's old school and all of these simulations are done by hand.
It's time for Braino to enter the $21^{\textrm{st}}$ century, and he's asked you
to help automate his simulations.

One of Prof.\ Mars' simulations models how small planetoids collide over time to
form larger planets.  To model this process he divides the space which the
planetoids inhabit into an $n_x \times n_y \times n_z$ grid of cubes, where each
cube can hold at most one planetoid.  Each planetoid has an initial mass $m$, an
initial location $(x, y, z)$ in the grid and a velocity $(v_x, v_y, v_z)$
indicating the number of cubes per second the planetoid travels through in each
dimension. For example, if a planetoid is initially in location $(1, 3, 2)$ and
has velocity $(3, -1, 2)$, then after $1$ second it will be in location
$(4, 2, 4)$, after $2$ seconds it will be in location $(7, 1, 6)$, and so on.  The
planetoid paths wrap around in all dimensions, so if, for example, the planetoid
described above resides in an $8\times8\times8$ space, its next two locations
will be $(2, 0, 0)$ and $(5, 7, 2)$ (note that all cube indices start at $0$).
When two or more planetoids collide, they form one larger planetoid which has a
mass equal to the sum of the colliding planetoids' masses and a velocity equal
to the average of the colliding velocities, truncating to the nearest integer.
So if a planetoid of mass $12$ with velocity $(5, 3, -2)$ collides with another
planetoid of mass $10$ and velocity $(8, -6, 1)$ the resulting planetoid has
mass $22$ and velocity $(6, -1, 0)$ (these values correspond to the first sample
input.) For simplicity, Prof.\ Mars only considers collisions that happen at
integer time steps, and when no more collisions are possible, the planetoids are
then considered full-fledged planets.

Given an initial set of planetoids, Prof.\ Mars is interested in determining how
many planets will form and what their orbits are.  Armed with your
implementation of his model, he should now be able to answer these questions
much more easily.

\section*{Input}

The input will start with a line containing four positive integers $n$ $n_x$
$n_y$ $n_z$, where $n \leq 100$ is the number of planetoids, and $n_x$, $n_y$
and $n_z$ are the dimensions of the space the planetoids reside in, where $n_x,
n_y, n_z \leq 1000$.

After this are $n$ lines of the form $m$ $x$ $y$ $z$ $v_x$ $v_y$ $v_z$,
specifying the mass, initial location and initial velocity of each planetoid at
time $t=0$, where $1 \leq m \leq 100$, $0\leq x<n_x, 0 \leq y<n_y, 0\leq z<n_z$,
and $-1000 \leq v_x, v_y, v_z \leq 1000$. No two planetoids will start in the
same initial location.
\newpage
\section*{Output}

Output an integer $p$ indicating the number of planets in the system after no
more collisions can occur.  After this output $p$ lines, one per planet, listing
a planet identifier P$i$, $(0 \leq i < p)$, the mass, location and velocity of
each planet. Use the location of the planets at the time that the last collision
occurred.

If no collisions occur, then use their location at time $t=0$.

The planets should be ordered from largest mass to smallest; break ties by using
the lexicographic ordering of the $x,y,z$ location of the planet, starting with
the smallest $x$ value.

