#include <bits/stdc++.h>
using namespace std;
int n, a[300000], b[300000];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    b[i] += a[i];
  }
  for (int i = 2; i <= n; i++) b[i] = min(b[i], b[i - 1] + 1);
  for (int i = n - 1; i > 0; i--) b[i] = min(b[i], b[i + 1] + 1);
  long long sum = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] > b[i]) {
      cout << "-1";
      return 0;
    } else
      sum += b[i] - a[i];
  cout << sum << endl;
  for (int i = 1; i <= n; i++) cout << b[i] << " ";
  return 0;
}
