There are two sequences X and Y, each containing N numbers. One cyclic shift removes the last element of a sequence and inserts it at the front. For example, one cyclic shift changes {1, 2, 3} into {3, 1, 2}, and another shift changes it into {2, 3, 1}.
You may apply zero or more cyclic shifts to X, and independently zero or more cyclic shifts to Y. After all shifts, compute the score S as follows.
S = X[0] * Y[0] + X[1] * Y[1] + ... + X[N-1] * Y[N-1]
Find the maximum possible value of S.