#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int s[maxn], g[maxn];
int l[maxn], r[maxn];
int ans[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> g[i];
    if (i == 0) {
      l[i] = s[i];
      r[i] = s[i] + g[i];
    } else {
      l[i] = max(l[i - 1] - 1, s[i]);
      r[i] = min(r[i - 1] + 1, s[i] + g[i]);
    }
    if (l[i] > r[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  ans[n - 1] = r[n - 1];
  long long res = (long long)ans[n - 1] - s[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    if (ans[i + 1] + 1 <= r[i]) {
      ans[i] = ans[i + 1] + 1;
    } else if (ans[i + 1] <= r[i]) {
      ans[i] = ans[i + 1];
    } else
      ans[i] = ans[i + 1] - 1;
    res += (long long)ans[i] - s[i];
  }
  cout << res << endl;
  cout << ans[0];
  for (int i = 1; i < n; i++) {
    cout << " " << ans[i];
  }
  cout << endl;
  return 0;
}
