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.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Task5 {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		 BufferedReader br = new BufferedReader(new FileReader("task5.in"));
//		 System.setOut(new PrintStream(new File("task5.out")));
//		 long ts = System.currentTimeMillis();
		int n = Integer.valueOf(br.readLine());
		Map<Integer, List<Cube>> byC = new HashMap<Integer, List<Cube>>();
		for (int i = 0; i < n; i++) {
			String[] ss = br.readLine().split(" ");
			int c = Integer.valueOf(ss[0]);
			int s = Integer.valueOf(ss[1]);
			Cube cube = new Cube(i + 1, s);
			if (!byC.containsKey(c))
				byC.put(c, new ArrayList<Cube>(10));
			byC.get(c).add(cube);
		}
		List<Cube>[] a = new List[byC.size()];
		long[][] z = new long[byC.size()][];
		int t = 0;
		for (List<Cube> lst : byC.values()) {
			Collections.sort(lst);
			a[t] = lst;
			t++;
		}
		Arrays.sort(a, new Comparator<List>() {
			@Override
			public int compare(List o1, List o2) {
				return o2.size() - o1.size();
			}
		});
		for (int i = 0; i < a.length; i++) {
			List<Cube> lst = (List<Cube>) a[i];
			z[i] = new long[lst.size()];
            int j = 0;
            long sum = 0;
            for (Cube c : lst) {
                sum += c.s;
                z[i][j] = sum;
//                System.out.print(z[i][j] + " ");
                j++;
            }
//            System.out.println();
		}
//        System.out.println("-----");
		long max = 0;
		int t1 = 0;
		int t2 = 0;
		for (int i = 1; i < z.length; i++) {
			while (i < z.length - 1 && z[i+1].length == z[i].length) {
				i++;
			}
			int k = z[i].length - 1;
			long max1 = 0; 
			long max2 = 0;
			int tt1 = 0;
			int tt2 = 0;
			for (int j = 0; j < i+1; j++) {
				long p = z[j][k];
				if (z[j].length > k+1) p = z[j][k+1];
				if (p > max1) {
					max2 = max1; tt2 = tt1;
					max1 = p; tt1 = j;
				} else if (p > max2) {
					max2 = p; tt2 = j;
				}
			}
			if (max1 + max2 > max) {
				max = max1 + max2;
				t1=tt1;
				t2=tt2;
			}
		}
		System.out.println(max);
		List<Cube> e1 = a[t1];
		List<Cube> e2 = a[t2];
		if (e1.size() < e2.size()) {
			List<Cube> tmp = e1;
			e1 = e2;
			e2 = tmp;
		}
//		System.out.println(t1 + " " + t2);
		if (e1.size() > e2.size()) {
			System.out.println(2*e2.size() + 1);
			System.out.print(e1.remove(0).num + " ");
		} else {
			System.out.println(2*e2.size());
		}
		Iterator<Cube> it1 = e1.iterator();
		Iterator<Cube> it2 = e2.iterator();
		while (it2.hasNext()) {
			System.out.print(it2.next().num + " " + it1.next().num + (it2.hasNext() ? " " : ""));
		}
//		System.out.println();
//		System.out.println(System.currentTimeMillis() - ts);
	}

	public static final class Cube implements Comparable<Cube> {
		public final int num;
		public final int s;

		public Cube(int n, int size) {
			num = n;
			s = size;
		}

		//the biggest is smaller =)
		@Override
		public int compareTo(Cube o) {
			return o.s - s;
		}
	}
}