You are given an array sorted in non-decreasing order. Imagine compacting it in place so that every distinct value appears at most twice, preserving order, and dropping any extra copies beyond the first two of each value.
Return the length of the compacted prefix — i.e. how many elements remain after the trim.
Because the input is sorted, all copies of a value are contiguous, so the kept count for a value v is min(count(v), 2), and the answer is the sum of those over all distinct values.
Input format
Line 1: an integer n.
Line 2: n space-separated integers in non-decreasing order (empty when n == 0).
Output format
A single integer: the number of elements remaining after keeping each value at most twice.
Constraints
- 0 ≤ n ≤ 100000
- -1000000000 ≤ each value ≤ 1000000000
- The input array is guaranteed to be sorted in non-decreasing order.