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

public class missions_av {

	FastScanner in;
	PrintWriter out;
	final String fileName = "missions";
	
	void solve() {
		Task[] t = readTasks();
		int n = t.length;
		
		int maxP = 0, maxS = 0;
		for (int i = 1; i < n; i++) {
			if (t[i].pain > t[maxP].pain) {
				maxP = i;
			}
			if (t[i].suffering > t[maxS].suffering) {
				maxS = i;
			}
		}
		
		int[] order = new int[n];
		for (int i = 0; i < n; i++) {
			order[i] = i;
		}
		if (maxP == maxS) {
			order[0] = maxP;
			order[maxP] = 0;
		} else {
			order[0] = maxP;
			order[1] = maxS;
			for (int i = 0, tmp = 2; i < n; i++) {
				if (i != maxP && i != maxS) {
					order[tmp++] = i;
				}
			}
			if (t[maxP].suffering > t[maxS].pain) {
				order[0] = maxS;
				order[1] = maxP;
			}
		}
		
		out.println(getAns(t, order));
		for (int i : order) {
			out.print((i + 1) + " ");
		}
	}
	
	class Task {
		int pain, suffering;
		int id;
		public Task(int pain, int suffering, int id) {
			super();
			this.pain = pain;
			this.suffering = suffering;
			this.id = id;
		}
	}
	
	long getAns(Task[] tasks, int[] order) {
		int maxPain = 0, maxSuffering = 0;
		long result = 0;
		for (int i : order) {
			Task t = tasks[i];
			
			if (t.pain > maxPain) {
				result += t.pain;
				maxPain = t.pain;
			}
			
			if (t.suffering > maxSuffering) {
				result += t.suffering;
				maxSuffering = t.suffering;
			}
		}
		return result;
	}
	
	Task[] readTasks() {
		int n = in.nextInt();
		Task[] t = new Task[n];
		for (int i = 0; i < n; i++) {
			t[i] = new Task(in.nextInt(), in.nextInt(), i);
		}
		return t;
	}

	void run() {
		try {
			in = new FastScanner(fileName + ".in");
			out = new PrintWriter(fileName + ".out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

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