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 E159 {
	static String next() {
		if (st == null || !st.hasMoreTokens())
			nextLine();
		return st.nextToken();
	}

	static int nextInt() {
		return Integer.parseInt(next());
	}

	static void nextLine() {
		try {
			st = new StringTokenizer(f.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	static class color {
		long[] sums;
		ArrayList<cube> cubes;

		public color(int c) {
			cubes = new ArrayList<cube>();
		}

		public void calc() {
			Collections.sort(cubes);
			sums = new long[cubes.size() + 1];
			for (int x = 0; x < cubes.size(); x++) {
				sums[x + 1] = sums[x] + cubes.get(x).val;
				pq[x + 1].add(this);
			}
		}
	}

	static class cube implements Comparable<cube> {
		int val;
		int num;

		public cube(int v, int n) {
			val = v;
			num = n;
		}

		public int compareTo(cube o) {
			return o.val - val;
		}
	}

	static class colorcomp implements Comparator<color> {
		int h;

		public colorcomp(int height) {
			h = height;
		}

		public int compare(color a, color b) {
			return b.sums[h] - a.sums[h]>0?1:-1;
		}
	}

	static PriorityQueue<color>[] pq;
	static StringTokenizer st;
	static PrintWriter out;
	static BufferedReader f;

	public static void main(String[] args) throws IOException {
		f = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		Hashtable<Integer, color> ht = new Hashtable<Integer, color>();
		ArrayList<color> colors = new ArrayList<color>();
		int N = nextInt();
		for (int x = 0; x < N; x++) {
			int a = nextInt(), b = nextInt();
			if (ht.get(a) == null) {
				color c = new color(a);
				ht.put(a, c);
				colors.add(c);
			}
			color c = ht.get(a);
			c.cubes.add(new cube(b, x + 1));
		}
		pq = new PriorityQueue[N + 1];
		for (int x = 0; x < N + 1; x++) {
			pq[x] = new PriorityQueue<color>(10, new colorcomp(x));
		}
		for (color c : colors)
			c.calc();
		long maxh = -1, h1 = -1, h2 = -1;
		color col1 = null, col2 = null;
		for (int a = 1; a <= N; a++) {
			color ca = pq[a].peek();
			if (ca == null)
				break;
			for (int b = a - 1; b <= a + 1; b++) {
				if (b <= 0)
					continue;
				color cb = pq[b].peek();
				if (cb == ca) {
					pq[b].poll();
					color temp = pq[b].peek();
					pq[b].add(cb);
					cb = temp;
				}
				if (cb == null)
					continue;
				long sum = ca.sums[a] + cb.sums[b];
				if (sum > maxh) {
					maxh = sum;
					h1 = a > b ? a : b;
					h2 = a > b ? b : a;
					col1 = a > b ? ca : cb;
					col2 = a > b ? cb : ca;
				}
			}
		}
		out.println(maxh);
		out.println(h1 + h2);
		String sep = "";
		StringBuffer sb = new StringBuffer();
		for (int x = 0; x < h1; x++) {
			sb.append(sep);
			sep = " ";
			sb.append(col1.cubes.get(x).num);
			if (x < h2) {
				sb.append(sep);
				sep = " ";
				sb.append(col2.cubes.get(x).num);
			}
		}
		out.println(sb);
		out.close();
		// System.exit(0);
	}
}