#include <bits/stdc++.h>
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
struct interval {
  int l, r;
};
inline interval intersect(interval a, interval b) {
  return {std::max(a.l, b.l), std::min(a.r, b.r)};
}
inline interval extend(const interval& a) { return {a.l - 1, a.r + 1}; }
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  int s[n], g[n];
  for (int i = 0; i < n; i++) std::cin >> s[i] >> g[i];
  interval possible[n];
  possible[0] = {s[0], s[0] + g[0]};
  for (int i = 1; i < n; i++)
    possible[i] = intersect(extend(possible[i - 1]), {s[i], s[i] + g[i]});
  for (int i = 0; i < n; i++) {
    if (possible[i].l > possible[i].r) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  int value[n];
  value[n - 1] = possible[n - 1].r;
  long long sum = 0;
  for (int i = n - 2; i >= 0; i--)
    value[i] = std::min(value[i + 1] + 1, possible[i].r);
  for (int i = 0; i < n - 1; i++) {
    if (std::abs(value[i] - value[i + 1]) > 1) {
      std::cout << -1 << std::endl;
      return 0;
    }
    sum += (value[i] - s[i]);
  }
  sum += value[n - 1] - s[n - 1];
  std::cout << sum << std::endl;
  for (int i = 0; i < n; i++) std::cout << value[i] << " ";
  return 0;
}
