#include <bits/stdc++.h>
using namespace std;
const int maxn = 4 * 100005;
char s[maxn];
int n;
vector<pair<int, int> > v;
pair<int, int> f[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    v.push_back(pair<int, int>(a, a + b));
  }
  int l = v[0].first, r = v[0].second;
  f[0] = pair<int, int>(l, r);
  for (int i = 1; i < n; ++i) {
    cerr << l << " " << r << "\n";
    l = max(l - 1, v[i].first), r = min(r + 1, v[i].second);
    f[i] = pair<int, int>(l, r);
    if (l > r) {
      return puts("-1");
    }
  }
  long long tot = 0;
  vector<int> res;
  res.push_back(f[n - 1].second);
  tot += f[n - 1].second - v[n - 1].first;
  int lst = f[n - 1].second;
  for (int i = n - 2; i >= 0; --i) {
    res.push_back(min(f[i].second, lst + 1));
    tot += (long long)(1LL * res.back() - v[i].first);
    lst = res.back();
  }
  reverse((res).begin(), (res).end());
  cout << tot << "\n";
  for (int i = 0; i < ((int)((res).size())); i++) {
    printf("%d ", res[i]);
  }
  puts("");
}
