#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<LL> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i] - i;
}
priority_queue<LL> max_heap;
for (int i = 0; i < n; i++) {
max_heap.push(b[i]);
if (max_heap.top() > b[i]) {
max_heap.pop();
max_heap.push(b[i]);
}
b[i] = max_heap.top();
}
for (int i = n - 2; i >= 0; i--) {
if (b[i] > b[i + 1]) {
b[i] = b[i + 1];
}
}
LL total = 0;
for (int i = 0; i < n; i++) {
total += abs(a[i] - (b[i] + i));
}
cout << total << "\n";
for (int i = 0; i < n; i++) {
if (i) cout << " ";
cout << b[i] + i;
}
cout << endl;
return 0;
}