#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 3e5 + 10;
int s[N], g[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> g[i];
    g[i] += s[i];
  }
  for (int i = 2; i <= n; i++) {
    if (g[i] > g[i - 1]) g[i] = g[i - 1] + 1;
  }
  for (int i = n - 1; i > 0; i--) {
    if (g[i] > g[i + 1]) g[i] = g[i + 1] + 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (g[i] < s[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans += g[i] - s[i];
  }
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", g[i]);
  return 0;
}
