#K35917. Sequence Compression

    ID: 25638 Type: Default 1000ms 256MiB

Sequence Compression

Sequence Compression

You are given a sequence of integers and a value max_value. Your task is to compress the sequence by retaining only the first occurrence of each number and filtering out any integer that is greater than max_value. Specifically, for each number in the sequence, if it has not appeared before and it is less than or equal to max_value, you should include it in the output.

Note: The order of the retained numbers must be the same as their first appearance in the sequence.

For example, given a sequence 3 3 2 2 5 with max_value equal to 4, the compressed sequence is 3 2 because:

  • The first 3 is kept, the second 3 is ignored.
  • The first 2 is kept, the second 2 is ignored.
  • 5 is greater than 4 so it is discarded.

Solve the problem by reading from stdin and writing to stdout. If no number in the input meets the criteria, print an empty line.

inputFormat

The input consists of three lines:

  1. An integer n, representing the length of the sequence.
  2. n space-separated integers representing the sequence.
  3. An integer max_value representing the maximum allowed value.

outputFormat

Print the compressed sequence as a single line of space-separated integers. The sequence should contain only the first occurrence of each element that is less than or equal to max_value. If no element qualifies, output an empty line.

## sample
5
3 3 2 2 5
4
3 2