import java.io.*;
import java.util.*;

public class elect_is implements Runnable {
    private static final String FILENAME = elect_is.class.getName().substring(0, elect_is.class.getName().indexOf('_'));
    
    File inFile = new File(FILENAME + ".in");
    PrintWriter out;
    BufferedReader in;

    private StringTokenizer st;

    elect_is() {     
        try {
            in = new BufferedReader(new FileReader(inFile));
            st = new StringTokenizer(in.readLine());
            out = new PrintWriter(new File(FILENAME + ".out"));
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(239);           
        }       
    }
    
    int nextInt() throws IOException {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }
    
    class C implements Comparator<Integer> {
        long[] v;
        int[] p;
        C(long[] v, int[] p) {
            this.v = v;
            this.p = p;
        }
        public int compare(Integer o1, Integer o2) {
            int t = Long.signum(v[o2] - v[o1]);
            if (t == 0) {
                return (((p[o2] == -1) ? (int)1e7 : p[o2]) 
                      - ((p[o1] == -1) ? (int)1e7 : p[o1])); 
            } else
                return t;
        }
    }
    
    
    public void run() {
        try {
            int n = nextInt();
            int i;
            long[] v = new long[n];
            int[] p = new int[n];            
            for (i = 0; i < n; i++) {               
                v[i] = nextInt();
                p[i] = nextInt();               
            }
            Integer[] r = new Integer[n];
            for (i = 0; i < n; i++)
                r[i] = i;
            Arrays.sort(r, new C(v, p));
            long[] ps = new long[n];
            ps[0] = 0;
            for (i = 1; i < n; i++)
                ps[i] = ps[i - 1] + v[r[i - 1]];
            
//            int[] vs = v.clone();
//            Arrays.sort(vs);
//            ArrayList<Integer> vv = new ArrayList<Integer>();
//            for (int I : vs)
//              vv.add(I);
//            Collections.reverse(vv);
            
            long res = Integer.MAX_VALUE;
            int resi = -1;
            long resLevel = -1;
            for (i = 0; i < n; i++) {
                while (i < n - 1 && v[r[i + 1]] == v[r[i]]) {                   
                    i++;
                }
                int I = r[i];
                if (p[I] == -1) {
                    continue;
                }
                int lb = 0;
                int rb = i;
                while (lb + 1 < rb) {
                    int x = (lb + rb) / 2;
//                  ps[x] - v[r[x]] * x + v[I] > v[r[x]
                    if (ps[x] + v[I] > v[r[x]] * (x + 1)) {
                        rb = x;
                    } else {
                        lb = x;
                    }
                }
                long d = (ps[rb] + v[I]) / (rb + 1);
                if (d * (rb + 1) == (ps[rb] + v[I]))
                    d--;
                
                long ng;
                {
                    int ln = 0;
                    int rn = rb;
                    while (ln + 1 < rn) {
                        int xn = (ln + rn) / 2;
                        if (v[r[xn]] > d) {
                            ln = xn;
                        } else {
                            rn = xn;
                        }
                    }
                    ng = ln + 1;
                }
                
                long z = (ps[rb] - d * rb) + v[I];
                ng = Math.min(ng, Math.max(0, z - Math.max((d + 2), v[r[rb]])));
                z -= ng;
                long t = p[I] + z - v[I];
                
                if (res > t) {
                    res = t;
                    resi = I;
                    resLevel = d;
                }
            }
            out.println(res);
            out.println(resi + 1);
            if (p[resi] == -1) {
                throw new RuntimeException("Buying honest party");
            }
            long nres = p[resi];
            
            for (long rl : new long[]{resLevel + 1, resLevel}) {
                for (int j = 0; j < n; j++) {
                    if (r[j] == resi || v[r[j]] < v[resi] || v[r[j]] <= rl)
                        break;
                    v[resi] += v[r[j]] - rl;
                                    
                    nres += v[r[j]] - rl;
                    
                    v[r[j]] = rl;                         
                }
            }            
            
            if (nres != res) {
                throw new RuntimeException("Wrong money calc");
            }
            for (int j = 0; j < n; j++) {
                out.print(v[j] + " ");              
            }
            out.println();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
        
                
    }
    
    public static void main(String[] args) {
        new Thread(new elect_is()).start();
    }

}