NOTE: The translation may not reflect the original text verbatim.
Following the experiments carried out in the month in which the County Olympiad of Informatics was held, Dexter decided to protect at all costs the discoveries he had made regarding a cure for cancer. He therefore chose to implement homomorphic encryption, a special method that allows logical operations to be performed directly on encrypted data without decrypting it.
Convinced that this type of encryption will ensure the confidentiality of his discoveries, Dexter is preparing to send to his nanotechnology professor the chapters of his scientific work, entitled From experiments to experiments.
In each chapter, he represents the collection of the experimental data as a sequence of non-negative integers, arranged either linearly (in a line) or circularly (in a ring).
Before sending the data, Dexter thinks he has noticed an unusual phenomenon whilst analysing the homomorphic encryption: if, in either a linear or a circular structure, the sequence reaches a uniform state, that is to say, all values in the sequence become equal, by repeatedly replacing two adjacent elements with their exclusive disjunction—i.e., a logical operation called xor, often denoted by ; in C/C++ it is written as the operator—, then an unforeseen problem may arise: encryption algorithms can no longer distinguish between encrypted data, and direct computations on it become useless.
For instance, if a chapter consists of integers arranged linearly, , and we choose the first two elements and replace them with their exclusive disjunction, we obtain . Whatever adjacent pair we next choose, we can never obtain a uniform sequence, because
and .
Instead, should we choose, for the same initial sequence, the last two elements and replace them with their exclusive disjunction, we get , which is a uniform sequence.
Task
For each of the chapters, determine whether the sequence of the non-negative integers can be transformed into a uniform state—with at least two values remaining in the sequence—by repeatedly (as many times as necessary) replacing two adjacent elements with their exclusive disjunction.
Input data
The file experimente2.in
contains on the first line two values:
- , which is if the values are considered to be arranged linearly, or if they are considered to be arranged circularly;
- , a natural number indicating the number of chapters Dexter wishes to analyse.
Each of the next chapters is described by:
- one line containing the number , the length of the sequence;
- one line with the non-negative integers, separated by spaces, representing the sequence values.
Output data
The file experimente2.out
must contain, for every chapter—in the order given in the input—a single line with:
- the text
DA
, if there exists a sequence of replacements that leaves at least two values in the sequence and all remaining values equal, or - the text
NU
, otherwise.
Constraints and clarifications
- ;
- ;
- ;
- every element of every sequence belongs to ;
- the sum of all over all chapters does not exceed ;
- the exclusive disjunction is the xor operation.
# | Points | Restrictions |
---|---|---|
1 | 5 | |
2 | 6 | |
3 | 9 | |
4 | 10 | , with no further constraints |
5 | 7 | |
6 | 9 | |
7 | 10 | |
8 | 9 | |
9 | 35 | , with no further constraints |
Example 1
experimente2.in
1 2
6
1 1 0 0 1 1
4
2 4 8 32
experimente2.out
DA
NU
Explanation
We have , therefore the values are arranged linearly.
One possible sequence of operations is to replace the first two and the last two elements with their exclusive disjunction, obtaining , which is a uniform sequence.
For the sequence there is no way to reach a uniform state.
Example 2
experimente2.in
2 2
5
2 1 1 1 3
6
1 2 4 7 7 7
experimente2.out
DA
DA
Explanation
We have , therefore the values are arranged circularly.
For the first chapter, we can replace the first and last elements with their exclusive disjunction (since they are adjacent on the circle), yielding .
For the second chapter, we may successively replace the first two elements with their exclusive disjunction, obtaining .