#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
long long n;
long long a[400000], mn[400000], mx[400000];
void solve(long long i, long long l, long long r) {
  l = max(l, mn[i]);
  r = min(r, mx[i]);
  if (l > r) {
    cout << -1;
    exit(0);
  }
  if (i == n) {
    a[i] = r;
    return;
  }
  solve(i + 1, l - 1, r + 1);
  a[i] = min(r, a[i + 1] + 1);
  if (a[i] < l || abs(a[i] - a[i + 1]) > 1) {
    cout << -1;
    exit(0);
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> mn[i] >> mx[i];
    mx[i] += mn[i];
  }
  solve(1, -1e9, 1e9);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += a[i] - mn[i];
    if (a[i] > mx[i] || a[i] < mn[i]) {
      cout << -1;
      return (0);
    }
  }
  cout << ans << '\n';
  for (long long i = 1; i <= n; i++) cout << a[i] << ' ';
}
