#P11842. [USACO25FEB] Bessie's Function G
[USACO25FEB] Bessie's Function G
Description
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.
Input Format
The first line contains .
The second line contains space-separated integers .
The third line contains space-separated integers .
Output Format
Output the minimum total cost Bessie needs to make idempotent.
5
2 4 4 5 3
1 1 1 1 1
3
8
1 2 5 5 3 3 4 4
9 9 2 5 9 9 9 9
7
Hint
For Sample 1:
We can change , , . Since all equal one, the total cost is equal to , the number of changes. It can be shown that there is no solution with only or fewer changes.
For Sample 2:
We change and . The total cost is .
SCORING:
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 .
京公网安备 11011102002149号