#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int s[maxn], g[maxn];
long long top[maxn], bot[maxn];
int n = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", s + i, g + i);
  }
  top[1] = s[1] + g[1];
  for (int i = 2; i <= n; i++) {
    if (s[i] + g[i] > top[i - 1] + 1)
      top[i] = top[i - 1] + 1;
    else {
      top[i] = s[i] + g[i];
    }
  }
  for (int i = n - 1; i >= 1; i--) {
    if (top[i] > top[i + 1] + 1) top[i] = top[i + 1] + 1;
  }
  bot[1] = s[1];
  for (int i = 2; i <= n; i++) {
    if (s[i] < bot[i - 1] - 1)
      bot[i] = bot[i - 1] - 1;
    else {
      bot[i] = s[i];
    }
  }
  for (int i = n - 1; i >= 1; i--) {
    if (bot[i] < bot[i + 1] - 1) bot[i] = bot[i + 1] - 1;
  }
  bool hasans = true;
  for (int i = 1; i <= n; i++) {
    if (bot[i] > top[i]) {
      hasans = false;
    }
  }
  if (!hasans) {
    printf("-1\n");
    return 0;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += top[i] - s[i];
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    cout << top[i] << " ";
  }
  printf("\n");
  return 0;
}
