#K6571. Remove Duplicates from Sorted Array

    ID: 32258 Type: Default 1000ms 256MiB

Remove Duplicates from Sorted Array

Remove Duplicates from Sorted Array

You are given a sorted array of integers nums in non-decreasing order. Your task is to remove the duplicates in-place such that each unique element appears only once while maintaining the relative order of the elements.

You must achieve this with an extra space complexity of $O(1)$. In other words, you should not allocate extra memory for another array. Instead, modify the input array in-place.

After removing the duplicates, output the new length of the array and then the first part of the modified array consisting of the unique elements.

Note: The input will be provided via stdin and the output should be written to stdout.

inputFormat

The first line of input contains a single integer n, which denotes the number of elements in the array. If n is greater than 0, the second line contains n space-separated integers representing the sorted array.

outputFormat

The output consists of two lines. The first line should print the new length of the array after removing duplicates. The second line should print the first part of the modified array (i.e. the unique elements) separated by spaces. If n is 0, simply output 0.

## sample
6
0 0 1 1 2 2
3

0 1 2

</p>