Hadron Collider
In the hadron collider, N
types of new particles have emerged, with quantities of A[1], … , A[N] units for each type. However, most of these particles react with one another before they can be detected, making it essential for physicists to predict the final results of these reactions.
For simplicity, assume that the reaction between two particles can result in one of the following scenarios, based on their types:
The first particle destroys the second.
Both particles destroy each other.
The particles collide without any effect.
Your task is to determine all possible outcomes of the experiment.
Input Data
Each test case is described by a series of numbers: the first number indicates the number of particle types N
(1 ≤ N ≤ 4
). The next line contains N
numbers, representing the initial quantity of each particle type A
[i] (1 ≤ A[i] ≤ 2). The subsequent N
lines provide the matrix A
[N
][N
]. A non-zero entry in cell A[ij] signifies that a particle of type i
destroys a particle of type j
upon collision. The input continues with the description of the next test. A test with N
= 0 marks the end of the input data.
Output Data
The first line should be a header in the format TEST n: (where n
is the test number, starting from 1). The following lines should list the different possible outcomes of the experiment, with each outcome presented on a separate line of N
numbers.