#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int BASE = 1e9 + 7;
int N, S[MAXN], G[MAXN], A[MAXN], result[MAXN];
void read_input() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> S[i] >> G[i];
  }
}
void solve() {
  long long res = 0;
  int _min = S[1], _max = S[1] + G[1];
  result[1] = S[1] + G[1];
  for (int i = 2; i <= N; i++) {
    int x = S[i], y = S[i] + G[i];
    _min = max(_min - 1, x);
    _max = min(_max + 1, y);
    result[i] = _max;
    if (_min > _max) {
      cout << -1 << endl;
      return;
    }
  }
  int value = result[N];
  res += value - S[N];
  A[N] = value;
  for (int i = N - 1; i >= 1; i--) {
    value = min(result[i], value + 1);
    A[i] = value;
    res += value - S[i];
  }
  cout << res << endl;
  for (int i = 1; i < N; i++) {
    cout << A[i] << " ";
  }
  cout << A[N] << endl;
}
void execute() {
  int test = 1;
  for (int i = 1; i <= test; i++) {
    read_input();
    solve();
  }
}
int main() {
  execute();
  return 0;
}
