#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-9;
const int inf = 1 << 30;
int n, a[200005], b[200005], a0[200005];
bool nivelar(int i, int j) {
  if (!i || !j || i == n + 1 || j == n + 1) return false;
  if (a[i] - b[i] > a[j] + 1) {
    cout << -1 << '\n';
    exit(0);
  }
  if (a[i] > a[j] + 1) {
    int x = (a[i] - a[j] - 1);
    a[i] -= x;
    b[i] -= x;
    return true;
  }
  return false;
}
void solve(int l, int r) {
  if (l == r) return;
  int piv = (l + r) >> 1;
  solve(l, piv);
  solve(piv + 1, r);
  if (a[piv] > a[piv + 1] + 1)
    for (int i = piv; i >= l; i--) nivelar(i, i + 1);
  else if (a[piv + 1] > a[piv] + 1)
    for (int i = piv + 1; i <= r; i++) nivelar(i, i - 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    a0[i] = a[i];
    a[i] += b[i];
  }
  solve(1, n);
  long long sol = 0;
  for (int i = 1; i <= n; i++) sol += a[i] - a0[i];
  cout << sol << '\n';
  for (int i = 1; i <= n; i++) cout << a[i] << " \n"[i == n];
  return 0;
}
