#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int read() {
  int ret = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  for (; ch >= '0' && ch <= '9'; ch = getchar()) ret = ret * 10 + ch - '0';
  return ret;
}
const int INF = 0x3f3f3f3f;
const int MAX_N = 2e5 + 10;
int l[MAX_N], r[MAX_N], s[MAX_N], g[MAX_N], tot[MAX_N], ans[MAX_N], n;
long long sum = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", s + i, g + i);
    tot[i] = s[i] + g[i];
  }
  l[0] = INF;
  for (int i = 1; i <= n; i++) {
    l[i] = min(l[i - 1] + 1, tot[i]);
  }
  r[n + 1] = INF;
  for (int i = n; i >= 1; i--) {
    r[i] = min(r[i + 1] + 1, tot[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = min(r[i], l[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (ans[i] < s[i]) {
      puts("-1");
      return 0;
    }
    sum += (long long)(ans[i] - s[i]);
  }
  printf("%lld\n", sum);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
