#K90827. Find Consecutive Duplicates
Find Consecutive Duplicates
Find Consecutive Duplicates
You are given a sequence of integers. Your task is to find all elements that appear consecutively more than once. For each group of identical numbers appearing consecutively, output the number only once if its repetition count is more than one.
For example, in the sequence:
1 1 2 3 3 3 4 5 5 6
the elements 1
, 3
, and 5
occur consecutively with a count greater than one. Therefore, the answer is:
1 3 5
Note: If no element appears consecutively more than once, output an empty line.
Constraints:
- The input begins with an integer \( n \) denoting the number of elements in the sequence.
- \( 1 \leq n \leq 10^5 \)
- Each of the following \( n \) integers fits in a 32-bit signed integer.
Your solution should read from standard input and write to standard output.
inputFormat
The first line contains an integer ( n ) denoting the number of elements. The second line contains ( n ) space-separated integers.
outputFormat
Print in one line the integers that appear consecutively more than once in the order of their occurrence, separated by a single space. If there is no such element, print an empty line.## sample
10
1 1 2 3 3 3 4 5 5 6
1 3 5
</p>