#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), sum(N + 1, 0);
    rep(i, N) { cin >> A[i]; }

    map<ll, ll> cnt;
    ll ans = 0;
    rep(i, N) { sum[i + 1] = sum[i] + A[i]; }

    rep(i, N + 1) { cnt[sum[i] % M]++; }

    for (auto c : cnt) {
        ans += (c.second * (c.second - 1)) / 2;
    }

    cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N=200000;

int n,m,a[N+9];
int cnt[N+9];

bool Get_a(){
  for (int i=1;i<=n;++i) cnt[i]=0;
  for (int i=1;i<=n;++i){
	int l=max(i-a[i],1),r=min(i+a[i],n);
	++cnt[l];--cnt[r+1];
  }
  for (int i=1;i<=n;++i) a[i]=cnt[i]+=cnt[i-1];
  for (int i=1;i<=n;++i)
	if (a[i]<n) return 0;
  return 1;
}

int main(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
  for (int i=1;i<=m;++i)
	if (Get_a()) break;
  for (int i=1;i<=n;++i)
	printf("%d ",a[i]);
  puts("");
  return 0;
}