#QHD0000053. Đếm nhóm có tổng chia hết (Divisible Group Sums)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm nhóm có tổng chia hết (Divisible Group Sums)
Divisible Group Sums
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given signed integers , answer independent queries about the same array. Each query specifies positive integers .
Count subsets of exactly distinct positions whose sum is divisible by . The order of selected positions does not matter, but equal values at different positions still count as different choices. Negative integers may occur and remainders must be normalized mathematically.
Input
The first line contains . The next lines contain one each. Then lines contain .
Output
Print lines. Line contains the exact number of valid groups for query ; no modulo is applied. If , answer .
Subtasks
Scoring groups are independent. All constraints listed for a group apply simultaneously.
- Subtask 1 (20%): , , , , .
- Subtask 2 (30%): , , , , .
- Subtask 3 (50%): , , , , .
Examples
Input
5 2
1
2
3
4
5
3 2
5 3
Output
4
2
Explanation
For , the valid pairs of positions are , , , . For , the valid triples are and . The answers are and .