#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<int> v;
vector<int> u;
void solve(int l, int r) {
  if (l == r) {
    a[l] = v[l];
    return;
  }
  int m = (l + r) >> 1;
  solve(l, m);
  solve(m + 1, r);
  if (a[m] < a[m + 1]) {
    for (int i = m + 1; i <= r; i++) {
      if (abs(a[i] - a[i - 1]) > 1) {
        a[i] = a[i - 1] + 1;
        if (u[i] <= a[i] && a[i] <= v[i]) {
        } else {
          printf("-1\n");
          exit(0);
        }
      } else
        break;
    }
  } else {
    for (int i = m; i >= l; i--) {
      if (abs(a[i + 1] - a[i]) > 1) {
        a[i] = a[i + 1] + 1;
        if (u[i] <= a[i] && a[i] <= v[i]) {
        } else {
          printf("-1\n");
          exit(0);
        }
      } else {
        break;
      }
    }
  }
}
int main(int argc, char const* argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a.push_back(x);
    u.push_back(x);
    v.push_back(x + y);
  }
  solve(0, n - 1);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i];
    ans -= u[i];
  }
  printf("%lld\n", ans);
  for (int i = 0; i < n; i++) {
    printf("%d ", a[i]);
  }
  printf("\n");
  return 0;
}
