#K50222. Minimum Operations to Permutation

    ID: 28817 Type: Default 1000ms 256MiB

Minimum Operations to Permutation

Minimum Operations to Permutation

You are given an integer N and a sequence of N integers. The sequence may contain duplicates and lacks some numbers from the set \(\{1, 2, \ldots, N\}\). In one operation, you can replace any element of the sequence with any integer. Your goal is to transform the sequence into a permutation of the integers from 1 to N.

The minimum number of operations needed is equal to the number of missing integers in the sequence, i.e. the size of the set difference \(\{1, 2, \ldots, N\} \setminus \text{set}(sequence)\).

Example:
For N = 5 and sequence [4, 2, 2, 1, 5], the numbers present are \(\{1, 2, 4, 5\}\) and the missing number is 3. Therefore, the minimum operations required is 1.

inputFormat

The input is provided via standard input (stdin) and consists of two lines:

  • First line: a single integer N, representing the length of the sequence.
  • Second line: N space-separated integers representing the sequence.

outputFormat

Output a single integer on standard output (stdout): the minimum number of operations required to transform the sequence into a permutation of integers from 1 to N.

## sample
5
4 2 2 1 5
1