#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 201000;
int n, s[N], g[N], ret[N], tot[N];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", s + i, g + i);
    ret[i] = tot[i] = s[i] + g[i];
  }
  int mv = tot[0];
  for (int i = 0; i < n; i++) {
    mv = min(mv, tot[i] - i);
    ret[i] = min(ret[i], mv + i);
  }
  mv = tot[n - 1] + (n - 1);
  for (int i = n - 1; i >= 0; i--) {
    mv = min(mv, tot[i] + i);
    ret[i] = min(ret[i], mv - i);
  }
  for (int i = 0; i < n; i++) {
    if (ret[i] < s[i]) {
      puts("-1");
      return 0;
    }
    ans += ret[i] - s[i];
  }
  printf("%lld\n", ans);
  for (int i = 0; i < n; i++) printf("%d ", ret[i]);
  puts("");
}
