#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
pair<int, int> a[N];
pair<int, int> ra[N];
int ans[N];
pair<int, int> cross(pair<int, int> a, pair<int, int> b) {
  if (a > b) swap(a, b);
  return pair<int, int>(b.first, min(a.second, b.second));
}
void solve() {
  ra[n] = pair<int, int>(a[n].first, a[n].first + a[n].second);
  for (int i = n - 1; i >= 1; i--) {
    ra[i] = cross(pair<int, int>(ra[i + 1].first - 1, ra[i + 1].second + 1),
                  pair<int, int>(a[i].first, a[i].first + a[i].second));
    if (ra[i].first > ra[i].second) {
      cout << "-1";
      return;
    }
  }
  ans[1] = ra[1].second;
  for (int i = 2; i <= n; i++) {
    pair<int, int> cur =
        cross(pair<int, int>(ans[i - 1] - 1, ans[i - 1] + 1), ra[i]);
    ans[i] = cur.second;
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) sum += ans[i] - a[i].first;
  cout << sum << '\n';
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].first, &a[i].second);
  solve();
}
