#include <bits/stdc++.h>
const int N = 2e6 + 5;
const long double Pi = 3.141592653;
const long long mod = 1e9 + 7;
const long long Mod = 998244353;
const long long Inf = 4e18;
using namespace std;
int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) {
    long long n, ans = 0;
    cin >> n;
    vector<long long> a(n), b(n), x(n), y(n), s(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    x[0] = a[0] + b[0];
    y[n - 1] = a[n - 1] + b[n - 1];
    for (int i = 1; i < n; i++) x[i] = min(x[i - 1] + 1, a[i] + b[i]);
    for (int i = n - 2; i >= 0; i--) y[i] = min(y[i + 1] + 1, a[i] + b[i]);
    for (int i = 0; i < n; i++) {
      s[i] = min(x[i], y[i]);
      if (s[i] < a[i]) {
        cout << -1;
        return 0;
      } else
        ans += (s[i] - a[i]);
    }
    cout << ans << "\n";
    for (int i = 0; i < n; i++) cout << s[i] << " ";
  }
  return 0;
}
