#C3825. Count Divisible Subsequences
Count Divisible Subsequences
Count Divisible Subsequences
You are given a list of n integers and three integers n, a, and b. Your task is to count the number of non-contiguous subsequences (i.e., subsets preserving the relative order) of the list with the following properties:
1. The length of the subsequence is at least a.
2. The sum of the elements in the subsequence is divisible by b.
Formally, if S is a subsequence of the array such that |S| ≥ a, then we want to count S if
\( \sum_{x \in S} x \equiv 0 \pmod{b} \).
Note that the subsequences selected do not need to occupy consecutive positions in the original array.
This is a combinatorial problem that may require examining different subsets of the given list. You are required to read input from standard input (stdin) and print the result to standard output (stdout).
inputFormat
The input is given via standard input (stdin) in the following format:
n a b x₁ x₂ x₃ ... xₙ
Here, the first line contains three integers: n (the number of elements in the array), a (the minimum subsequence length), and b (the divisor). The second line contains n integers representing the array elements.
outputFormat
Output a single integer representing the number of subsequences such that the length of the subsequence is at least a and the sum of its elements is divisible by b.
## sample5 2 3
3 6 5 8 2
5