#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ll;
typedef vector<long long> vl;
typedef vector<ll> vll;
typedef vector<vl> vvl;
template <typename T>
ostream &operator<<(ostream &o, vector<T> v) {
  if (v.size() > 0) o << v[0];
  for (unsigned i = 1; i < v.size(); i++) o << " " << v[i];
  return o << "\n";
}
template <typename U, typename V>
ostream &operator<<(ostream &o, pair<U, V> p) {
  return o << "(" << p.first << ", " << p.second << ") ";
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (unsigned i = 0; i < v.size(); i++) in >> v[i];
  return in;
}
template <typename T>
istream &operator>>(istream &in, pair<T, T> &p) {
  in >> p.first;
  in >> p.second;
  return in;
}
int main() {
  long long n, a, b, arr[200100], ans;
  vll ve, pos;
  cin >> n;
  for (long long i = (0); i < (long long)n; i++) {
    cin >> a >> b;
    ve.push_back((make_pair((a), (b))));
  }
  a = ve[0].first;
  b = ve[0].second + ve[0].first;
  pos.push_back((make_pair((a), (b))));
  for (long long i = (1); i < (long long)n; i++) {
    if (ve[i].first + ve[i].second < a &&
        abs(ve[i].first + ve[i].second - a) >= 2) {
      cout << "-1";
      return 0;
    }
    if (ve[i].first > b && abs(ve[i].first - b) >= 2) {
      cout << "-1";
      return 0;
    }
    a = max(ve[i].first, a - 1);
    b = min(b + 1, ve[i].first + ve[i].second);
    pos.push_back((make_pair((a), (b))));
  }
  ans = 0;
  arr[n - 1] = b;
  ans += abs(ve[n - 1].first - arr[n - 1]);
  for (long long i = (n - 2); i >= (0); i--) {
    arr[i] = min(arr[i + 1] + 1, pos[i].second);
    ans += abs(ve[i].first - arr[i]);
  }
  cout << ans << "\n";
  for (long long i = (0); i < (long long)n; i++) cout << arr[i] << " ";
  return 0;
}
