Remove Duplicates from Sorted Array
Given a sorted array, remove duplicates in-place so each element appears once, returning the new length.
Input format
The first line contains N. The second line contains N integers sorted in non-decreasing order.
Output format
Print two lines: the count K of distinct elements, then the K distinct elements in order.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5
1 1 2 2 3Expected output
3
1 2 3Example 2
Input
3
7 7 7Expected output
1
7