Bear and Segments

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Bear Limak has a sequence of N nonnegative integers A_{1}, A_{2}, ..., A_{N}. 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 nonempty 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 ≤ 10^{5}
 1 ≤ P ≤ 10^{9}
 0 ≤ A_{i} ≤ 10^{9}
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.
Author:  admin2 
Tester:  lg5293 
Editorial  https://discuss.codechef.com/problems/BEARSEG 
Tags  admin2, bst, easymedium, ltime47, partialsums 
Date Added:  29042017 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions