#705
Unrated
Cow Checkups
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John's NN (1N51051 \leq N \leq 5 \cdot 10^5) cows are standing in a line, with cow 11 at the front of the line and cow NN at the back of the line. FJ's cows also come in many different species. He denotes each species with an integer from 11 to NN. The ii'th cow from the front of the line is of species aia_i (1aiN1 \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 ii'th cow in the line, only if it is species bib_i (1biN1 \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 ll and rr such that 1lrN1 \leq l \le r \leq N. Reverse the order of the cows that are between the ll-th cow and the rr-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)/2N(N+1)/2 possible operations.

입력

The first line contains an integer NN.

The second line contains a1,a2,,aNa_1, a_2, \ldots, a_N.

The third line contains b1,b2,,bNb_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.

예제 입력 1

3
1 3 2
3 2 1

예제 출력 1

3

예제 입력 2

3
1 2 3
1 2 3

예제 출력 2

12

예제 입력 3

7
1 3 2 2 1 3 2
3 2 2 1 2 3 1

예제 출력 3

60

점수

Input 4: N100N\le 100Input 5: N5000N\le 5000Inputs 6-9: ai,bia_i, b_i are all generated uniformly at random in the range [1,N][1,N]Inputs 10-15: ai,bia_i, b_i are all generated uniformly at random in the range [1,2][1,2]Inputs 16-23: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.