#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  int arr[n];
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, x + y});
    arr[i] = x;
  }
  bool is = 1;
  for (int i = 1; i < n; i++) {
    int s = max(v[i].first, v[i - 1].first - 1);
    int e = min(v[i].second, v[i - 1].second + 1);
    if (s > e) {
      is = 0;
    }
    v[i] = {s, e};
  }
  long long sum = 0;
  for (int i = n - 2; i >= 0; i--) {
    int s = max(v[i].first, v[i + 1].first - 1);
    int e = min(v[i].second, v[i + 1].second + 1);
    if (s > e) {
      is = 0;
    }
    v[i] = {s, e};
  }
  for (int i = 0; i < n; i++) {
    sum += v[i].second - arr[i];
  }
  if (!is) {
    return cout << -1, 0;
  }
  cout << sum << '\n';
  for (int i = 0; i < n; i++) {
    cout << v[i].second << ' ';
  }
  return 0;
}
