#include <bits/stdc++.h>
using namespace std;
int n;
int L[2001111], R[200111];
int last[200111];
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a, b;
    cin >> a >> b;
    L[i] = a;
    R[i] = a + b;
  }
  int now = R[1];
  last[1] = now;
  for (int i = 2; i <= n; i++) {
    if (now + 1 < L[i]) {
      cout << -1 << "\n";
      return 0;
    }
    if (now + 1 > R[i])
      last[i] = R[i];
    else
      last[i] = now + 1;
    now = last[i];
  }
  now = last[n];
  for (int i = n - 1; i >= 1; i--) {
    if (now + 1 < L[i]) {
      cout << -1 << "\n";
      return 0;
    }
    if (now + 1 < last[i])
      last[i] = now + 1;
    else if (abs(now - last[i]) > 1) {
      cout << -1 << "\n";
      return 0;
    }
    now = last[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += last[i] - L[i];
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) cout << last[i] << " ";
  cout << "\n";
  return 0;
}
