#include <stdio.h>

#define MAXN    100000
#define INF     1000000000

int v[MAXN];
int c[MAXN];
int p[MAXN];
int total[MAXN];
int need[MAXN];
int people[MAXN];

int n, tmp;

void qs(int l, int h) {
    int r = v[(l + h) / 2];
    int i = l;
    int j = h;

    while (i <= j) {
        while (v[i] > r) i++;
        while (v[j] < r) j--;
        if (i <= j) {
            tmp = p[i];
            p[i] = p[j];
            p[j] = tmp;

            tmp = v[i];
            v[i] = v[j];
            v[j] = tmp;

            tmp = c[i];
            c[i] = c[j];
            c[j] = tmp;

            i++;
            j--;
        }
    }
    if (l < j) qs(l, j);
    if (i < h) qs(i, h);
}

void print() {
    int i;

    for (i = 0; i < n; i++) {
        printf("%d", people[i]);
        if (i + 1 < n)
            printf(" ");
    }

    printf("\n");
}

int main() {
    long long int sum, curSum;
    int i, k, l, h, t;
    int cur, diff, ans, ansi, rest;

    freopen("elect.in", "r", stdin);
    freopen("elect.out", "w", stdout);

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d %d", &v[i], &c[i]);
        p[i] = i;
    }

    qs(0, n - 1);
    sum = 0;
    for (i = 0; i < n; i++) {
        sum = sum + v[i];
        curSum = sum - (i + 1) * ((long long int) v[i]);
        total[i] = (curSum > INF) ? INF : curSum;
    }

    need[0] = v[0];
    if ((n > 1) && (v[0] == v[1])) {
        need[0] = v[0] + 1;
    }

    for (i = 1; i < n; i++) {
        l = 0;
        h = i;
        while (l + 1 < h) {
            t = (l + h) / 2;
            if (total[t] + v[i] > v[t])
                h = t;
            else
                l = t;
        }

        cur = v[i] + total[l];
        diff = v[l] - cur;
        k = l + 1;

        t = diff / (k + 1);
        rest = diff % (k + 1);
        cur = cur + t * k + ((rest < k) ? (rest + 1) : k);
        need[i] = cur;
    }

    ans = INF;
    ansi = -1;
    for (i = 0; i < n; i++) {
        if ((c[i] != -1) && (need[i] - v[i] + c[i] < ans)) {
            ans = need[i] - v[i] + c[i];
            ansi = i;
        }
    }

    if (ansi == 0) {
        printf("%d\n", ans);
        printf("%d\n", p[ansi] + 1);
        for (i = 0; i < n; i++) {
            people[p[i]] = v[i];
        }
        if (need[0] > people[p[0]]) {
            people[p[0]]++;
            people[p[1]]--;
        }
        print();
        return 0;
    }

    l = 0;
    h = ansi;
    while (l + 1 < h) {
        t = (l + h) / 2;
        if (total[t] + v[ansi] > v[t])
            h = t;
        else
            l = t;
    }

    cur = v[ansi] + total[l];
    diff = v[l] - cur;
    k = l + 1;

    t = diff / (k + 1);
    rest = diff % (k + 1);
    rest = ((rest < k) ? (rest + 1) : k);
    cur = cur + t * k + rest;

    printf("%d\n", ans);
    printf("%d\n", p[ansi] + 1);

    for (i = 0; i < n; i++) {
        people[p[i]] = v[i];
    }

    for (i = 0; i <= l; i++) {
        people[p[i]] = people[p[l]] - t;
    }

    for (i = 0; i < rest; i++) {
        people[p[i]]--;
    }

    people[p[ansi]] = cur;
    print();
    return 0;
}
