#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1e4;
long long a[maxn], s[maxn], g[maxn];
long long sx, sy;
int n, x;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &s[i]);
    scanf("%I64d", &g[i]);
  }
  for (int i = 0; i < n; i++) {
    sx += s[i];
    a[i] = s[i] + g[i];
  }
  int mn = 0;
  for (int i = mn + 1; i < n; i++) {
    if (a[i] >= a[mn] + i - mn) {
      a[i] = a[mn] + i - mn;
    } else {
      mn = i;
    }
  }
  mn = n - 1;
  for (int i = mn - 1; i >= 0; i--) {
    if (a[i] >= a[mn] + mn - i) {
      a[i] = a[mn] + mn - i;
    } else {
      mn = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] < s[i]) {
      printf("%s", "-1");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) sy += a[i];
  printf("%I64d", sy - sx);
  printf("%s", "\n");
  for (int i = 0; i < n; i++) {
    printf("%d", a[i]);
    printf("%s", " ");
  }
  return 0;
}
