题目描述
Bear Limak has a sequence of N non-negative integers A1, A2, ..., AN. He defines the score of a segment (consecutive subsequence) as its sum of elements modulo P (not necessarily prime). Find the maximum score of a non-empty segment, and also find the number of segments with this maximum score.
-----Input-----
First line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
For each test case, the first line of the input contains two space separated integers, N and P.
The second line contains N space separated integers denoting the sequence.
-----Output-----
For each test case, output two space separated integers denoting the maximum score of a segment and the number of segments with the score, respectively.
-----Constraints-----
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 105
- 1 ≤ P ≤ 109
- 0 ≤ Ai ≤ 109
Subtask #1: (25 points)
- 1 ≤ N ≤ 100
Subtask #2: (25 points)
- 1 ≤ N ≤ 1000
Subtask #3: (50 points)
- original constraints
-----Example-----
Input:
4
2 3
1 2
3 5
2 4 3
3 100
1 3 5
4 3
1 2 3 4
Output:
2 1
4 2
9 1
2 2
-----Explanation-----
Example case 1. There are three segments - [1], [2] and [1, 2]. Sum of these segments are 1, 2 and 3 respectively. Sum of these segments modulo 3 will be 1, 2 and 0. Maximum score among these is 2. There is also only one segment with this score.
Example case 2. There are six segments - [2], [4], [3], [2, 4], [4, 3] and [2, 4, 3]. Sum of these segments are 2, 4, 3, 6, 7, 9 respectively. Sum of these segments modulo 5 will be 2, 4, 3, 1, 2, 4. Maximum score among these is 4. And there are two segments with this score.
输入格式
见题面
输出格式
见题面