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