Intact Intervals

아직 제출이 없습니다시간 제한6초메모리 제한1024 MB

문제

Gustav is an astronaut on the Nordic Celestial Planetary Craft (NCPC), a large space station in orbit around Mars. Today, one of Gustav's tasks is to look over the satefy routines on board.

The space station consists of nn modules arranged in a circle, so that module ii is connected to module i+1i+1 for i=1n1i = 1 \ldots n-1, and module nn is connected to module 11. Each module ii has a non-negative integer type a_ia\_i, representing the kind of equipment that can be found there. Different modules can have the same type. In case of emergency, the equipment must be rearranged so that each module ii instead gets type b_ib\_i, for some list b_1,b_2,,b_nb\_1, b\_2, \cdots, b\_n. Here, the list bb is a rearrangement of the list aa.

Gustav has noticed that if some module connections are severed, causing the space station to split into separate parts, it may become impossible to perform this rearrangement of the equipment. He decides to estimate how likely it is that the safety routines can be followed, by calculating in how many ways the space station can be separated into two or more parts such that it is still possible to rearrange the equipment according to the emergency procedures.

In other words, your task is to count in how many ways the circular list aa can be partitioned into at least two non-empty contiguous intervals, in such a way that the circular list bb can be obtained by rearranging elements within each interval. Since this number can be quite big, you should find its remainder modulo 109+710^9+7.

For example, consider Sample Input 1 below.  Here the list aa could be split into \[12234]\[1 | 2 2 3 | 4], indicating that the connection between modules 11 and 22, and the connection between modules 44 and 55, are severed.  Note that the connection between module 55 and 11 remains in this split.  The second possible way in which aa could be split is \[12234]\[1 2 | 2 | 3 4].

In Sample Input 2 below, the only possible way to split the list aa into at least two non-empty parts is to separate the two modules. But then it is impossible to rearrange the parts to create the list bb. Hence, the answer is 00.

입력

The first line of input contains a single integer nn (2n1062 \leq n \leq 10^6), the number of modules. The second line contains the nn integers a_1,a_na\_1, \ldots a\_n (0a_i1090 \leq a\_i \leq 10^9). The third and final line contains the nn integers b_1,,b_nb\_1, \ldots, b\_n (0b_i1090 \leq b\_i \leq 10^9).

The list bb is guaranteed to be a rearrangement of the list aa.

출력

Print one integer, the number of safe separations modulo 109+710^9+7.