#C12702. Non-Decreasing Subsequences

    ID: 42159 Type: Default 1000ms 256MiB

Non-Decreasing Subsequences

Non-Decreasing Subsequences

Given an array of integers, find all the non-decreasing subsequences that have a length of at least two. A subsequence is obtained by deleting some or no elements without changing the order of the remaining elements. Two subsequences are considered different if their sequence of values is different.

Mathematically, if a subsequence is represented as (a_1,a_2,\ldots,a_k) then it must satisfy (a_i \leq a_{i+1}) for (1 \leq i < k).

This problem requires generating all such unique subsequences. The output order does not matter, but to ensure consistency across solutions, please output the subsequences in lexicographical order (comparing elements from left to right).

inputFormat

The first line of input contains an integer (n) denoting the number of elements in the array. The second line contains (n) space-separated integers representing the array.

outputFormat

Output each non-decreasing subsequence (of length at least 2) on a separate line. The numbers in each subsequence should be separated by a single space. If there is no valid subsequence, output nothing.## sample

4
4 6 7 7
4 6

4 6 7 4 6 7 7 4 7 4 7 7 6 7 6 7 7 7 7

</p>