Subsequence Hashes
Time limit1sMemory limit256 MB
Print the polynomial hashes of the K lexicographically smallest non-empty subsequences of the given array.
- Level
Hard8 of 10
- Topics
- Heap, Sorting, Combinatorics
- Solved
- No attempts yet
Problem
You are given an array of integers. Sort every non-empty subsequence of that array lexicographically and call the result . A subsequence is an array obtained by deleting zero or more elements from the original array. Several subsequences can be equal to one another, and .
Array is lexicographically smaller than array if at the first position where the two arrays differ, or if is a strict prefix of .
The hash of an array with values is defined as
where and are given integers. For a given , compute .
Input
The first line contains the integers , , , (, , ).
The second line contains the integers ().
Every input satisfies .
Output
Print lines. Line contains .
Note
In the first example the sorted subsequences are , , , so , and .
In the second example they are , , , . Two elements have the value 1, so appears twice. The hashes are , , and .