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 static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "1", 1 << 23).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	
	HashMap<Integer, Integer> rec = new HashMap<Integer, Integer>();
	int prec = 0;
	int getReColor(int color){
		if(!rec.containsKey(color))
			rec.put(color, prec++);
		return rec.get(color);
	}
	
	final int maxC = 100000;
	final int maxLen = maxC;
	
	ArrayList<Cube>[] init = new ArrayList[maxC];
	
	long fstScore[] = new long[maxC];
	int fstId[] = new int[maxC];
	long sndScore[] = new long[maxC];
	int sndId[] = new int[maxC];

	ArrayList<Cube> ans1;
	ArrayList<Cube> ans2;
	
	long maxH = 0;
	int ansLen = 0;
	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		long t0 = currentTimeMillis();
		fill(fstScore, -1L);
		fill(sndScore, -1L);
		fill(fstId, -1);
		fill(sndId, -1);
		
		int n = nextInt();
		for(int i = 0; i < n; i++){
			int color = nextInt();
			int reColor = getReColor(color);
			add(reColor, new Cube(i + 1, reColor, nextInt()));
		}
		for(int i = 0; i < prec; i++)
			Collections.sort(init[i]);
		for(int i = 0; i < prec; i++){
			long curSum = 0L;
			int p = 0;
			for(Cube e : init[i]){
				curSum += e.size;
				relax(p, curSum, i);
				p++;
			}
		}
		

		for(int i = 0; i < maxLen; i++){
			{
				if(i < maxLen - 1){
					int j = i + 1;
					if(fstId[i] != fstId[j])
						relaxAns(fstScore[i], fstId[i], fstScore[j], fstId[j], i, j);
					
					if(fstId[i] != sndId[j])
						relaxAns(fstScore[i], fstId[i], sndScore[j], sndId[j], i, j);
					
					if(sndId[i] != fstId[j])
						relaxAns(sndScore[i], sndId[i], fstScore[j], fstId[j], i, j);
				}
				relaxAns(fstScore[i], fstId[i], sndScore[i], sndId[i], i, i);
					
			}
		}
		out.println(maxH);
		
		out.println(ansLen);
		for(int i = 0; i < ansLen; i++){
			if(i != 0) out.print(" ");
			if((i & 1) != 0)
				out.print(ans1.get(i >> 1));
			else
				out.print(ans2.get(i >> 1));
		}
//		System.err.println((currentTimeMillis() - t0) / 1000.0);
		in.close();
		out.close();
	}

	boolean FIRST = true;
	private void relaxAns(long zi, int i, long zj, int j, int l1, int l2) {
		if(i == -1 || j == -1) return;
//		if(i == j)
//			throw new RuntimeException(i + " " + j);
		if(i == j && FIRST){
			FIRST = false;
			long t0 = currentTimeMillis();
			while(currentTimeMillis() - t0 < 500);
		}
		if(zi + zj > maxH){
			ansLen = l1 + l2 + 2;
			maxH = zi + zj;
			ans1 = init[i];
			ans2 = init[j];
		}
	}

	private void relax(int pos, Long cur, int id) {
//		System.err.println("call " + pos + " " + cur + " " + id);
		if(fstScore[pos] < cur){
			sndScore[pos] = fstScore[pos];
			sndId[pos] = fstId[pos];
			fstScore[pos] = cur;
			fstId[pos] = id;
//			System.err.println(fstId[pos] + " 1 " + sndId[pos]);
		} else { 
			if(sndScore[pos] < cur && id != fstId[pos]){
				sndScore[pos] = cur;
				sndId[pos] = id;
//				System.err.println(fstId[pos] + " 2 " + sndId[pos]);
			}
		}
	}

	private void add(int color, Cube e) {
		if(init[color] == null)
			init[color] = new ArrayList();
		init[color].add(e);
	}

	class Cube implements Comparable <Cube>{
		int color, size, id;
		public Cube(int i, int c, int s) {
			id = i;
			color = c;
			size = s;
		}
		@Override
		public int compareTo(Cube e) {
			if(size != e.size)
				return e.size - size;
			return id - e.id;
		}
		@Override
		public String toString() {
			return id + "";
		}
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}