Hide

Problem K
Horse Race - Hard

You are currently in horse racing competition with your arch nemesis. Both you and your arch nemesis have $N$ horses. This race has $N$ rounds, where in each round, one of your horses will race against one of your nemesis’s horses. All horses only race once.

You possess $N$ horses currently arranged in a line. The $i$-th horse in this line will have speed $a_ i$.

Your arch nemesis is sending out $N$ horses too. Each of their horses has a speed $b_ i$. The horse with a higher speed will always win the race. No two horses have the same speed.

You know the exact sequence in which your arch nemesis will send out their horses, which is in the order $b_0, b_1, b_2, \dotsc , b_{n-1}$. Since your horses are currently arranged in a line, it would take too much work to fully reorder them. Instead, you can pick any cyclic shift of your horses, and send them out in that order. We consider the $i$-th ($0 \leq i \leq N - 1$) cyclic shift to be the $i$-th right cyclic shift, so the cyclic shift where the last $i$ horses in the ordering are moved to the front.

You win the competition if, in the ordering you choose, you win strictly more than half the individual races. Print each cyclic shift that results in you winning the competition!

Input

The first line contains a single integer $N \: (1 \leq N \leq 200\, 000)$, representing the number of rounds in the race. The second line contains N space-separated integers, where the $i$-th integer represents $a_ i \: (1 \leq a_ i \leq 10^9)$, the speed of the $i$-th horse in your line. The third line contains $N$ space-separated integers, where the $i$-th integer represents $b_ i \: (1 \leq b_ i \leq 10^9)$, the speed of the $i$-th horse in your arch nemesis’ horse ordering. All values of $a_ i$ and $b_ i$ are distinct.

Output

On the first line, output a number, representing the number of cyclic shifts that win the competition. Then, in the next line, output space-separated each of the cyclic shift numbers that win in sorted order.

Sample Input 1 Sample Output 1
3
7 10 4 
1 6 9 
2
0 1

Please log in to submit a solution to this problem

Log in