#include <bits/stdc++.h>
using namespace std;
int n;
int a[220000];
int s[220000];
int g[220000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", s + i, g + i);
    a[i] = s[i] + g[i];
  }
  for (int i = 0; i < n - 1; ++i) a[i + 1] = min(a[i + 1], a[i] + 1);
  for (int i = n - 1; i > 0; --i) a[i - 1] = min(a[i - 1], a[i] + 1);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] < s[i]) {
      printf("-1\n");
      return 0;
    }
    ans += a[i] - s[i];
  }
  printf("%lld\n", ans);
  for (int i = 0; i < n; ++i) printf("%d ", a[i]);
  printf("\n");
  return 0;
}
