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