#C9282. Remove Duplicates from Sorted Array

    ID: 53358 Type: Default 1000ms 256MiB

Remove Duplicates from Sorted Array

Remove Duplicates from Sorted Array

Given a sorted array of integers, remove the duplicates in-place such that each element appears only once. The relative order of the elements must be preserved. After removal, the front part of the array should contain the unique elements in sorted order. Your task is to modify the array in-place with \(O(1)\) extra memory, and then output the new length followed by the unique elements.

inputFormat

The input is given from stdin in the following format:

  1. The first line contains an integer \(n\) representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers sorted in non-decreasing order.

outputFormat

Output to stdout in the following format:

  1. The first line contains the new length of the array after duplicates have been removed.
  2. The second line contains the unique elements separated by a single space. If the array is empty, only output the new length.
## sample
5
1 1 2 2 3
3

1 2 3

</p>