#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, l[200100], r[200100], L[200100], R[200100];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    l[i] = read();
    r[i] = read();
    r[i] += l[i];
  }
  L[0] = R[n + 1] = 1e9 + 10;
  for (int i = 1; i <= n; i++) L[i] = min(r[i], L[i - 1] + 1);
  for (int i = n; i >= 1; i--) R[i] = min(r[i], R[i + 1] + 1);
  long long ans = 0, f = 0;
  for (int i = 1; i <= n; i++) {
    if (min(L[i], R[i]) < l[i]) f = 1;
    ans += min(L[i], R[i]) - l[i];
  }
  if (f) {
    puts("-1");
    return 0;
  }
  printf("%I64d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", min(L[i], R[i]));
  return 0;
}
