## Editorial for Yet Another Contest 8 P2 - No More Modern Art

**only**when stuck, and

**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.

**Submitting an official solution before solving the problem yourself is a bannable offence.**

Author:

#### Subtask 1

It suffices to simulate all possible sequences of operations.

**Time complexity:**

#### Subtask 2

Suppose a bucket with colour is selected for the first operation, and a bucket with initial colour is selected for the second operation. For all other buckets, a bucket starting with colour would end up having colour . It is clear that the actual value of does not affect the answer. In general, all buckets other than the last two remaining buckets before the final operation do not matter; the final colour is simply the XOR of the last two remaining buckets.

Thus, it suffices to loop through all pairs of elements, and check if the XOR of any of them is equal to .

**Time complexity:**

#### Subtask 3

We can speed up subtask . Loop through the array and maintain a set of already seen values. When processing value , we should check if is in the set, since . If not, we should add to the set and continue.

It's also possible to just create a set for the entire array at once, and do the above check for each element. However, be careful of the special case where ; here, , so we need to check that there is an element occurring more than once.

**Time complexity:** or

## Comments