#include <bits/stdc++.h>
const long long N = 2e5 + 5;
long long n, ans;
long long f[N], g[N], sum[N];
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while ('0' > ch or ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
  while ('0' <= ch and ch <= '9') x = x * 10 + ch - 48, ch = getchar();
  return x * f;
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++)
    f[i] = read(), g[i] = read(), sum[i] = f[i] + g[i];
  for (long long i = 2; i <= n; i++) sum[i] = std::min(sum[i], sum[i - 1] + 1);
  for (long long i = n - 1; i >= 1; i--)
    sum[i] = std::min(sum[i + 1] + 1, sum[i]);
  for (long long i = 1; i <= n; i++)
    if (f[i] > sum[i])
      return puts("-1"), 0;
    else
      ans += sum[i] - f[i];
  printf("%lld\n", ans);
  for (long long i = 1; i <= n; i++) printf("%lld ", sum[i]);
  return 0;
}
