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.awt.*;
import java.io.*;
import java.math.*;
import java.util.*;
import static java.lang.Math.*;

public class VKCup_Qual2_E implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(null, new VKCup_Qual2_E(), "", 256 * (1L << 20)).start();
	}

	@Override
	public void run() {
		try {
			long startTime = System.currentTimeMillis();
			if (System.getProperty("ONLINE_JUDGE") != null) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			}
			Locale.setDefault(Locale.US);
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			long endTime = System.currentTimeMillis();
			System.err.println("Time = " + (endTime - startTime));
			long freeMemory = Runtime.getRuntime().freeMemory();
			long totalMemory = Runtime.getRuntime().totalMemory();
			System.err.println("Memory = " + ((totalMemory - freeMemory) >> 10));
		} catch (Throwable t) {
			t.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	/** http://pastebin.com/j0xdUjDn */
	static class Utils {

		private Utils() {}

		public static void mergeSort(int[] a) {
			mergeSort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 50;

		private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergeSort(a, leftIndex, middleIndex);
					mergeSort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}

	// solution
	
	class Cube implements Comparable<Cube> {
		int c;
		long x;
		int i;
		
		public Cube(int c, long x, int i) {
			this.c = c;
			this.x = x;
			this.i = i;
		}

		@Override
		public int compareTo(Cube o) {
			if (x > o.x) return -1;
			if (x < o.x) return 1;
			return 0;
		}

		@Override
		public String toString() {
			return "Cube [c=" + c + ", i=" + i + ", x=" + x + "]";
		}
		
	}

	void solve() throws IOException {
		int n = readInt();
		Cube[] a = new Cube[n];
		for (int i = 0; i < n; i++) {
			int color = readInt();
			long size = readLong();
			a[i] = new Cube(color, size, i);
		}
		int numOfColors = compressColors(a);
		ArrayList<Cube>[] lists = new ArrayList[numOfColors];
		for (int i = 0; i < numOfColors; i++) {
			lists[i] = new ArrayList<Cube>();
		}
		for (Cube cube : a) {
			lists[cube.c].add(cube);
		}
		for (ArrayList<Cube> list : lists) {
			Collections.sort(list);
		}
		long[][] prefSums = new long[numOfColors][];
		for (int c = 0; c < numOfColors; c++) {
			int numOfCubes = lists[c].size();
			prefSums[c] = new long[numOfCubes];
			prefSums[c][0] = lists[c].get(0).x;
			for (int i = 1; i < numOfCubes; i++) {
				prefSums[c][i] = prefSums[c][i-1] + lists[c].get(i).x;
			}
		}
		long[] firstMaxH = new long[n+1];
		long[] secondMaxH = new long[n+1];
		int[] firstMaxC = new int[n+1];
		int[] secondMaxC = new int[n+1];
		Arrays.fill(firstMaxC, -1);
		Arrays.fill(secondMaxC, -1);
		for (int c = 0; c < numOfColors; c++) {
			int numOfCubes = prefSums[c].length;
			for (int i = 0; i < numOfCubes; i++) {
				updateMax(firstMaxH, secondMaxH, firstMaxC, secondMaxC, i+1, c, prefSums[c][i]);
			}
		}
		int bestFirstCnt = -1;
		int bestSecondCnt = -1;
		int bestFirstColor = -1;
		int bestSecondColor = -1;
		long bestH = -1;
		for (int cnt = 2; cnt <= n; cnt++) {
			int cnt2 = cnt / 2;
			int cnt1 = cnt - cnt2;
			if (cnt1 == cnt2) {
				if (firstMaxC[cnt1] != -1 && secondMaxC[cnt1] != -1) {
					long h = firstMaxH[cnt1] + secondMaxH[cnt1];
					if (h > bestH) {
						bestH = h;
						bestFirstCnt = cnt1;
						bestSecondCnt = cnt1;
						bestFirstColor = firstMaxC[cnt1];
						bestSecondColor = secondMaxC[cnt1];
					}
				}
			} else {
				if (firstMaxC[cnt1] != -1 && firstMaxC[cnt2] != -1 && firstMaxC[cnt1] != firstMaxC[cnt2]) {
					long h = firstMaxH[cnt1] + firstMaxH[cnt2];
					if (h > bestH) {
						bestH = h;
						bestFirstCnt = cnt1;
						bestSecondCnt = cnt2;
						bestFirstColor = firstMaxC[cnt1];
						bestSecondColor = firstMaxC[cnt2];
					}
				} else {
					if (firstMaxC[cnt2] != -1 && secondMaxC[cnt1] != -1) {
						long h = firstMaxH[cnt2] + secondMaxH[cnt1];
						if (h > bestH) {
							bestH = h;
							bestFirstCnt = cnt2;
							bestSecondCnt = cnt1;
							bestFirstColor = firstMaxC[cnt2];
							bestSecondColor = secondMaxC[cnt1];
						}
					}
					if (firstMaxC[cnt1] != -1 && secondMaxC[cnt2] != -1) {
						long h = firstMaxH[cnt1] + secondMaxH[cnt2];
						if (h > bestH) {
							bestH = h;
							bestFirstCnt = cnt1;
							bestSecondCnt = cnt2;
							bestFirstColor = firstMaxC[cnt1];
							bestSecondColor = secondMaxC[cnt2];
						}
					}
				}
			}
		}
		out.println(bestH);
		out.println(bestFirstCnt + bestSecondCnt);
		for (int i = 0; i < bestFirstCnt + bestSecondCnt; i++) {
			int pos = i / 2;
			int col = i % 2 == 0 ? bestFirstColor : bestSecondColor;
			int index = lists[col].get(pos).i;
			index++;
			out.print(index + " ");
		}
	}

	private void updateMax(long[] firstMaxH, long[] secondMaxH, int[] firstMaxC, int[] secondMaxC, int numOfCubes, int color, long h) {
		if (firstMaxC[numOfCubes] == color) {
			if (h >= firstMaxH[numOfCubes]) {
				firstMaxH[numOfCubes] = h;
				firstMaxC[numOfCubes] = color;
			}
			return;
		}
		
		if (h >= firstMaxH[numOfCubes]) {
			secondMaxH[numOfCubes] = firstMaxH[numOfCubes];
			secondMaxC[numOfCubes] = firstMaxC[numOfCubes];
			firstMaxH[numOfCubes] = h;
			firstMaxC[numOfCubes] = color;
		} else if (h >= secondMaxH[numOfCubes]) {
			secondMaxH[numOfCubes] = h;
			secondMaxC[numOfCubes] = color;
		}
	}

	private int compressColors(Cube[] a) {
		int curColor = 0;
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (Cube cube : a) {
			if (map.containsKey(cube.c)) {
				continue;
			}
			map.put(cube.c, curColor);
			curColor++;
		}
		for (Cube cube : a) {
			cube.c = map.get(cube.c);
		}
		return curColor;
	}

}