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.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.TreeSet;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskE {
    public void solve(int testNumber, MyScanner in, PrintWriter out) {
        int n = in.nextInt();
        Cube[] cubes = new Cube[n];
        for (int i = 0; i < n; i++) {
            cubes[i] = new Cube(in.nextInt(),in.nextInt(),i);
        }
        Cube[][] colorToCubes = ArrayUtils.classify(cubes);
        Entry[] highest = new Entry[n];
        Entry[] secondHighest = new Entry[n];
        Arrays.fill(highest,new Entry(-1,Long.MIN_VALUE/10,0));
        Arrays.fill(secondHighest,new Entry(-1,Long.MIN_VALUE/10,0));
        for(int i=0;i<colorToCubes.length;i++){
            Arrays.sort(colorToCubes[i],new Comparator<Cube>() {
                public int compare(Cube o1, Cube o2) {
                    return - (o1.height - o2.height);
                }
            });
            long height = 0;
            for(int j=0;j<colorToCubes[i].length;j++){
                height += colorToCubes[i][j].height;
                if(highest[j].height < height){
                    secondHighest[j] = highest[j];
                    highest[j] = new Entry(i,height,j+1);
                }else if(secondHighest[j].height < height){
                    secondHighest[j] = new Entry(i,height,j+1);
                }
            }
        }
        long maxHeight = 0;
        for(int i=0;i<n;i++){
            // i,i
            maxHeight = Math.max(maxHeight,highest[i].height + secondHighest[i].height);
            // i,i+1
            if(i<n-1){
                if(highest[i].colorIndex != highest[i+1].colorIndex){
                    maxHeight = Math.max(maxHeight,highest[i].height + highest[i+1].height);
                }
                maxHeight = Math.max(maxHeight, highest[i].height + secondHighest[i + 1].height);
                maxHeight = Math.max(maxHeight, secondHighest[i].height + highest[i + 1].height);
            }
        }
        out.println(maxHeight);
        Entry bottom = null;
        Entry upper = null;
        for(int i=0;i<n;i++){
            // i,i
            if(maxHeight == highest[i].height + secondHighest[i].height){
                bottom = highest[i];
                upper = secondHighest[i];
                break;
            }
            // i,i+1
            if(i<n-1){
                if(highest[i].colorIndex != highest[i+1].colorIndex){
                    if(maxHeight == highest[i].height + highest[i+1].height){
                        upper = highest[i];
                        bottom = highest[i+1];
                        break;
                    }
                }
                if(maxHeight == highest[i].height + secondHighest[i+1].height){
                    upper = highest[i];
                    bottom = secondHighest[i+1];
                        break;
                }
                if(maxHeight == secondHighest[i].height + highest[i+1].height){
                    upper = secondHighest[i];
                    bottom = highest[i+1];
                    break;
                }
            }
        }
        out.println(bottom.cubeCount + upper.cubeCount);
        for(int i=0;i<bottom.cubeCount + upper.cubeCount;i++){
            if(i>0)out.print(" ");
            out.print((i&1)==0 ? colorToCubes[bottom.colorIndex][i/2].index+1 :
                                 colorToCubes[upper.colorIndex][i/2].index+1);
        }
        out.println();
    }

    class Entry{
        int colorIndex;
        long height;
        int cubeCount;

        Entry(int colorIndex, long height, int cubeCount) {
            this.colorIndex = colorIndex;
            this.height = height;
            this.cubeCount = cubeCount;
        }
    }

    class Cube implements Classifiable {
        int color;
        int height;
        int index;

        Cube(int color, int height, int index) {
            this.color = color;
            this.height = height;
            this.index = index;
        }

        public int getKey() {
            return color;
        }
    }
}

class MyScanner {
    private final InputStream in;
    public MyScanner(InputStream in){
        this.in = in;
    }

    public int nextInt(){
        try{
            int c=in.read();
            if(c==-1) return c;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=in.read();
                if(c==-1) return c;
            }
            if(c=='-') return -nextInt();
            int res=0;
            do{
                res*=10;
                res+=c-'0';
                c=in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    }

class ArrayUtils {

    public static<T> T[] createArray (int length,T instanceOfType){
        return (T[]) java.lang.reflect.Array.newInstance(instanceOfType.getClass(), length);
    }

    public static<T extends Classifiable> T[][] classify(T[] entries){
        TreeSet<Integer> set = new TreeSet<Integer>();
        for(T entry : entries){
            set.add(entry.getKey());
        }
        int[] keys = toIntArray(set);
        int[] ids = new int[entries.length];
        int[] counts = new int[keys.length];
        for (int i = 0; i < entries.length; i++) {
            int id = Arrays.binarySearch(keys,entries[i].getKey());
            ids[i] = id;
            counts[id]++;
        }
        T[][] idToEntries = createArray(keys.length, entries);
        for (int i = 0; i < keys.length; i++){
            idToEntries[i] = createArray(counts[i], entries[0]);
            counts[i] = 0;
        }
        for (int i = 0; i < entries.length; i++) {
            int id = ids[i];
            idToEntries[id][counts[id]++] = entries[i];
        }
        return idToEntries;
    }

    public static int[] toIntArray(Collection<Integer> integerCollection) {
        int[] res = new int[integerCollection.size()];
        int i=0;
        for(int num : integerCollection){
            res[i++] = num;
        }
        return res;
    }

    }

interface Classifiable {
    int getKey();
}