#include <bits/stdc++.h>
using namespace std;
const int CMAX = 1e6 + 10;
const int MX = 1e9;
set<int> pos[2 * CMAX];
pair<int, int> arr[CMAX];
int ans[CMAX];
int main() {
  memset(ans, -1, sizeof(ans));
  int n;
  cin >> n;
  int mx = MX;
  for (int i = 0; i < n; i++) {
    int s, g;
    cin >> s >> g;
    arr[i] = {s, g};
    pos[s + g].insert(i);
    mx = min(mx, s + g);
  }
  for (int i = 0; i < 2 * CMAX; i++) {
    for (auto ii : pos[i]) {
      int lft = ii - 1;
      int rgt = ii + 1;
      if (ans[ii] == -1) {
        ans[ii] = min(arr[ii].second + arr[ii].first, i + 1);
      }
      if (lft >= 0 && ans[lft] == -1) {
        ans[lft] = min(arr[lft].second + arr[lft].first, i + 1);
        pos[ans[lft]].insert(lft);
      }
      if (rgt < n && ans[rgt] == -1) {
        ans[rgt] = min(arr[rgt].second + arr[rgt].first, i + 1);
        pos[ans[rgt]].insert(rgt);
      }
    }
    pos[i].clear();
  }
  long long ss = 0;
  for (int i = 0; i < n; i++) {
    if (i > 0)
      if (abs(max(ans[i], arr[i].first) - max(ans[i - 1], arr[i - 1].first)) >
          1) {
        cout << -1;
        return 0;
      }
    ss += max(ans[i], arr[i].first) - arr[i].first;
  }
  cout << ss << endl;
  for (int i = 0; i < n; i++) {
    cout << max(ans[i], arr[i].first) << " ";
  }
  return 0;
}
