#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
ll const maxn = 2e5 + 10;
using namespace std;
ll a[maxn];
ll b[maxn];
int main(void) {
  ll n, m;
  set<int> s;
  int i;
  cin >> n >> m;
  int cnt = n / m;
  ll ans = 0;
  for (i = 0; i < m; i++) s.insert(i);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    int r = a[i] % m;
    if (r <= *s.rbegin())
      r = *s.lower_bound(r);
    else
      r = *s.begin();
    b[r]++;
    if (b[r] == cnt) s.erase(r);
    ans += (r - a[i] % m + m) % m;
    a[i] += (r - a[i] % m + m) % m;
  }
  cout << ans << '\n';
  for (i = 0; i < n; i++) cout << (i != 0 ? " " : "") << a[i];
  cout << '\n';
  return 0;
}
