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.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class E2 {
    static class pair implements Comparable<pair> {
        int k, v;

        public pair(int k, int v) {
            this.k = k;
            this.v = v;
        }

        @Override
        public int compareTo(pair arg0) {
            if (k > arg0.k)
                return -1;
            return 1;
        }

    }

    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());
        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        int top = 0;
        int[] c = new int[n];
        int[] s = new int[n];
        int[] count = new int[n];
        for (int i = 0; i < n; i++) {
            st = new StringTokenizer(in.readLine(), " ");
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            if (!map.containsKey(a))
                map.put(a, top++);
            int t = map.get(a);
            c[i] = t;
            s[i] = b;
            count[t]++;
        }
        long[][] arr = new long[top][];
        for (int i = 0; i < top; i++)
            arr[i] = new long[count[i]];
        Arrays.fill(count, 0);
        for (int i = 0; i < c.length; i++)
            arr[c[i]][count[c[i]]++] = -s[i];
        for (long[] a : arr)
            Arrays.sort(a);
        for (long[] a : arr)
            for (int i = 0; i < a.length; i++)
                a[i] = -a[i];
        long[] max = new long[n];
        long[] secondmax = new long[n];
        int[] maxInd = new int[n];
        int[] secmaxInd = new int[n];
        Arrays.fill(max, -1);
        Arrays.fill(secondmax, -1);
        for (int j = 0; j < arr.length; j++) {
            long[] a = arr[j];
            long cur = 0;
            for (int i = 0; i < a.length; i++) {
                cur += a[i];
                a[i] = cur;
                if (cur > max[i]) {
                    secondmax[i] = max[i];
                    secmaxInd[i] = maxInd[i];
                    max[i] = cur;
                    maxInd[i] = j;
                } else if (cur > secondmax[i]) {
                    secondmax[i] = cur;
                    secmaxInd[i] = j;
                }
            }
        }
        long maxH = -1;
        int cube1 = -1;
        int cube2 = -1;
        int cnt1 = 0;
        int cnt2 = 0;
        for (int j = 0; j < max.length; j++) {
            if (max[j] != -1) {
                if (secondmax[j] != -1) {
                    if ((max[j] + secondmax[j] > maxH)) {
                        cube1 = maxInd[j];
                        cube2 = secmaxInd[j];
                        maxH = max[j] + secondmax[j];
                        cnt1 = j;
                        cnt2 = j;
                    }
                    if (j + 1 < max.length) {
                        if (max[j + 1] != -1 && secmaxInd[j] != maxInd[j + 1]
                                && secondmax[j] + max[j + 1] > maxH) {
                            cube1 = secmaxInd[j];
                            cube2 = maxInd[j + 1];
                            cnt1 = j;
                            cnt2 = j + 1;
                            maxH = secondmax[j] + max[j + 1];
                        }
                        if (secondmax[j + 1] != -1
                                && secmaxInd[j] != secmaxInd[j + 1]
                                && secondmax[j + 1] + secondmax[j] > maxH) {// useless
                                                                            // condition
                            cube1 = secmaxInd[j];
                            cube2 = secmaxInd[j + 1];
                            cnt1 = j;
                            cnt2 = j + 1;
                            maxH = secondmax[j] + secondmax[j + 1];
                        }
                    }
                }
                if (j + 1 < max.length && max[j + 1] != -1) {
                    if (maxInd[j] == maxInd[j + 1]) {
                        if (secondmax[j + 1] != -1
                                && max[j] + secondmax[j + 1] > maxH) {
                            cube1 = maxInd[j];
                            cube2 = secmaxInd[j + 1];
                            maxH = max[j] + secondmax[j + 1];
                            cnt1 = j;
                            cnt2 = j + 1;
                        }
                    } else {
                        if (max[j] + max[j + 1] > maxH) {
                            cube1 = maxInd[j];
                            cube2 = maxInd[j + 1];
                            maxH = max[j] + max[j + 1];
                            cnt1 = j;
                            cnt2 = j + 1;

                        }
                    }
                }
            }
        }
        PriorityQueue<pair> Q1 = new PriorityQueue<pair>();
        PriorityQueue<pair> Q2 = new PriorityQueue<pair>();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == cube1)
                Q1.add(new pair(s[i], i + 1));
            if (c[i] == cube2)
                Q2.add(new pair(s[i], i + 1));
        }
        Queue<Integer> R1 = new LinkedList<Integer>();
        Queue<Integer> R2 = new LinkedList<Integer>();
        StringBuilder out = new StringBuilder("");
        int d1 = 0;
        int d2 = 0;
        while (d1 <= cnt1) {
            R1.add(Q1.remove().v);
            d1++;
        }
        while (d2 <= cnt2) {
            R2.add(Q2.remove().v);
            d2++;
        }
        if (R2.size() > R1.size())
            out.append(R2.remove());
        while (true) {
            if (!R1.isEmpty())
                out.append(" " + R1.remove());
            if (!R2.isEmpty())
                out.append(" " + R2.remove());
            if (R1.isEmpty() && R2.isEmpty())
                break;
        }
        if (out.charAt(0) == ' ')
            out.deleteCharAt(0);
        System.out.println(maxH);
        System.out.println((cnt1 + 1 + cnt2 + 1));
        System.out.println(out);
    }
}