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.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;

public class Solution {
	
	class Cube {
		int c;
		int s;
		int n;
		Cube(int qq, int q, int w) { c = qq; s = q; n = w; }
	}
	
	void solve() throws Exception {
		int n = nextInt();
		Cube[] a = new Cube[n];
		for (int i = 0; i < n; i++) {
			int c = nextInt();
			int s = nextInt();
			a[i] = new Cube(c, s, i + 1);
		}
		Arrays.sort(a, new Comparator<Cube>() {
			public int compare(Cube a, Cube b) {
				if (a.c != b.c) return a.c - b.c;
				if (a.s != b.s) return b.s - a.s;
				return a.n - b.n;
			}
		});
		long[] d = new long[n + 2];
		int[] dc = new int[n + 2];
		long ans = 0;
		int c1 = -1, c2 = -1;
		for (int b = 0; b < n; ) {
			int e = b;
			while (e < n && a[e].c == a[b].c) e++;
			long sum = 0;
			if (b != 0) {
				for (int i = b; i < e; i++) {
					sum += a[i].s;
					int ss = i - b + 1;
					for (int q = -1; q < 2; q++) {
						if (ss + q >= 0 && d[ss + q] != 0 && ans < d[ss + q] + sum) {
							ans = d[ss + q] + sum;
							c1 = dc[ss + q];
							c2 = a[i].c;
						}
					}
				}
			}
			sum = 0;
			for (int i = b; i < e; i++) {
				sum += a[i].s;
				int ss = i - b + 1;
				if (d[ss] < sum) {
					d[ss] = sum;
					dc[ss] = a[i].c;
				}
			}
			b = e;
		}
		out.println(ans);
		int q1 = 0;
		while (a[q1].c != c1) q1++;
		int l1 = 1;
		while (q1 + l1 < n && a[q1 + l1].c == c1) l1++;
		int q2 = 0;
		while (a[q2].c != c2) q2++;
		int l2 = 1;
		while (q2 + l2 < n && a[q2 + l2].c == c2) l2++;
		l1 = Math.min(l1, Math.min(l1, l2) + 1);
		l2 = Math.min(l2, Math.min(l1, l2) + 1);
		out.println(l1 + l2);
		if (l2 > l1) {
			int t = l1; l1 = l2; l2 = t;
			t = q1; q1 = q2; q2 = t;
		}
		while (l1 > 0) {
			out.print(a[q1 + --l1].n + " ");
			if (l2 > 0) out.print(a[q2 + --l2].n + " ");
		}
	}

	public static void main(String[] args) {
		new Solution().run();
	}
	
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}
	
	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null) return null;
			st = new StringTokenizer(s);
		}
		return st.nextToken();
	}
	
	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}
	
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

}