Remember to use this editorial 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: Tzak
For the first subtask, it suffices to try possible values of
less than
. The resulting multisets can be compared with sorting in
.
Time complexity: 
For the second subtask, we observe that if a value for
exists, there is some
such that
, meaning
. With this, we have
possible candidates for
:
.
Time complexity: 
For the final subtask, we will use the fact that
is odd. Let's begin by assuming that we have found a value of
which makes the multisets equal. This implies that:

Let's XOR both sides by
:

The left hand side has an odd number of copies of
, so we have:

We have proven if a solution exists, then it is unique and given by the expression above. All that remains is to check if this value of
works.
Time complexity: 
Comments