Circular Buffer Alignment
A radio module keeps its last n received bytes in a ring buffer of n slots, numbered 0 to
n - 1. After a crash, a debugger dumped the buffer slot by slot, starting at slot 0, into a
string A. The write pointer was lost, so nobody knows which slot holds the first byte of the
message.
The message the module should have received is known: the string B, of the same length n.
Reading the buffer from slot k means reading slots k, k + 1, …, n - 1, 0, 1, …, k - 1 in that
order. The offset k is consistent if this reading is exactly B.
Find every consistent offset. A buffer with repeating content can have many of them.
Input
The first line contains n (1 ≤ n ≤ 10^6), the number of slots.
The second line contains the dump A, a string of exactly n lowercase English letters.
The third line contains the expected message B, a string of exactly n lowercase English
letters.
Output
On the first line print c, the number of consistent offsets.
On the second line print the c consistent offsets in increasing order, separated by single
spaces. If c = 0, print an empty line.
Notes
In the first example, reading lohel from slot 2 gives hel followed by lo, which is
hello. No other offset works.
In the second example, the dump repeats abc, so reading from slots 1, 4 and 7 all give
bcabcabca.