#K67977. Minimum New Toys Needed
Minimum New Toys Needed
Minimum New Toys Needed
You are given a collection of toy identifiers, one for each friend. Some identifiers may be duplicated. Your goal is to determine the minimum number of new toys needed such that after replacing duplicates, all toy identifiers are unique.
More formally, you are given an integer n and a sequence of integers \( a_1, a_2, \dots, a_n \). You need to compute the number of duplicate occurrences. That is, if a toy identifier appears more than once, only the first occurrence is kept. Every subsequent copy is considered a duplicate. Mathematically, if we define the indicator function \( I(\text{toy} \in \text{seen}) \), the answer is:
[ \text{Answer} = \sum_{i=1}^{n} I(a_i \text{ is a duplicate}) ]
This problem is simple but tests your ability to work with sets and counting duplicates.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer \( n \) indicating the number of toys.
- The second line contains \( n \) space-separated integers where each integer represents a toy identifier.
outputFormat
Output to stdout a single integer representing the minimum number of new toys needed to guarantee that all toy identifiers are unique.
## sample4
1 2 3 4
0