Link to this code: https://cses.fi/paste/35d45c2a32ca0fd42babf7/
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	
	ll n,k;
	cin >> n >> k;
	vector < ll > v(n);
	for(ll i=0; i<n ; i++) cin >> v[i];
	map<ll ,ll> prevSum;
	int currSum = 0 , res = 0;
	for(ll i=0; i<n ; ++i)
	{
		currSum += v[i];
		if(currSum == k) res++;
		if(prevSum.count(currSum - k))
		{
			res += prevSum[currSum - k];
		} 
		prevSum[currSum]++;
	}
	cout << res << '\n';
	
	return 0;
}