Under construction

Still being built. Things may change

Remainder Subarray Count

Interview

Time limit1sMemory limit256 MB

Summary
Count contiguous intervals whose sum is divisible by M using prefix remainder frequencies.
Level

Medium4 of 10

Topics
Prefix sum, Hash map
Solved
No attempts yet

Problem

You are given a sequence A1,A2,…,ANA_1, A_2, \dots, A_N of length NN. Count the contiguous intervals whose sum is divisible by MM.

An interval is a pair (i,j)(i, j) with 1≤i≤j≤N1 \le i \le j \le N, and it covers AiA_i through AjA_j. Two intervals count as different when they differ in ii or in jj.

Input

The first line contains NN and MM, separated by a space. (1≤N≤1061 \le N \le 10^6, 2≤M≤1032 \le M \le 10^3)

The second line contains the NN numbers of the sequence A1,A2,…,ANA_1, A_2, \dots, A_N, separated by spaces. (0≤Ai≤1090 \le A_i \le 10^9)

Output

Print the number of intervals that satisfy the condition on the first line.

Examples3

  1. Example 1

    Input
    5 3
    1 2 3 1 2
    
    Expected output
    7
    
  2. Example 2

    Input
    3 5
    1 2 3
    
    Expected output
    1
    
  3. Example 3

    Input
    1 2
    4
    
    Expected output
    1