Problem: Little Janet likes playing with cubes. Actually, she likes to play with anything whatsoever, cubes or tesseracts, as long as they are multicolored. Each cube is described by two parameters — color ci and size si. A Zebra Tower is a tower that consists of cubes of exactly two colors. Besides, the colors of the cubes in the tower must alternate (colors of adjacent cubes must differ). The Zebra Tower should have at least two cubes. There are no other limitations. The figure below shows an example of a Zebra Tower.

<image>

A Zebra Tower's height is the sum of sizes of all cubes that form the tower. Help little Janet build the Zebra Tower of the maximum possible height, using the available cubes.

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of cubes. Next n lines contain the descriptions of the cubes, one description per line. A cube description consists of two space-separated integers ci and si (1 ≤ ci, si ≤ 109) — the i-th cube's color and size, correspondingly. It is guaranteed that there are at least two cubes of different colors.

Output

Print the description of the Zebra Tower of the maximum height in the following form. In the first line print the tower's height, in the second line print the number of cubes that form the tower, and in the third line print the space-separated indices of cubes in the order in which they follow in the tower from the bottom to the top. Assume that the cubes are numbered from 1 to n in the order in which they were given in the input.

If there are several existing Zebra Towers with maximum heights, it is allowed to print any of them. 

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples

Input

4
1 2
1 3
2 4
3 3


Output

9
3
2 3 1 


Input

2
1 1
2 1


Output

2
2
2 1 

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main implements Runnable {

	public void _main() throws IOException {
		int n = nextInt();
		Cube[] c = new Cube[n];
		for (int i = 0; i < n; i++) {
			int col = nextInt();
			int size = nextInt();
			c[i] = new Cube(size, col, i);
		}
		Arrays.sort(c);
		Map<Integer, Integer> startPos = new HashMap<Integer, Integer>();
		long[] best = new long[n + 2];
		Arrays.fill(best, -1);
		int[] bestCol = new int[n + 2];
		Arrays.fill(bestCol, -1);
		long[] cur = new long[n + 2]; // total height for current colour
		int pos = 0;
		int prevCol = -1;
		long globalBest = -1;
		int bestCol1 = -1;
		int bestCol2 = -1;
		int bestSize1 = -1;
		int bestSize2 = -1; // bs2 <= bs1 <= bs2 + 1
		for (int i = 0; i < n; i++) {
			if (c[i].col != prevCol) {
				startPos.put(c[i].col, i);
				for (int j = 0; j < pos; j++) {
					if (best[j] < cur[j]) {
						best[j] = cur[j];
						bestCol[j] = prevCol;
					}
				}
				prevCol = c[i].col;
				pos = 0;
			}
			if (pos > 0)
				cur[pos] = cur[pos - 1];
			else
				cur[pos] = 0;
			cur[pos] += c[i].height;
			if (globalBest < cur[pos] + best[pos] && bestCol[pos] != -1) {
				globalBest = cur[pos] + best[pos];
				bestCol1 = c[i].col;
				bestCol2 = bestCol[pos];
				bestSize1 = pos + 1;
				bestSize2 = pos + 1;
			}
			if (pos > 0 && globalBest < cur[pos] + best[pos - 1] && bestCol[pos - 1] != -1) {
				globalBest = cur[pos] + best[pos - 1];
				bestCol1 = c[i].col;
				bestCol2 = bestCol[pos - 1];
				bestSize1 = pos + 1;
				bestSize2 = pos;
			}
			if (globalBest < cur[pos] + best[pos + 1] && bestCol[pos + 1] != -1) {
				globalBest = cur[pos] + best[pos + 1];
				bestCol1 = bestCol[pos + 1];
				bestCol2 = c[i].col;
				bestSize1 = pos + 2;
				bestSize2 = pos + 1;
			}
			pos++;
		}
		long height = 0;
		int[] res = new int[bestSize1 + bestSize2];
		for (int i = 0; i < bestSize1; i++) {
			int sp = startPos.get(bestCol1);
			res[2 * i] = c[sp + i].id;
			height += c[sp + i].height;
		}
		for (int i = 0; i < bestSize2; i++) {
			int sp = startPos.get(bestCol2);
			res[2 * i + 1] = c[sp + i].id;
			height += c[sp + i].height;
		}
		out.println(height);
		out.println(res.length);
		for (int i = 0; i < res.length; i++)
			out.print((res[i] + 1) + " ");
	}

	class Cube implements Comparable<Cube> {
		int height, col, id;
		Cube(int size, int col, int id) {
			this.height = size;
			this.col = col;
			this.id = id;
		}
		public int compareTo(Cube o) {
			if (col != o.col)
				return col - o.col;
			return o.height - height;
		}
	}


	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

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

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

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

	public static void main(String[] args) {
		Locale.setDefault(Locale.UK);
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			//in = new BufferedReader(new FileReader("a.in"));
			//out = new PrintWriter(new FileWriter("a.out"));

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}