#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long n, m, s[N], g[N], len;
long long x[N], y[N], ans[N];
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &s[i], &g[i]);
  }
  x[1] = s[1], y[1] = s[1] + g[1];
  for (long long i = 2; i <= n; i++) {
    if (x[i - 1] - 1 > s[i] + g[i]) {
      cout << -1;
      return 0;
    }
    if (y[i - 1] + 1 < s[i]) {
      cout << -1;
      return 0;
    }
    x[i] = max(s[i], x[i - 1] - 1);
    y[i] = min(s[i] + g[i], y[i - 1] + 1);
  }
  ans[n] = y[n];
  for (long long i = n - 1; i >= 1; i--) {
    ans[i] = min(y[i], ans[i + 1] + 1);
  }
  long long sum = 0;
  for (long long i = 1; i <= n; i++) sum += ans[i] - s[i];
  cout << sum << endl;
  for (long long i = 1; i <= n; i++) cout << ans[i] << ' ';
  return 0;
}
