Interpret each string as a polynomial over , with characters written from the lowest-degree coefficient to the highest-degree coefficient. Since every string starts with , every polynomial has constant coefficient . Shifting by is equivalent to multiplying the polynomial by .
Assume that several normalized polynomials are placed at some starting positions and that their total XOR is zero. At least two terms must have the minimum starting position. Otherwise, the bit at that position would be contributed by exactly one term and could not be canceled.
We can therefore backtrack by guessing two terms with the same starting position. Align the starts of two normalized polynomials and XOR them.
Try every pair and recurse. If a solution exists, one branch chooses two terms having the minimum starting position in that solution. The transformation preserves the condition that the XOR of all remaining terms is zero, so repeatedly applying it eventually finds a complete solution. Conversely, if the recursion cancels every term, the shifts of the original strings can be reconstructed from the relative positions recorded during the merges.
For reconstruction, store the original string indices contained in every current term and their shifts relative to the normalized start of that term. If a merge removes leading bits, subtract from every stored relative shift in the merged term. When two terms cancel completely, subtract the minimum stored shift from all shifts in that component so that its minimum becomes zero. A completely canceled component has XOR zero by itself, so different components may be normalized independently.
Every current polynomial has length at most . Before its final cancellation, one original string participates in at most nonzero normalizations, and each normalization removes at most bits. Therefore the reconstructed shifts can always be made to lie between and .
Store each polynomial as an array of 64-bit words. XOR and normalization of one pair then take time. The size of the recursion tree depends only on , and . Pairs with the same two polynomial values can be tried only once at the same recursion state to remove symmetric branches.
Solution written by GPT5.6