#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  scanf("%i", &n);
  vector<int> s(n + 1), g(n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%i %i", &s[i], &g[i]);
  }
  priority_queue<pair<int, int>> Q;
  for (int i = 1; i <= n; i++) {
    Q.push(make_pair(-s[i] - g[i], i));
  }
  vector<int> ans(n + 2, int(1e9));
  set<int> pos;
  ans[0] = ans[n + 1] = int(1e9);
  pos.insert(0);
  pos.insert(n + 1);
  for (int j = 1; j <= n; j++) {
    int idx = Q.top().second;
    Q.pop();
    auto it = pos.lower_bound(idx);
    int left = *(--it);
    it = pos.upper_bound(idx);
    int right = *it;
    ans[idx] = min(s[idx] + g[idx],
                   min(ans[left] + idx - left, ans[right] + right - idx));
    pos.insert(idx);
  }
  for (int i = 1; i <= n; i++) {
    if (ans[i] < s[i]) {
      puts("-1");
      return 0;
    }
  }
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    tot += ans[i] - s[i];
  }
  printf("%lld\n", tot);
  for (int i = 1; i <= n; i++) {
    printf("%i%c", ans[i], (i == n) ? '\n' : ' ');
  }
  return 0;
}
