#include <bits/stdc++.h>
using namespace std;
int n, s[1000000], g[1000000], t[1000000];
bitset<1000000> v;
vector<int> st[2000001];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i] >> g[i], st[s[i] + g[i]].push_back(i);
  queue<int> q;
  for (int th = 0; th <= 2000000; th++) {
    for (int i : st[th])
      if (!v[i]) q.push(i), t[i] = s[i] + g[i], v[i] = true;
    while (!q.empty() && t[q.front()] == th) {
      int i = q.front();
      q.pop();
      if (i > 0 && !v[i - 1]) v[i - 1] = true, t[i - 1] = th + 1, q.push(i - 1);
      if (i < n - 1 && !v[i + 1])
        v[i + 1] = true, t[i + 1] = th + 1, q.push(i + 1);
    }
  }
  bool possible = true;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    possible = possible && t[i] >= s[i];
    sum += t[i] - s[i];
  }
  if (!possible)
    cout << -1 << "\n";
  else {
    cout << sum << "\n";
    for (int i = 0; i < n; i++) cout << t[i] << (i < n - 1 ? " " : "\n");
  }
}
