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

public class elect_md implements Runnable {
	class Party implements Comparable<Party> {
		int a, price, id;
		
		public Party(String s, int i) {
			StringTokenizer st = new StringTokenizer(s);
			a = Integer.parseInt(st.nextToken());
			price = Integer.parseInt(st.nextToken());
			id = i;
			if (price < 0)
				price = infty;
		}

		public int compareTo(Party that) {
			if (a == that.a)
				return price - that.price;
			return that.a - a;
		}
	}

	private BufferedReader in;
	private PrintWriter out;
	
	int infty = Integer.MAX_VALUE / 2;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws IOException {
		in = new BufferedReader(new FileReader("elect.in"));
		out = new PrintWriter("elect.out");
		int n = Integer.parseInt(in.readLine());
		Party[] p = new Party[n];
		for (int i = 0; i < n; i++) {
			p[i] = new Party(in.readLine(), i);
		}
		Arrays.sort(p);
		int best = p[0].price;
		if (n > 1 && p[0].a == p[1].a)
			best++;
		int bwho = 0;
		int bhow = -1;
		int aboveL = 0;
		int buy = 0;
		int i = 0;
		for (int L = Math.min(p[0].a, 1000000); L >= 0; L--) {
			while (aboveL < n && p[aboveL].a > L)
				aboveL++;
			buy += aboveL;
			int wins = L + 1 - buy;
			while (i < n && p[i].a >= wins) {
				int cur = buy + p[i].price;
				if (p[i].a > L) {
					cur -= p[i].a - L;
				}
				if (cur < best) {
					best = cur;
					bwho = i;
					bhow = L;
				}
				i++;
			}
		}
		out.println(best);
		out.println(p[bwho].id + 1);
		int[] ans = new int[n];
		if (bhow < 0) {
			if (n > 1 && p[0].a == p[1].a) {
				p[0].a++;
				p[1].a--;
			}
			for (i = 0; i < n; i++) {
				ans[p[i].id] = p[i].a;
			}
		} else {
			ans[p[bwho].id] = p[bwho].a;
			for (i = 0; i < n; i++) {
				if (i == bwho)
					continue;
				if (p[i].a > bhow) {
					ans[p[bwho].id] += p[i].a - bhow;
					ans[p[i].id] = bhow;
					continue;
				}
				ans[p[i].id] = p[i].a;
			}
		}
		System.out.println("bhow = " + bhow);
		for (int x : ans)
			out.print(x + " ");
		out.println();
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(new elect_md()).run();
	}

}
