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.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(in.readLine());

		ArrayList<Pair> orig = new ArrayList<Pair>();

		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			orig.add(new Pair(Integer.parseInt(st.nextToken()), Integer
					.parseInt(st.nextToken()), i + 1));
		}

		Collections.sort(orig, new EwCmp());

		ArrayList<Group> ans = new ArrayList<Group>();

		ans.add(new Group());
		ans.get(0).plus(orig.get(0));

		for (int i = 1; i < n; i++) {
			Group x;

			x = ans.get(ans.size() - 1);

			if (orig.get(i).x != orig.get(i - 1).x) {
				ans.add(new Group());
			} 

			x = ans.get(ans.size() - 1);

			x.plus(orig.get(i));
		}

		Pair[] m1 = new Pair[100001];
		Pair[] m2 = new Pair[100001];

		for (int i = 0; i < 100001; i++) {
			m1[i] = m2[i] = new Pair();
		}

		for (int i = 0; i < ans.size(); i++) {
			for (int j = 0; j < ans.get(i).el.size(); j++) {
				if (ans.get(i).el.get(j).y > m1[j + 1].y) {
					m2[j + 1] = m1[j + 1];
					m1[j + 1] = ans.get(i).el.get(j);
				} else if (ans.get(i).el.get(j).y > m2[j + 1].y)
					m2[j + 1] = ans.get(i).el.get(j);
			}
		}
		
		int[] P = new int[5];
		Long size = new Long(0);
		
		boolean d = false;
		
		for (int k = 2; k <= 100001; k++) {
			if (k % 2 == 0) { 
				size = max(m1, m2, k / 2, k / 2, size, P);
				if (d && k < 6) System.out.println(k + " " + size);
			} else {
				if (m1[k / 2 + 1].x != m2[k / 2].x) {
					size = max(m1, m2, k / 2 + 1, k / 2, size, P);
					if (d && k < 6) System.out.println(k + " A: " + size + " COLOURS: " + m1[k/2+1].x + " " + m2[k/2].x);
				}
				if (m1[k / 2 + 1].x != m1[k / 2].x) {
					size = max(m1, m1, k / 2 + 1, k / 2, size, P);
					if (d && k < 6) System.out.println(k + " B: " + size);
				}
				if (m2[k / 2 + 1].x != m2[k / 2].x) {
					size = max(m2, m2, k / 2 + 1, k / 2, size, P);
					if (d && k < 6) System.out.println(k + " C: " + size);
				}
			}
			
		}

		System.out.println(size + "\n" + (P[0] + P[1]));
		
		int minJ =(int) Math.min(P[0], P[1]);
		
		int ind1 = 0, ind2 = 0;
		
		for (int i = 0 ; i < ans.size() ; i++) {
			if (ans.get(i).el.size() > 0 && ans.get(i).el.get(0).x == P[2]) {
				ind1 = i;
			} else if (ans.get(i).el.size() > 0 && ans.get(i).el.get(0).x == P[3]) {
				ind2 = i;
			}
		}
		
		for (int i = 0 ; i < minJ ; i++) {
			System.out.print(ans.get(ind1).el.get(i).index + " " + ans.get(ind2).el.get(i).index + " ");
		}
		
		if (P[0] != minJ) System.out.print(ans.get(ind1).el.get(minJ).index);
		if (P[1] != minJ) System.out.print(ans.get(ind2).el.get(minJ).index);
	}

	static long max(Pair[] m1, Pair[] m2, int k1, int k2, long size, int[] args) {
		if ((m1[k1].y + m2[k2].y) > size) {
			args[0] = k1;
			args[1] = k2;
			args[2] = m1[k1].x;
			args[3] = m2[k2].x;
			return m1[k1].y + m2[k2].y;
		} else {
			return size;
		}
	}

	static class EwCm2 implements Comparator<Group> {
		public int compare(Group A, Group B) {
			if (A.s > B.s)
				return -1;
			else
				return 1;
		}
	}

	static class EwCmp implements Comparator<Pair> {
		public int compare(Pair A, Pair B) {
			if (A.x < B.x || (A.x == B.x && A.y > B.y))
				return -1;
			else
				return 1;
		}
	}

	static class Group {
		ArrayList<Pair> el;
		long s;
		int b, e;

		Group() {
			el = new ArrayList<Pair>();
			s = 0;
			b = 0;
			e = 0;
		}

		void plus(Pair A) {
			el.add(A);
			s += A.y;
			el.get(el.size() - 1).y = s;
			e++;
		}

		public String toString() {
			return el + " == > " + Long.toString(s);
		}

		Group subGroup(int n) {
			if (n == el.size())
				return this;

			ArrayList<Pair> subEl = new ArrayList<Pair>();

			for (int i = (el.size() - n); i < el.size(); i++) {
				subEl.add(el.get(i));
			}

			long subS = s - el.get(el.size() - 1 - n).y;

			Group sub = new Group();

			sub.el = subEl;
			sub.s = subS;

			return sub;
		}
	}

	static class Pair {
		int x, index;
		long y;

		Pair(int a, int b, int i) {
			x = a;
			y = b;
			index = i;
		}

		Pair() {
			x = 0;
			y = -1000000000;
			index = 0;
		}

		public String toString() {
			return Integer.toString(index);
		}
	}
}