#include <bits/stdc++.h>
using namespace std;
long long int div_floor(const long long int &a, const long long int &b) {
  return a / b - (((a ^ b) < 0) and a % b);
}
long long int div_ceil(const long long int &a, const long long int &b) {
  return a / b + (((a ^ b) >= 0) and a % b);
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> s(n), g(n);
  for (long long int i = 0; i < n; i++) cin >> s[i] >> g[i];
  vector<long long int> sf(n, 0);
  set<long long int> pres;
  vector<pair<long long int, long long int> > lawns(n);
  for (long long int i = 0; i < n; i++) lawns[i] = {s[i] + g[i], i};
  sort(lawns.begin(), lawns.end());
  for (long long int i = 0; i < n; i++) {
    long long int width = lawns[i].first;
    long long int idx = lawns[i].second;
    auto it = pres.lower_bound(idx);
    if (it != pres.end()) {
      long long int fidx = *it;
      width = min(width, sf[fidx] + fidx - idx);
    }
    if (it != pres.begin()) {
      it--;
      long long int bidx = *it;
      width = min(width, sf[bidx] + idx - bidx);
    }
    sf[idx] = width;
    pres.insert(idx);
  }
  for (int i = 0; i < n; i++)
    if (sf[i] < s[i]) {
      cout << -1 << '\n';
      return;
    }
  long long int ans = 0;
  for (int i = 0; i < n; i++) ans += sf[i] - s[i];
  cout << ans << '\n';
  for (auto &e : sf) cout << e << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) solve();
}
