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

public class missions_av_fact {

	FastScanner in;
	PrintWriter out;
	final String fileName = "missions".toLowerCase();

	void solve() {
		final Task[] t = readTasks();
		int n = t.length;
		
		class AllPermsGenerator {
			int n;
			boolean[] used;
			int[] p;
			
			int[] bestOrder;
			long bestAns = Long.MAX_VALUE;
			
			public AllPermsGenerator(int n) {
				this.n = n;
				used = new boolean[n];
				p = new int[n];
			}
			
			public void generate() {
				gen(0);
			}
			
			private void gen(int i) {
				if (i == n) {
					long curAns = getAns(t, p);
					if (curAns < bestAns) {
						bestOrder = p.clone();
						bestAns = curAns;
					}
					
					return;
				}
				for (int j = 0; j < n; j++) {
					if (!used[j]) {
						p[i] = j;
						used[j] = true;
						gen(i + 1);
						used[j] = false;
					}
				}
			}
		}
		AllPermsGenerator gen = new AllPermsGenerator(n);
		gen.generate();
		
		out.println(gen.bestAns);
		for (int i : gen.bestOrder) {
			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_fact().run();
	}
}
