#K11071. Counting Good Subarrays

    ID: 23387 Type: Default 1000ms 256MiB

Counting Good Subarrays

Counting Good Subarrays

Given an array of integers and an integer (K), a subarray is called a good subarray if the sum of its elements is divisible by (K). In other words, a subarray (A[i..j]) is good if (\sum_{k=i}^{j} A[k] \equiv 0 \pmod{K}).

Your task is to compute the total number of good subarrays in the given array.

For example, for the array [4, 5, 0, -2, -3, 1] and (K = 5), the number of good subarrays is 7.

inputFormat

The input consists of two lines. The first line contains two integers (n) and (K), where (n) is the number of elements in the array, and (K) is the divisor. The second line contains (n) space-separated integers representing the array.

outputFormat

Output a single integer representing the number of good subarrays whose sum is divisible by (K).## sample

6 5
4 5 0 -2 -3 1
7