#1259
Unrated
Kralj
시간 제한
2s
메모리 제한
128MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Young ruler Mirko has declared himself king of dwarves. Upon hearing this, Slavko felt threatened and soon declared himself king of elves! As there cannot be more than one king in the land, they have decided to resolve the issue of power once and for all. Slavko will, along with N strongest elves of the kingdom, labeled with numbers from 1 to N, go visit Mirko’s castle. In the castle hall, they will be greeted by N strongest dwarves sitting in a circle, labeled clockwise with numbers from 1 to N. Mirko has, upon entering the castle, given a number AiA_{i} to each of Slavko’s elves – the label of the dwarf it will fight against. Unfortunately, he didn’t make sure that each elf should get a unique adversary, and soon a terrible fight broke out. They have decided to solve the problem in the following way: ● Slavko will send his elves to the hall one by one, in the order he chooses. The next elf can enter the hall only after the one before him found a place to sit. ● The elf labeled k will first approach the dwarf labeled AkA_{k}. If there isn’t an elf sitting beside the dwarf, he will sit there. Otherwise, he will continue walking, from dwarf to dwarf, clockwise, until he finds an unclaimed dwarf. Now the N resulting pairs of elves and dwarves compete in armwrestling, and the stronger one always wins. Slavko is well prepared for this event. He has studied all the fighters and determined the strength of each one. Now he wants to send the elves to the hall in the order which, after they all sit down, will bring the most victories for him. Help him and calculate the highest number of victories in duels that can be achieved by elves!

입력

The first line of input contains the integer N (1 ≤ N ≤ 5 ⋅ 10510^{5}) The second line of input contains N integers AiA_{i} (1 ≤ AiA_{i} ≤ N), the adversaries chosen by Mirko. The third line of input contains N integers PiP_{i} (1 ≤ PiP_{i}10910^{9}), the dwarves’ strengths. The fourth line of input contains N integers ViV_{i} (1 ≤ ViV_{i}10910^{9}), the elves’ strengths. All strengths from the input will be mutually distinct.

출력

The first and only line of input must contain the maximum number of victories that can be achieved by elves.

채점

In test cases worth 40% of total points, Mirko will choose the dwarf labeled with 1 (AiA_{i} = 1 for each i from 1 to N) as an adversary in each elf duel.

예제 입력 1

3
2 3 3
4 1 10
2 7 3

예제 출력 1

2

예제 입력 2

4
3 1 3 3
5 8 7 10
4 1 2 6

예제 출력 2

1

예제 입력 3

3
1 2 3
8 4 3
9 2 6

예제 출력 3

2
코드 제출

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

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