Transform a sequence using . After removing position , consider a later position . If is odd, the preceding sum decreases by and that element increases by . If it is even, the preceding sum increases by and the element decreases by . Thus its transformed value is unchanged. The operation simply deletes one transformed value. The transformation is invertible: given the preceding sum , recover the next element as . Therefore equal resulting sequences correspond exactly to common subsequences of the transformed sequences. If their LCS has length , the answer is . For subtask 1, enumerate actual deletion states and compare common states. There are at most states; an ordered-set implementation has the conservative bound . The full solution uses LCS DP in time and memory. Initially . Every later transformed sequence is a subsequence, so every reconstructed element has magnitude at most . Signed 64-bit integers suffice. Solution written by GPT6.1