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

public class zebra implements Runnable {
	public StringTokenizer strtok;
	public BufferedReader inr;
	public PrintWriter out;

	public static void main(String[] args) {
		new Thread(new zebra()).start();
	}

	public static final String taskname = "zebra";

	public void run() {
		Locale.setDefault(Locale.US);
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		try {
			inr = new BufferedReader(oj ? new InputStreamReader(System.in, "ISO-8859-1") : new FileReader(taskname + ".in"));
			out = new PrintWriter(oj ? new OutputStreamWriter(System.out, "ISO-8859-1") : new FileWriter(taskname + ".out"));
			solve();
		} catch (Exception e) {
			if (!oj)
				e.printStackTrace();
			System.exit(9000);
		} finally {
			out.flush();
			out.close();
		}
	}

	public String nextToken() throws IOException {
		while (strtok == null || !strtok.hasMoreTokens()) {
			strtok = new StringTokenizer(inr.readLine());
		}
		return strtok.nextToken();
	}

	public int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	// Solution

	public void solve() throws NumberFormatException, IOException {
		int n = nextInt();
		HashMap<Integer, ArrayList<Cube>> colorsMap = new HashMap<Integer, ArrayList<Cube>>();
		for (int i = 0; i < n; i++) {
			int color = nextInt();
			long size = nextLong();
			Cube cube = new Cube(i, size);
			if (colorsMap.containsKey(color)) {
				colorsMap.get(color).add(cube);
			}
			else {
				ArrayList<Cube> newa = new ArrayList<Cube>();
				newa.add(cube);
				colorsMap.put(color, newa);
			}
		}
		TreeMap<Integer, HashMap<Integer, ArrayList<Cube>>> quantities = new TreeMap<Integer, HashMap<Integer,ArrayList<Cube>>>();
		for (Map.Entry<Integer, ArrayList<Cube>> ent : colorsMap.entrySet()) {
			int color = ent.getKey();
			ArrayList<Cube> arr = ent.getValue();
			Collections.sort(arr);
			int key = arr.size();
			if (quantities.containsKey(key)) {
				quantities.get(key).put(color, arr);
			}
			else {
				HashMap<Integer, ArrayList<Cube>> newm = new HashMap<Integer, ArrayList<Cube>>();
				newm.put(color, arr);
				quantities.put(key, newm);
			}
		}
		long bestsize = Long.MIN_VALUE;
		int bestcol1 = -1;
		int bestcol2 = -1;
		ArrayList<BestColor> bestColors = new ArrayList<BestColor>();
		for (Map.Entry<Integer, HashMap<Integer, ArrayList<Cube>>> ent : quantities.entrySet()) {
			int numElems = ent.getKey();
			HashMap<Integer, ArrayList<Cube>> colors = ent.getValue();
			HashMap<Integer, Long> partialSums = new HashMap<Integer, Long>();
			for (int color : colors.keySet()) {
				partialSums.put(color, 0L);
			}
			int prevNumElems = -1;
			for (BestColor bestColor : bestColors) {
				int curNumElems = bestColor.cubes.size();
				long bestpref = Long.MIN_VALUE;
				int bestprefcol = -1;
				for (Map.Entry<Integer, ArrayList<Cube>> innerEntry : colors.entrySet()) {
					int color = innerEntry.getKey();
					ArrayList<Cube> cubes = innerEntry.getValue();
					long cursum = 0;
					for (int i = prevNumElems + 1; i <= curNumElems; i++) {
						cursum += cubes.get(i).size;
					}
					long newsum = partialSums.get(color) + cursum;
					partialSums.put(color, newsum);
					if (newsum > bestpref) {
						bestpref = newsum;
						bestprefcol = color;
					}
				}
				long newbest = bestpref + bestColor.sum;
				if (newbest > bestsize) {
					bestsize = newbest;
					bestcol1 = bestColor.color;
					bestcol2 = bestprefcol;
				}
				prevNumElems = curNumElems;
			}
			long max1 = Long.MIN_VALUE;
			long max2 = Long.MIN_VALUE;
			int maxcol1 = -1;
			int maxcol2 = -1;
			for (Map.Entry<Integer, ArrayList<Cube>> innerEntry : colors.entrySet()) {
				int color = innerEntry.getKey();
				ArrayList<Cube> cubes = innerEntry.getValue();
				long cursum = 0;
				for (int i = prevNumElems + 1; i < numElems; i++) {
					cursum += cubes.get(i).size;
				}
				long newsum = partialSums.get(color) + cursum;
				if (newsum > max2) {
					if (newsum > max1) {
						max2 = max1;
						maxcol2 = maxcol1;
						max1 = newsum;
						maxcol1 = color;
					}
					else {
						max2 = newsum;
						maxcol2 = color;
					}
				}
			}
			if (maxcol2 != -1 && max1 + max2 > bestsize) {
				bestsize = max1 + max2;
				bestcol1 = maxcol1;
				bestcol2 = maxcol2;
			}
			bestColors.add(new BestColor(maxcol1, colors.get(maxcol1), max1));
		}
		ArrayList<Cube> bestCubes1 = colorsMap.get(bestcol1);
		ArrayList<Cube> bestCubes2 = colorsMap.get(bestcol2);
		int cubesInTower = bestCubes1.size() * 2;
		if (bestCubes1.size() < bestCubes2.size()) {
			cubesInTower++;
		}
		out.printf("%d\n%d\n", bestsize, cubesInTower);
		for (int i = 0; i < bestCubes1.size(); i++) {
			out.print(bestCubes2.get(i).index + " " + bestCubes1.get(i).index + " ");
		}
		if (bestCubes1.size() < bestCubes2.size()) {
			out.print(bestCubes2.get(bestCubes1.size()).index);
		}
 	}
}

class Cube implements Comparable<Cube> {
	int index;
	long size;

	public Cube(int index, long size) {
		this.index = index + 1;
		this.size = size;
	}
	
	public int compareTo(Cube cube) {
		return Long.signum(cube.size - this.size);
	}
	
	public String toString() {
		return String.format("(%d, %d)", index, size);
	}
}

class BestColor {
	ArrayList<Cube> cubes;
	long sum;
	int color;
	
	public BestColor(int color, ArrayList<Cube> cubes, long sum) {
		this.color = color;
		this.cubes = cubes;
		this.sum = sum;
	}
	
	public String toString() {
		return String.format("(color=%d, sum=%d, cubes=%s)", color, sum, cubes);
	}
}