#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	// int pid[] = {1,2,3,4};
	int arr[] = {2,1,3,2,4}; // k-3 ans=3
	int n = 5;
	int k=3;
	
	int pid[n+1];
	int p[n];
	
	for(int i=1; i<=n; i++){
		pid[i]=arr[i-1];
		p[i]=p[i-1]+arr[i];
	}
	
	
	
	unordered_map<int, int> mp;
	
	
	int count=0;
	mp[0] = 1;
	
	
	
	for(int j=1; j<n; j++){
		
		
		
		int t=(p[j]%k -j%k + k)%k;
		
		
		cout<<"chosen for position- " << j << " target: "<< t << endl;
		
		cout<<"mp[t]: " << mp[t]<< endl;
		if(mp.find(t)!=mp.end()){
			count += mp[t];	
		}
		
		
		cout<< "count is now: " << count<<endl;
		
		mp[t]++;
		
		
	}
	
	cout<<count;
	return 0;
}