#K52982. Minimum Items After Merge
Minimum Items After Merge
Minimum Items After Merge
Given a sequence of n items, you are allowed to merge consecutive items if they are identical. Merging a group of adjacent identical items results in a single item representing that group. Determine the minimum number of items remaining after performing all possible merge operations.
Formally, if the input sequence is \(a_1, a_2, \ldots, a_n\), then after merging, the number of items left is equal to the number of contiguous blocks of identical items.
Example: For the sequence [2, 2, 3, 3, 1, 1, 1], there are three contiguous blocks: [2,2], [3,3] and [1,1,1]. Hence, the answer is 3.
inputFormat
The input is given from stdin in the following format:
- The first line contains an integer n representing the number of items.
- If n > 0, the second line contains n space-separated integers representing the items.
If n is 0, the second line is omitted.
outputFormat
Print a single integer to stdout representing the minimum number of items remaining after performing all merge operations.
## sample7
2 2 3 3 1 1 1
3
</p>