#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
long long ans, c[N], a[N];
vector<pair<int, int> > v[N], store;
int main() {
  scanf("%d%d", &n, &m);
  long long k = n / m, x = 0, res = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a + i);
    v[a[i] % m].push_back({a[i], i});
  }
  for (int i = 0; i < m; ++i) c[i] = (int)v[i].size() - k;
  for (int i = 1; i < m; ++i) c[i] += c[i - 1];
  for (int i = 0; i < n; ++i) x = min(x, c[i]);
  for (int i = 0; i < m; ++i) c[i] -= x, res += c[i];
  printf("%lld\n", res);
  int st = 0;
  for (int i = 0; i < m; ++i)
    if (c[i] == 0) {
      st = i;
      break;
    }
  st = (st + 1) % m;
  for (int time = 0; time < m; ++time) {
    while (store.size() < c[st]) {
      pair<int, int> t = v[st].back();
      v[st].pop_back();
      store.push_back({t.first - time, t.second});
    }
    while (store.size() > c[st]) {
      pair<int, int> t = store.back();
      store.pop_back();
      v[st].push_back({t.first + time, t.second});
    }
    st = (st + 1) % m;
  }
  for (int i = 0; i < m; ++i)
    for (auto &t : v[i]) a[t.second] = t.first;
  for (int i = 0; i < n; ++i) printf("%d ", a[i]);
  puts("");
  return 0;
}
