#include <bits/stdc++.h>
using namespace std;
struct node {
  int val;
  node *l, *r;
};
int n;
int a[200005];
int s[200005], g[200005];
int res[200005];
long long ans = 0;
node *root;
node *buildSeg(int l, int r) {
  node *t = new node();
  if (l == r) {
    t->val = a[l];
    return t;
  }
  t->l = buildSeg(l, (l + r) / 2);
  t->r = buildSeg((l + r) / 2 + 1, r);
  t->val = min(t->l->val, t->r->val);
  return t;
}
int q(node *t, int l, int r, int st, int ed) {
  if (st <= l && r <= ed) return t->val;
  int mid = (l + r) / 2;
  int res = 10000000;
  if (st <= mid) res = min(res, q(t->l, l, mid, st, ed));
  if (mid + 1 <= ed) res = min(res, q(t->r, mid + 1, r, st, ed));
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &s[i], &g[i]);
    a[i] = s[i] + g[i] + i;
  }
  root = buildSeg(1, n);
  int cur = 2000000;
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    cur = min(cur + 1, q(root, 1, n, i, n) - i);
    res[i] = cur;
    ans += cur - s[i];
    if (cur < s[i]) {
      flag = false;
      break;
    }
  }
  if (!flag)
    printf("-1\n");
  else {
    printf("%lld\n", ans);
    for (int i = 1; i <= n; i++) printf("%d ", res[i]);
  }
  return 0;
}
