Bessie's Function
시간 제한: 2000ms메모리 제한: 2048MB출처: USACO 2025 February GoldBOJ 33729
문제
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
출력
3
예제 2
입력
8 1 2 5 5 3 3 4 4 9 9 2 5 9 9 9 9
출력
7
코드를 제출하려면 로그인하세요.