#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
const int oo = 1000000000;
int n, s[N], g[N], v[N], l[N], r[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &s[i], &g[i]);
    v[i] = s[i] + g[i];
  }
  int ls = oo;
  for (int i = 0; i < n; ++i) {
    ls = min(v[i], ls + 1);
    l[i] = ls;
  }
  ls = oo;
  for (int i = n - 1; i >= 0; --i) {
    ls = min(v[i], ls + 1);
    r[i] = ls;
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int d = min(l[i], r[i]);
    if (d < s[i]) return cout << -1 << endl, 0;
    ans += d - s[i];
  }
  cout << ans << endl;
  for (int i = 0; i < n; ++i) printf("%d ", min(l[i], r[i]));
  puts("");
}
