2052: [USACO 2025 February Contest, Gold] Problem 1. Bessie's Function

文件提交:无需freopen 内存限制:256 MB 时间限制:8.000 S
评测方式:普通裁判 命题人:
提交:3 解决:1

题目描述

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.

样例输入

5
2 4 4 5 3
1 1 1 1 1

样例输出

3

提示

We can change a= 4, a= 4, a= 4. Since all ci equal one, the total cost is equal to 3, the number of changes. It can be shown that there is no solution with only 2 or fewer changes.

SAMPLE INPUT:

8

1 2 5 5 3 3 4 4

9 9 2 5 9 9 9 9 

SAMPLE OUTPUT:

7

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 .


来源/分类