/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int n = 4;
		int k = 4;
		int[] arr = new int[]{1,3,2,4};
		
		System.out.println(helper(arr,n,k));
 	}
 	static int helper(int[]arr, int n, int k){
 		int[] preSum = new int[n];
 		HashMap<Integer,Integer> map = new HashMap<>();
 		int cnt = 0;
 		preSum[0] = arr[0];
 		for(int i=1;i<n;i++){
 			preSum[i] = preSum[i-1]+arr[i];
 		}
 		map.put(0,1);
 		for(int i=0;i<n;i++){
 			int modFreq = (preSum[i]%k-i%k+k)%k;
 			cnt+= map.getOrDefault(modFreq,0);
 			map.put(modFreq,map.getOrDefault(modFreq,0)+1);
 		}
 		
 		return cnt;
 	}
}