Cow Checkups

시간 제한2초메모리 제한2048 MB

문제

Farmer John's $N$ ($1 \leq N \leq 5 \cdot 10^5$) cows are standing in a line, with cow $1$ at the front of the line and cow $N$ at the back of the line. FJ's cows also come in many different species. He denotes each species with an integer from $1$ to $N$. The $i$'th cow from the front of the line is of species $a_i$ ($1 \leq a_i \leq N$).

FJ is taking his cows to a checkup at a local bovine hospital. However, the bovine veterinarian is very picky and wants to perform a checkup on the $i$'th cow in the line, only if it is species $b_i$ ($1 \leq b_i \leq N$).

FJ is lazy and does not want to completely reorder his cows. He will perform the following operation exactly once.

  • Select two integers $l$ and $r$ such that $1 \leq l \le r \leq N$. Reverse the order of the cows that are between the $l$-th cow and the $r$-th cow in the line, inclusive.

FJ wants to measure how effective this approach is. Find the sum of the number of cows that are checked by the veterinarian over all $N(N+1)/2$ possible operations.

입력

The first line contains an integer $N$.

The second line contains $a_1, a_2, \ldots, a_N$.

The third line contains $b_1, b_2, \ldots, b_N$.

출력

Output one line with the sum of the number of cows that are checked by the veterinarian over all possible operations.