문제
Bessie has a special function that takes as input an integer in and returns an integer in (). Her function is defined by integers where ().
Bessie wants this function to be idempotent. In other words, it should satisfy for all integers .
For a cost of , Bessie can change the value of to any integer in (). Determine the minimum total cost Bessie needs to make idempotent.
입력
The first line contains .
The second line contains space-separated integers .
The third line contains space-separated integers .
출력
Output the minimum total cost Bessie needs to make idempotent.
예제 입력 1
5
2 4 4 5 3
1 1 1 1 1
예제 출력 1
3
예제 입력 2
8
1 2 5 5 3 3 4 4
9 9 2 5 9 9 9 9
예제 출력 2
7
점수
Subtasks:
Input 3: Inputs 4-9: Inputs 10-15: All are distinct.Inputs 16-21: No additional constraints.
Additionally, in each of the last three subtasks, the first half of tests will satisfy for all .
코드를 제출하려면 로그인이 필요합니다.
로그인