#include <bits/stdc++.h>
using namespace std;
int s[1001000];
int g[1001000];
int ans[1001000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> g[i];
    ans[i] = 1001000;
  }
  ans[0] = s[0] + g[0];
  for (int i = 0; i < n - 1; i++) {
    ans[i + 1] = min(g[i + 1] + s[i + 1], ans[i] + 1);
  }
  for (int i = n - 1; i > 0; i--) {
    ans[i - 1] = min(ans[i] + 1, ans[i - 1]);
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += ans[i] - s[i];
    if (ans[i] < s[i]) {
      cout << -1;
      return 0;
    }
  }
  cout << sum << endl;
  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  return 0;
}
