#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n;
int l[N], r[N], tim, tag[N];
bool vis[N];
priority_queue<pair<int, pair<int, int> > > stk;
void add(int p) { stk.push(make_pair(-r[p], make_pair(p, tag[p] = ++tim))); }
void solve() {
  for (int i = (0); i < (n); ++i) add(i);
  for (int i = (0); i < (n); ++i) {
    while (vis[stk.top().second.first] ||
           tag[stk.top().second.first] != stk.top().second.second)
      stk.pop();
    int u = stk.top().second.first;
    stk.pop();
    vis[u] = true;
    if (u - 1 >= 0) r[u - 1] = min(r[u - 1], r[u] + 1), add(u - 1);
    if (u + 1 < n) r[u + 1] = min(r[u + 1], r[u] + 1), add(u + 1);
  }
  for (int i = (0); i < (n); ++i)
    if (r[i] < l[i]) {
      puts("-1");
      return;
    }
  long long cut = 0;
  for (int i = (0); i < (n); ++i) cut += r[i] - l[i];
  printf("%lld\n", cut);
  for (int i = (0); i < (n); ++i) printf("%d%c", r[i], " \n"[i == n - 1]);
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d%d", &l[i], &r[i]), r[i] += l[i];
  solve();
  return 0;
}
