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.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;
	
	private String next() throws Exception{
		while (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}
	
	private int nextInt() throws Exception{
		return Integer.parseInt(next());
	}
	
	private long nextLong() throws Exception{
		return Long.parseLong(next());
	}
	
	private double nextDouble() throws Exception{
		return Double.parseDouble(next());
	}
	
	int n;
	P []a;
	long []cnt;
	int []color;

	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
	
		n = nextInt();
		a = new P[n];
		for(int i=0;i<n;i++) a[i] = new P(nextInt(), nextInt(), i);
		Arrays.sort(a);

		// System.out.println(Arrays.toString(a));

		cnt = new long[n+1];
		color = new int[n+1];
		int diff = 0;
		for(int i=0;i<n;i++){
			long sum = 0;
			int j = i, c = 1;
			while(j < n && a[i].c == a[j].c) {
				sum+=a[j].s;
				if (cnt[c] < sum) {
					cnt[c] = sum;
					color[c] = a[j].c;
				}
				j++;c++;
			}

			i = j - 1;
			diff++;
		}

		// System.out.println(Arrays.toString(cnt));
		// System.out.println(Arrays.toString(color));
		
		if (diff == 1) {
			out.println(a[0].s);
			out.println(1);
			out.println(a[0].idx+1);
			out.close();
			return;
		}

		long max = 0;
		int cnt1 = 0, cnt2 = 0, clr1 = -1, clr2 = -1;

		for(int i=0;i<n;i++){
			long sum = 0;
			int j = i, c = 1;
			while(j < n && a[i].c == a[j].c) {
				sum+=a[j].s;
				if (c > 1 && color[c-1] != a[j].c) {
					if (max < sum + cnt[c-1]) {
						max = sum + cnt[c-1];
						cnt1 = c;
						cnt2 = c-1;
						clr1 = a[j].c;
						clr2 = color[c-1];
					}
				}
				if (color[c] != a[j].c) {
					if (max < sum + cnt[c]) {
						max = sum + cnt[c];
						cnt1 = c;
						cnt2 = c;
						clr1 = a[j].c;
						clr2 = color[c];
					}
				}
				if (c+1 < n && color[c+1] != a[j].c) {
					if (max < sum + cnt[c+1]) {
						max = sum + cnt[c+1];
						cnt1 = c;
						cnt2 = c+1;
						clr1 = a[j].c;
						clr2 = color[c+1];
					}
				}
				j++;c++;
			}
			i = j - 1;
		}

		// System.out.println("cnt1=" + cnt1);
		// System.out.println("cnt2=" + cnt2);
		// System.out.println("color1=" + clr1);
		// System.out.println("color2=" + clr2);

		out.println(max);
		out.println(cnt1+cnt2);
		List<Integer> cube1 = new ArrayList<Integer>();
		for(int i=0;i<n;i++){
			if (a[i].c == clr1) {
				for(int j=i, c1 = 0;c1 < cnt1;j++,c1++) {
					cube1.add(a[j].idx+1);
				}
				break;
			}
		}
		List<Integer> cube2 = new ArrayList<Integer>();
		for(int i=0;i<n;i++){
			if (a[i].c == clr2) {
				for(int j=i, c1 = 0;c1 < cnt2;j++,c1++) {
					cube2.add(a[j].idx+1);
				}
				break;
			}
		}
		if (cube1.size() < cube2.size()) {
			List<Integer> tmp = cube1;
			cube1 = cube2;
			cube2 = tmp;
		}

		for(int i=0;i<cube2.size();i++){
			out.print(cube1.get(i) + " " + cube2.get(i) + " ");
		}
		if (cube1.size() > cube2.size()) {
			out.print(cube1.get(cube1.size()-1));
		}
		out.println();
		out.close();
	}
	
	class P implements Comparable<P> {
		int c, s, idx;
		public P(int c, int s,int idx) {
			this.c = c;
			this.s = s;
			this.idx = idx;
		}

		public int compareTo(P other) {
			if (this.c < other.c) return -1;
			if (this.c > other.c) return 1;
			if (this.s > other.s) return -1;
			if (this.s < other.s) return 1;
			return 0;
		}

		@Override
		public String toString() {
			return this.c + " " + this.s + " " + this.idx;
		}
	}

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