#include <bits/stdc++.h>
using namespace std;
long long int mod(long long int a, long long int b) {
  a = a % b;
  if (a < 0) a += b;
  return a;
}
int main() {
  long long int i, j, k, l, n, test_case, m, val, cnt = 0;
  test_case = 1;
  while (test_case--) {
    cin >> n >> m;
    long long int arr[n + 1];
    long long int brr[m + 1];
    val = n / m;
    list<long long int> vec[200001];
    long long int ori[n + 1];
    memset(brr, 0, sizeof brr);
    for (i = 0; i < n; i++) {
      cin >> arr[i];
      ori[i] = arr[i];
      brr[arr[i] % m]++;
      vec[arr[i] % m].push_back(i);
    }
    list<long long int> sto;
    for (j = 0; j < m; j++) {
      i = j;
      if (brr[i] < val) {
        while (sto.size() > 0 && brr[i] < val) {
          brr[i]++;
          vec[i].push_back(sto.front());
          sto.pop_front();
        }
      } else if (brr[i] > val) {
        while (brr[i] > val) {
          brr[i]--;
          sto.push_back(vec[i].front());
          vec[i].pop_front();
        }
      }
    }
    for (j = 0; j < m; j++) {
      i = j;
      if (brr[i] < val) {
        while (sto.size() > 0 && brr[i] < val) {
          brr[i]++;
          vec[i].push_back(sto.front());
          sto.pop_front();
        }
      } else if (brr[i] > val) {
        while (brr[i] > val) {
          brr[i]--;
          sto.push_back(vec[i].front());
          vec[i].pop_front();
        }
      }
    }
    for (i = 0; i < m; i++) {
      for (auto it : vec[i]) {
        if (mod(arr[it], m) == i)
          continue;
        else {
          arr[it] += mod(i - arr[it], m);
          if (arr[it] % m != i) {
            while (1) {
              cout << ".";
            }
          }
        }
      }
    }
    for (i = 0; i < n; i++) {
      if (arr[i] < ori[i]) {
        while (1) {
          cout << "..";
        }
      }
      cnt += arr[i] - ori[i];
    }
    cout << cnt << "\n";
    for (i = 0; i < n; i++) {
      cout << arr[i] << " ";
    }
  }
  return 0;
}
