#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, s[N], g[N], ans[N];
int peak[N], ind[N], top;
int query(int q) { return peak[top - 1] - (q - ind[top - 1]); }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &s[i], &g[i]);
  peak[top] = s[0] + g[0];
  ind[top] = 0;
  ++top;
  for (int i = 1; i < n; ++i) {
    int target = s[i] + g[i];
    while (top >= 1 && target < query(i - 1) - 1) {
      --top;
      if (top > 0 && peak[top] - 1 > query(ind[top])) {
        peak[top++] -= 1;
      }
    }
    if (top == 0) {
      peak[top] = min(peak[top], target + i);
      ind[top] = 0;
      ++top;
    }
    int q = query(i - 1);
    if (target >= q) {
      peak[top] = min(target, q + 1);
      ind[top] = i;
      ++top;
    } else {
      assert(query(i) == target);
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (ind[top - 1] == i) {
      ans[i] = peak[top - 1];
      --top;
    } else {
      ans[i] = query(i);
    }
  }
  bool ok = true;
  long long su = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] < s[i] || ans[i] > s[i] + g[i]) ok = false;
    su += ans[i] - s[i];
    if (i > 0) assert(abs(ans[i] - ans[i - 1]) <= 1);
  }
  if (!ok) return printf("-1\n"), 0;
  cout << su << '\n';
  for (int i = 0; i < n; ++i) {
    if (i) cout << ' ';
    cout << ans[i];
  }
  cout << endl;
}
