Secret message
The letter from the Center did not reach Stirlitz.
Read it again... Still didn't get it...
The intelligence agency "Kolobok" uses a unique method to transmit secret messages to its operatives. Initially, the message is encoded using the standard ASCII table and then divided into two equal parts. A specific number, not present in the original message, is added to corresponding positions in both parts—this number is known as the key. Subsequently, each sequence is cyclically shifted: one part is shifted to the left, and the other to the right. The direction of the shift is arbitrary, but the number of positions shifted is identical for both parts.
Agent Vasya Pupkin discovered two numerical sequences of equal length in his desk drawer. He is now preoccupied with the idea that these sequences might be parts of an undiscovered secret message. To determine this, both sequences must be returned to their original form, ensuring the key number appears in the same positions. This requires cyclically shifting both sequences by an equal number of positions, with the first sequence shifted to the left and the second to the right. If, after this operation, all key numbers align in the same positions, the sequences are considered to be from the same message. If this alignment cannot be achieved, the sequences are from different messages.
Help Vasya determine the minimum number of positions needed to shift the sequences to restore the message.
Input
The program reads from the input the number N (1 ≤ N ≤ 200000) on the first line. The second and third lines each contain N numbers, representing the sequences found by Vasya. The last line contains a single number — the key P. All numbers are integers ranging from 0 to 255 inclusive.
Output
The program should output a single number — the minimum shift required to align the numerical sequences to form the original message. If the sequences originate from different messages, output the number -1.