#include <bits/stdc++.h>
using namespace std;
long long int n, s[200005], g[200005], val[200005], ini;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int i, j, k;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i] >> g[i];
    ini += s[i];
    val[i] = s[i] + g[i];
  }
  for (i = 2; i <= n; i++) {
    val[i] = min(val[i], 1 + val[i - 1]);
  }
  for (i = n - 1; i >= 1; i--) {
    val[i] = min(val[i], 1 + val[i + 1]);
  }
  long long int fg = 1;
  long long int ff = 0;
  for (i = 1; i <= n; i++) {
    if (val[i] < s[i]) fg = 0;
    ff += val[i];
  }
  for (i = 1; i < n; i++) {
    if (abs(val[i] - val[i + 1]) > 1) fg = 0;
  }
  if (fg == 0)
    cout << "-1\n";
  else {
    cout << ff - ini << "\n";
    for (i = 1; i <= n; i++) cout << val[i] << " ";
  }
  return 0;
}
