#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int oldRoad[300000];
  int maxRoad[300000];
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    oldRoad[i] = x;
    maxRoad[i] = x + y;
  }
  for (int i = 0; i < n - 1; i++) {
    if (maxRoad[i + 1] - maxRoad[i] > 1) maxRoad[i + 1] = maxRoad[i] + 1;
  }
  for (int i = n - 1; i > 0; i--) {
    if (maxRoad[i - 1] - maxRoad[i] > 1) maxRoad[i - 1] = maxRoad[i] + 1;
  }
  bool check = true;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (maxRoad[i] < oldRoad[i])
      check = false;
    else {
      ans += (long long)maxRoad[i] - (long long)oldRoad[i];
    }
  }
  if (check) {
    cout << ans << endl;
    for (int i = 0; i < n; i++) {
      cout << maxRoad[i] << " ";
    }
  } else
    cout << -1;
  return 0;
}
