#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const long double pi = acos(-1.0);
const int N = 2e5 + 100;
int tr[4 * N];
int inicial[N];
int v[4 * N];
int n;
void build(int node, int b, int e) {
  if (b == e)
    tr[node] = b;
  else {
    int mid = (b + e) / 2;
    build(2 * node, b, mid);
    build(2 * node + 1, mid + 1, e);
    if (v[tr[2 * node]] > v[tr[2 * node + 1]]) {
      tr[node] = tr[2 * node + 1];
    } else {
      tr[node] = tr[2 * node];
    }
  }
}
void update(int node, int b, int e, int i, int val) {
  if (i < b or i > e) return;
  if (b == e) {
    if (v[b] > val) v[b] = val + 1;
    return;
  }
  int mid = (b + e) / 2;
  update(2 * node, b, mid, i, val);
  update(2 * node + 1, mid + 1, e, i, val);
  if (v[tr[2 * node]] > v[tr[2 * node + 1]]) {
    tr[node] = tr[2 * node + 1];
  } else {
    tr[node] = tr[2 * node];
  }
}
int query(int node, int b, int e, int i, int j) {
  if (i > e or j < b) return -1;
  if (i <= b and j >= e) return tr[node];
  int mid = (b + e) / 2;
  int p1 = query(2 * node, b, mid, i, j);
  int p2 = query(2 * node + 1, mid + 1, e, i, j);
  if (p1 == -1) return p2;
  if (p2 == -1) return p1;
  if (v[p1] < v[p2]) return p1;
  return p2;
}
void conserta(int x) {
  if (x - 1 >= 1) {
    update(1, 1, n, x - 1, v[x]);
  }
  if (x + 1 <= n) {
    update(1, 1, n, x + 1, v[x]);
  }
}
void solve(int b, int e) {
  if (b > e) return;
  int x = query(1, 1, n, b, e);
  conserta(x);
  solve(b, x - 1);
  solve(x + 1, e);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    inicial[i] = x;
    v[i] = x + y;
  }
  build(1, 1, n);
  solve(1, n);
  long long resp = 0;
  bool pau = false;
  for (int i = 1; i <= n; i++) {
    resp += v[i] - inicial[i];
    if (inicial[i] > v[i]) pau = true;
  }
  if (pau) {
    printf("%d\n", -1);
  } else {
    cout << resp << endl;
    for (int i = 1; i < n; i++) printf("%d ", v[i]);
    printf("%d\n", v[n]);
  }
  return 0;
}
