#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int l[N], r[N];
int ans[N];
int main() {
  int n;
  long long sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &l[i], &r[i]), r[i] += l[i], sum += l[i];
  for (int i = 2; i <= n; i++) {
    l[i] = max(l[i], l[i - 1] - 1);
    r[i] = min(r[i], r[i - 1] + 1);
  }
  for (int i = n - 1; i > 0; i--) {
    l[i] = max(l[i], l[i + 1] - 1);
    r[i] = min(r[i], r[i + 1] + 1);
  }
  ans[0] = r[1];
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (l[i] <= ans[i - 1] + 1 && ans[i - 1] + 1 <= r[i])
      ans[i] = ans[i - 1] + 1;
    else if (l[i] <= ans[i - 1] && ans[i - 1] <= r[i])
      ans[i] = ans[i - 1];
    else if (l[i] <= ans[i - 1] - 1 && ans[i - 1] - 1 <= r[i])
      ans[i] = ans[i - 1] - 1;
    else
      return 0 * puts("-1");
    res += ans[i];
  }
  printf("%lld\n", res - sum);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
