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

int main() 
{
    //AtMost K -> we are doing that we are finding the longest subarray for the current window 
    
    int n=5;
    int a[] = {1,11,2,3,15};
    int k=10;   //sum<=k

    int cnt = 0; 
    int sum = 0;

    int i=0 , j=0;

    while(j<n)
    {
        // do calculation
        sum = sum + a[j]; // running sum find out kela 

        if(sum<=k)  //  if the sum is less than equal to k 
        {
            // finding ans <- from calculation 
            cnt = cnt + (j-i+1);  // keep counting the subarray 

            j++; // keep on moving 'j' pointer when sum <= k
        }
        else if(sum>k)
        {
            while(i<=j  &&  sum>k) // This while loop will run until the sum>k
            {
                sum = sum - a[i]; // we will start  removing the ' i ' index element from the window

                i++; // we will increment the ' i ' pointer 
            }
            //after coming from this while loop there can only two possibilities 
            //Edge case -> why this edge case??
            // 1. possibility -> current sum <=k 
            //2.  possibility -> sum==0 or the sum!=0
            if(sum<=k  &&  sum!=0) // so when sum<=k and sum!=0 we have go our subarrays 
            {
                cnt = cnt + (j-i+1); // again keep on counting the subarrays 

                j++;
            }
            else if(sum==0)
            {
                j++;
            }
        }
    }
    cout<<cnt<<" ";
}
