#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int mp[maxn];
int s[maxn], g[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    mp[i] = u + v;
    s[i] = u;
    g[i] = v;
    if (i > 0 && mp[i] > mp[i - 1]) mp[i] = mp[i - 1] + 1;
  }
  for (int i = n - 2; i >= 0; i--) {
    if (mp[i] > mp[i + 1]) mp[i] = mp[i + 1] + 1;
  }
  long long total = 0;
  int f = 1;
  for (int i = 0; i < n; i++) {
    if (mp[i] < s[i])
      f = 0;
    else {
      total += mp[i] - s[i];
    }
  }
  if (f == 0)
    printf("-1\n");
  else {
    printf("%lld\n", total);
    for (int i = 0; i < n; i++) {
      printf("%d", mp[i]);
      if (i != n - 1) printf(" ");
    }
    printf("\n");
  }
}
