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 ZebraTower {
	static final int TOT = 100001;
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int N = Integer.parseInt(st.nextToken());
        Cube[] c = new Cube[N];
        for(int i = 0; i < N; i++) {
        	st = new StringTokenizer(in.readLine());
        	int col = Integer.parseInt(st.nextToken());
        	int s = Integer.parseInt(st.nextToken());
        	c[i] = new Cube(col, s, i + 1);
        }
        Entry[][] best = new Entry[TOT][2];
        Arrays.sort(c);
        int len = 1;
        long curSum = 0;
        for(int i = 0; i < best.length; i++) {
        	Arrays.fill(best[i], new Entry(-1, -1, -1));
        }
        for(int i = 0; i < N; i++) {
        	if(i != 0 && c[i-1].col == c[i].col)
        		len++;
        	else {
        		len = 1;
        		curSum = 0;
        	}
        	int col = c[i].col;
        	int s = c[i].s;
        	curSum += s;
        	if(curSum > best[len][0].size) {
        		Entry temp = best[len][0];
        		best[len][0] = new Entry(curSum, col, len);
        		best[len][1] = temp;
        	}
        	else if (curSum > best[len][1].size) {
        		best[len][1] = new Entry(curSum, col, len);
        	}
        }
        Entry b1 = null;
        Entry b2 = null;
        int totLen = 1;
        long bLen = 0;
        //test two set of same length
        for(int i = 1; i < 100001; i++) {
        	if(best[i][0].size != -1 && best[i][1].size != -1 && best[i][0].size + best[i][1].size > bLen) {
        		b1 = best[i][0];
        		b2 = best[i][1];
        		totLen = 2 *i;
        		bLen = best[i][0].size + best[i][1].size;
        	}
        }
        for(int i = 1; i < 100000; i++) {
        	//check first i and first i + 1
        	if(best[i][0].size != -1 && best[i+1][0].size != -1 && best[i][0].color != best[i+1][0].color && best[i][0].size + best[i+1][0].size > bLen) {
        		b1 = best[i][0];
        		b2 = best[i+1][0];
        		bLen = best[i][0].size + best[i+1][0].size;
        		totLen = 2 * i + 1;
        	}
        	//check first i and second i + 1
        	if(best[i][0].size != -1 && best[i+1][1].size != -1 && best[i][0].color != best[i+1][1].color && best[i][0].size + best[i+1][1].size > bLen) {
        		b1 = best[i][0];
        		b2 = best[i+1][1];
        		bLen = best[i][0].size + best[i+1][1].size;
        		totLen = 2 * i + 1;
        	}
        	//check second i and first i + 1
        	if(best[i][1].size != -1 && best[i+1][0].size != -1 && best[i][1].color != best[i+1][0].color && best[i][1].size + best[i+1][0].size > bLen) {
        		b1 = best[i][1];
        		b2 = best[i+1][0];
        		bLen = best[i][1].size + best[i+1][0].size;
        		totLen = 2 * i + 1;
        	}
        }
        ArrayList<Integer> cube1 = new ArrayList<Integer>();
        ArrayList<Integer> cube2 = new ArrayList<Integer>();
        int k = 0;
        int j = 0;
        for(int i = 0; i < N; i++) {
        	boolean e1 = false;
        	boolean e2 = false;
        	while(i < N && c[i].col == b1.color && k < b1.len) {
        		cube1.add(c[i].orig);
        		k++;
        		i++;
        		e1 = true;
        	}
        	if(e1)
        		i--;
        	while(i < N && c[i].col == b2.color && j < b2.len) {
        		cube2.add(c[i].orig);
        		j++;
        		i++;
        		e2 = true;
        	}
        	if(e2)
        		i--;
        }
        System.out.println(bLen);
        System.out.println(totLen);
        if(cube2.size() > cube1.size()) {
        	System.out.print(cube2.get(0) + " ");
        	for(int i = 0; i < cube1.size(); i++) {
        		System.out.print(cube1.get(i) + " ");
        		System.out.print(cube2.get(i+1) + " ");
        	}
        }
        else if (cube1.size() > cube2.size()){
        	System.out.print(cube1.get(0) + " ");
        	for(int i = 0; i < cube2.size(); i++) {
        		System.out.print(cube2.get(i) + " ");
        		System.out.print(cube1.get(i+1) + " ");
        	}
        }
        else {
        	for(int i = 0; i < cube1.size(); i++) {
        		System.out.print(cube1.get(i) + " ");
        		System.out.print(cube2.get(i) + " ");
        	}
        }
        System.out.println();
    }
}
class Cube implements Comparable<Cube> {
	int col;
	int s;
	int orig;
	Cube(int c, int s, int o){ 
		this.col = c;
		this.s = s;
		orig = o;
	}
	public int compareTo(Cube other) {
		if(this.col < other.col) {
			return -1;
		}
		else if(this.col > other.col) {
			return 1;
		}
		else {
			if(this.s > other.s) {
				return -1;
			}
			else if (this.s < other.s) {
				return 1;
			}
		}
		return 0;
	}
}
class Entry {
	long size;
	int len;
	int color;
	Entry(long s, int c, int l) {
		size = s;
		color = c;
		len = l;
	}
}