#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long r[maxn], g[maxn];
long long mini[maxn], maxi[maxn];
int n;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i] >> g[i];
  }
  mini[0] = r[0], maxi[0] = r[0] + g[0];
  for (int i = 1; i < n; i++) {
    mini[i] = max(mini[i - 1] - 1, r[i]);
    maxi[i] = min(maxi[i - 1] + 1, r[i] + g[i]);
    if (mini[i] > maxi[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    mini[i] = max(mini[i + 1] - 1, mini[i]);
    maxi[i] = min(maxi[i + 1] + 1, maxi[i]);
    if (mini[i] > maxi[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (maxi[i] - r[i]);
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    cout << maxi[i] << " ";
  }
  cout << endl;
  return 0;
}
