Find all values that appear in the array as a run of equal numbers whose total length matches the value itself.
Problem
You are given an array of integers. A value is considered interesting if it appears in the array in one or more contiguous blocks, and the total number of times that value appears in the whole array is exactly equal to the value itself.
Your task is to output all interesting values in increasing order.
Clarification
If a number appears multiple times in different consecutive blocks, count all occurrences together. Only the final total frequency matters.
Goal
Identify every value such that the array contains exactly occurrences of .
Input Format
Input
- The first line contains an integer — the size of the array.
- The second line contains integers .
Output Format
Output
- Print the number of interesting values.
- Then print all interesting values in increasing order.
Constraints
Constraints
Example 1
Input
7 4 5 4 5 4 5 5
Output
2 4 5
Explanation
The value 4 appears exactly 4 times, and the value 5 appears exactly 5 times. Both are interesting.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.