#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 1;
long long a[MAXN];
vector<long long> mod[MAXN];
long long n, m, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  long long length = n / m;
  vector<long long> ext;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mod[a[i] % m].push_back(i);
  }
  for (int _ = 0; _ < 2; _++) {
    for (int i = 0; i < m; i++) {
      while (mod[i].size() > length) {
        ext.push_back(mod[i].back());
        mod[i].pop_back();
      }
      while (ext.size() && mod[i].size() < length) {
        int t = ext.back();
        ext.pop_back();
        a[t] += (i - a[t] % m + m) % m;
        mod[i].push_back(t);
      }
      k += ext.size();
    }
  }
  cout << k << endl;
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
