//|Art|
#include<iostream>
#include <chrono>
//#include <algorithm>
//#include <cmath>
//#include <climits>
//#include <numeric>
//#include <set>
//#include <unordered_set>
//#include <stack>
//#include <string>
//#include <iomanip>
//#include <vector>
//#include <deque>
//#include <queue>
//#include <unordered_map>
#include <map>
//#include <list>
//#include <bits/stdc++.h>
#define inout() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define el cout << '\n'
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ll long long
#define st string
#define N 100000
#define sz(x) (x).size()
#define all(v) (v).begin(), (v).end()
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#define FORE(a,b,c) for(int a=b;a>=c;--a)
#define __Art__ signed main()
#define NAME "Art"
using namespace std;
int n, k;
ll m;
void inp (){
cin >> n >> m >> k;
}
/*st binpow (st a, st b, st mod){
}*/
void sub1(){
map<int, int> mp;
int a[n + 1], res = 0;
res = a[0] = 0;
FOR (i, 1, n) cin >> a[i], a[i] = (a[i - 1] + a[i] % k) % k, res += mp[a[i]], ++mp[a[i]];
FOR (i, 1, n) cout << a[i] << ' ';
cout << res;
}
__Art__{
if (fopen(NAME".INP", "r")) {
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
inout();
inp();
if (m == 1) sub1();
//else if (m <= 1e3) sub2();
// else sub3();
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return (0 ^ 0);
}
Ci8vfEFydHwKI2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlIDxjaHJvbm8+Ci8vI2luY2x1ZGUgPGFsZ29yaXRobT4KLy8jaW5jbHVkZSA8Y21hdGg+Ci8vI2luY2x1ZGUgPGNsaW1pdHM+Ci8vI2luY2x1ZGUgPG51bWVyaWM+Ci8vI2luY2x1ZGUgPHNldD4KLy8jaW5jbHVkZSA8dW5vcmRlcmVkX3NldD4KLy8jaW5jbHVkZSA8c3RhY2s+Ci8vI2luY2x1ZGUgPHN0cmluZz4KLy8ja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