#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  long long int n;
  cin >> n;
  vector<long long int> s(n), g(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i] >> g[i];
  }
  vector<long long int> x(n), y(n);
  x[0] = s[0] + g[0];
  for (int i = 1; i < n; ++i) {
    x[i] = min(x[i - 1] + 1, s[i] + g[i]);
  }
  y[n - 1] = g[n - 1] + s[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    y[i] = min(y[i + 1] + 1, s[i] + g[i]);
  }
  for (int i = 0; i < n; ++i) {
    x[i] = min(x[i], y[i]);
  }
  if (x[0] < s[0]) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < n; ++i) {
    if (abs(x[i] - x[i - 1]) > 1 || x[i] < s[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += abs(x[i] - s[i]);
  }
  cout << ans << endl;
  for (int i = 0; i < n; ++i) {
    cout << x[i] << " ";
  }
  cout << endl;
  return 0;
}
