#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define stop system("pause")
#define sz(x) (int)(x.size())
#define all(x) begin(x),end(x)
#define lla(x) x.rbegin(),x.rend()
using ll = long long;using vi = vector<int>;
#define debug(v) cout<<#v<<":";cout<<v<<endl
using pii = pair<int, int>;const int MX = 1e6 + 10;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,b) for(register int i=0,i##len=(int)(b);i< i##len;++i)
#define rpp(i,b) for(register int i=1,i##len=(int)(b);i<=i##len;++i)
template <typename T> istream& operator>>(istream &is,vector<T> &v) {for(auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template <typename T> ostream& operator<<(ostream &os,const vector<T> &v) {for(auto i = begin(v);i!=end(v);i++) os<<*i<<(i==end(v)-1?"\n":" ");return os;}
template<typename T>inline void rd(T &s){s=0;T t=1,k=getchar();for(;k<'0'||k>'9';k=getchar())if (k=='-')t=-1;for(;k>='0'&&k<='9';k=getchar())s=(s<<1)+(s<<3)+(k^48);s*=t;}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


int a[MX],sum[MX];
inline void solve()
{
    int n,k;cin>>n>>k;
    rpp(i,n) cin>>a[i];
    rpp(i,n) sum[i]=sum[i-1]+a[i];
    rpp(i,n) sum[i]=(sum[i]-i)%k;
    map<int,int>mp;
    ++mp[0];
    ll ans=0;
    rpp(i,n)
    {
        ans+=mp[sum[i]];
        ++mp[sum[i]];
    }
    cout<<ans<<endl;
}
signed main()
{
    solve();

}