#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

long long countSubarrays(const vector<long long>& nums, int k) {
    // A subarray size must be >= 1. If it must also be < k, 
    // then k must be at least 2 for any valid subarray to exist.
    if (k <= 1) return 0;

    unordered_map<int, int> freq;
    vector<int> history; 
    
    long long ans = 0;
    long long prefix_sum = 0;

    // Base case: represents the "empty" prefix sum before index 0.
    // Our formula groups the terms as: (Prefix_Sum - Index) % k
    // For the empty prefix: Sum is 0, Index is -1.
    // Key = (0 - (-1)) % k = 1 % k.
    int base_key = 1 % k;
    freq[base_key]++;
    history.push_back(base_key);

    for (int i = 0; i < nums.size(); ++i) {
        prefix_sum += nums[i];

        // Sliding window logic: 
        // The maximum valid subarray length is k - 1. 
        // If our current index i >= k - 1, the prefix at index (i - k + 1) in our 
        // history array is now too far away and must be removed from the active map.
        if (i >= k - 1) {
            int key_to_remove = history[i - k + 1];
            freq[key_to_remove]--;
        }

        // Calculate the current key: (P[i] - i) % k
        long long val = (prefix_sum - i) % k;
        
        // C++ modulo on negative numbers yields a negative result.
        // We wrap it securely to guarantee a positive key.
        if (val < 0) {
            val = (val + k) % k;
        }
        
        int current_key = val;

        // If we've seen this key in our active sliding window, it forms a valid subarray
        ans += freq[current_key];

        // Record the current key in the map and history for future iterations
        freq[current_key]++;
        history.push_back(current_key);
    }

    return ans;
}
int main() {
    vector<pair<vector<long long>, int>> test_cases = {
        {{-2, 1}, 3},
        {{1, 1, 1}, 3},
        {{5, 10, 15}, 1},
        {{4, 4, 4}, 4},
        {{1000000001, 1000000001}, 5}
    };

    for (int i = 0; i < test_cases.size(); ++i) {
        long long result = countSubarrays(test_cases[i].first, test_cases[i].second);
        cout << "Case " << i + 1 << " Answer: " << result <<endl;
    }

    return 0;
}