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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;

public class Solver {

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws NumberFormatException, IOException {
        Solver solver = new Solver();
        solver.open();
        solver.solve();
        solver.close();
    }

    public void open() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

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

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

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

    public double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    class cube implements Comparable{
        public int number = 0;
        public int color = 0;
        public int size = 0;
        public cube(int n, int c, int s){
            number = n;
            color = c;
            size = s;
        }
        @Override
        public int compareTo(Object o) {
            cube comp = (cube)o;
            int result = color-comp.color;
            if (result==0) result = comp.size-size;
            return result;
        }
        
        @Override
        public String toString() {
            return "color: "+color+ "; size:"+size;
        }
    }

    public void solve() throws NumberFormatException, IOException {
        int n = nextInt();
        
        cube[] cubes = new cube[n];
        for (int i=0;i<n;i++){
            int c = nextInt();
            int s = nextInt();
            cubes[i] = new cube(i+1, c, s);
        }
        
        Arrays.sort(cubes);
        
        long[] max1st = new long[n];
        int[] color1st = new int[n];
        
        long[] max2nd = new long[n];
        int[] color2nd = new int[n];
        
        for (int i=0;i<n;){
            long sum = 0;
            int count = 0;
            int currentColor = cubes[i].color;
            for(;i<n && cubes[i].color==currentColor; i++,count++){
                sum += cubes[i].size;
                if (sum>max1st[count]){
                    max2nd[count] = max1st[count];
                    color2nd[count] = color1st[count];
                    max1st[count] = sum;
                    color1st[count] = currentColor;
                }else if (sum > max2nd[count]){
                    max2nd[count] = sum;
                    color2nd[count] = currentColor;
                }
            }
        }
        
        long maxSize = 0;
        int cubeCount = 0;
        int firstColor = 0;
        int secondColor = 0;

        if (color1st[0]!=0 && color2nd[0]!=0){
            maxSize = max1st[0]+max2nd[0];
            firstColor = color1st[0];
            secondColor = color2nd[0];
            cubeCount = 2;
        }
        
        for (int i=1;i<n;i++){
            if (color1st[i]!=0){
                if (color2nd[i]!=0){
                    long buf = max1st[i]+max2nd[i];
                    if (buf>maxSize){
                        maxSize = buf;
                        firstColor = color1st[i];
                        secondColor = color2nd[i];
                        cubeCount = 2*(i+1);
                    }
                }
                if (color1st[i-1]!=0){
                    if (color1st[i-1]!=color1st[i]){
                        long buf = max1st[i]+max1st[i-1];
                        if (buf>maxSize){
                            maxSize = buf;
                            firstColor = color1st[i];
                            secondColor = color1st[i-1];
                            cubeCount = 2*(i+1)-1;
                        }
                    }else if (color2nd[i-1]!=0){
                        long buf = max1st[i]+max2nd[i-1];
                        if (buf>maxSize){
                            maxSize = buf;
                            firstColor = color1st[i];
                            secondColor = color2nd[i-1];
                            cubeCount = 2*(i+1)-1;
                        }
                    }
                }
            }
        }
        
        int s1 = -1;
        int s2 = -1;
        
        for (int i=0;i<n;i++){
            if (s1<0 && cubes[i].color==firstColor){
                s1 = i;
            }
            if (s2<0 && cubes[i].color==secondColor){
                s2 = i;
            }
        }
        
        out.println(maxSize);
        out.println(cubeCount);
        
        boolean firstNow = true;
        for (;cubeCount>0;cubeCount--){
            int currentCube = 0;
            if (firstNow){
                currentCube = s1++;
            }else{
                currentCube = s2++;
            }
            out.print(cubes[currentCube].number+" ");
            firstNow = !firstNow;
        }
    }

    public void close() {
        out.flush();
        out.close();
    }

}