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 ZebraTowers {

	final String filename = new String("ZebraTowers").toLowerCase();

	class Cube implements Comparable<Cube> {
		int size, color, id;

		public Cube(int size, int color, int id) {
			this.size = size;
			this.color = color;
			this.id = id;
		}
		
		@Override
		public int compareTo(Cube o) {
			if (size != o.size) {
				return o.size - size;
			}
			return id - o.id;
		}
	}

	void solve() throws Exception {
		int n = nextInt();
		int[] size = new int[n];
		int[] color = new int[n];
		TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			color[i] = nextInt();
			size[i] = nextInt();
			tm.put(color[i], 0);
		}
		int tmp = 0;
		for (int i : tm.keySet()) {
			tm.put(i, tmp++);
		}
		for (int i = 0; i < n; i++) {
			color[i] = tm.get(color[i]);
		}
		int colorsCount = tm.size();
		
		final ArrayList<Cube>[] cubes = new ArrayList[colorsCount];
		for (int i = 0; i < colorsCount; i++) {
			cubes[i] = new ArrayList<ZebraTowers.Cube>();
		}
		
		for (int i = 0; i < n; i++) {
			cubes[color[i]].add(new Cube(size[i], color[i], i + 1));
		}
		
		Integer[] indices = new Integer[colorsCount];
		for (int i = 0; i < colorsCount; i++) {
			Collections.sort(cubes[i]);
			indices[i] = i;
		}
		Arrays.sort(indices, new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return cubes[o2].size() - cubes[o1].size();
			}
		});
		
		long[] longest = new long[n + 1];
		int[] longestID = new int[n + 1];
		Arrays.fill(longest, -1);
		
		long best = 0;
		int count1 = -1, count2 = -1;
		int best1 = -1, best2 = -1;
		
		for (int i = 0; i < colorsCount; i++) {
			int curColor = indices[i];
			int count = cubes[curColor].size();
			
			long sum = 0;
			for (Cube c : cubes[curColor]) {
				sum += c.size;
			}
			long curBest = Math.max(longest[count - 1], longest[count]);
			curBest = Math.max(curBest, longest[count + 1]);
			if (curBest != -1) {
				if (best < curBest + sum) {
					int otherCount;
					if (curBest == longest[count - 1]) {
						otherCount = count - 1;
					} else if (curBest == longest[count]) {
						otherCount = count;
					} else {
						otherCount = count + 1;
					}
					
					best = curBest + sum;
					count1 = count;
					count2 = otherCount;
					best1 = curColor;
					best2 = longestID[otherCount];
				}
			}
			
			sum = 0;
			for (int j = 0; j < cubes[curColor].size(); j++) {
				sum += cubes[curColor].get(j).size;
				if (longest[j + 1] < sum) {
					longest[j + 1] = sum;
					longestID[j + 1] = curColor;
				}
			}
		}
		
		out.println(best);
		out.println(count1 + count2);
		if (count1 > count2) {
			out.print(cubes[best1].get(count1 - 1).id + " ");
		}
		for (int i = 0; i < Math.min(count1, count2); i++) {
			out.print(cubes[best2].get(i).id + " " + cubes[best1].get(i).id + " ");
		}
		if (count2 > count1) {
			out.print(cubes[best2].get(count2 - 1).id + " ");
		}
	}

	void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			// in = new BufferedReader(new FileReader("input.txt"));
			// out = new PrintWriter("output.txt");

			solve();

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

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

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

}