#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[1000002];
pair<int, int> ans[1000002];
vector<int> vec;
int n;
int main() {
  cin >> n;
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  int pmin = a[0].first, pmax = a[0].first + a[0].second;
  ans[0].first = pmin;
  ans[0].second = pmax;
  for (int i = 1; i < n; i++) {
    int curmin = a[i].first, curmax = a[i].first + a[i].second;
    if (pmin - 1 > curmax or pmax + 1 < curmin) {
      flag = 1;
      break;
    }
    pmin = max(pmin - 1, curmin);
    pmax = min(pmax + 1, curmax);
    ans[i].first = pmin;
    ans[i].second = pmax;
  }
  if (flag)
    cout << -1 << endl;
  else {
    long long sum = ans[n - 1].second - a[n - 1].first,
              previ = ans[n - 1].second;
    vec.emplace_back(previ);
    for (int i = n - 2; i >= 0; i--) {
      if (ans[i].second >= previ + 1) {
        sum += (previ + 1) - a[i].first;
        previ++;
      } else if (ans[i].second == previ)
        sum += previ - a[i].first;
      else {
        sum += (previ - 1) - a[i].first;
        previ--;
      }
      vec.emplace_back(previ);
    }
    reverse(vec.begin(), vec.end());
    cout << sum << endl;
    for (int i = 0; i < n; i++) {
      cout << vec[i] << " ";
    }
  }
  return 0;
}
