#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int s[N], g[N], n, f[N];
int main(int argc, const char **argv) {
  if (argc >= 2) {
    freopen(argv[1], "r", stdin);
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &s[i], &g[i]);
    f[i] = s[i] + g[i];
    if (i) {
      if (s[i - 1] + g[i - 1] > s[i] + g[i]) {
        f[i - 1] = s[i] + g[i] + 1;
      } else if (s[i - 1] + g[i - 1] < s[i] + g[i]) {
        f[i] = s[i - 1] + g[i - 1] + 1;
      }
    }
    f[i] = min(f[i], s[i] + g[i]);
  }
  auto smoothen_backward = [&]() {
    for (int i = n - 2; i >= 0; i--) {
      if (f[i] > f[i + 1]) {
        f[i] = f[i + 1] + 1;
      } else if (f[i] < f[i + 1]) {
        f[i + 1] = f[i] + 1;
      }
    }
  };
  auto smoothen_forward = [&]() {
    for (int i = 1; i < n; i++) {
      if (f[i - 1] > f[i]) {
        f[i - 1] = f[i] + 1;
      } else if (f[i - 1] < f[i]) {
        f[i] = f[i - 1] + 1;
      }
    }
  };
  smoothen_backward();
  for (int i = 0; i < 2; i++) {
    smoothen_forward();
    smoothen_backward();
  }
  bool flag = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] - s[i] < 0 || f[i] - s[i] > g[i]) {
      flag = 1;
    }
    ans += (f[i] - s[i]);
  }
  if (flag == false) {
    cout << ans << endl;
    for (int i = 0; i < n; i++) {
      printf("%d ", f[i]);
    }
  } else {
    cout << -1 << endl;
  }
}
