#include <bits/stdc++.h>
using namespace std;
long long n, m, num[200001], sum[200001], ans;
set<int> s;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) s.insert(i);
  for (int i = 0; i < n; i++) {
    int d, tmp;
    cin >> num[i];
    d = num[i] % m;
    if (d > *s.rbegin())
      tmp = *s.begin();
    else
      tmp = *s.lower_bound(d);
    sum[tmp]++;
    if (sum[tmp] == n / m) s.erase(tmp);
    int s = (tmp - d + m) % m;
    ans += s;
    num[i] += s;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << num[i] << " ";
  return 0;
}
