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.*;
import java.util.*;
import java.math.*;

public class A implements Runnable {

    public void run() {
        long startTime = System.nanoTime();

        int n = nextInt();
        class T implements Comparable<T> {
            int i, c, x;

            public T(int i, int c, int x) {
                this.i = i;
                this.c = c;
                this.x = x;
            }

            public int compareTo(T o) {
                return c - o.c;
            }
        }

        T[] t = new T[n];
        for (int i = 0; i < n; i++) {
            t[i] = new T(i + 1, nextInt(), nextInt());
        }
        Arrays.sort(t);
        int z = 0;
        for (int i = 0; i < n; i++) {
            int p = t[i].c;
            t[i].c = z;
            if (i == n - 1 || p != t[i + 1].c) {
                z++;
            }
        }
        int[] c = new int[z];
        for (int i = 0; i < n; i++) {
            c[t[i].c]++;
        }
        long[][] a = new long[z][];
        for (int i = 0; i < z; i++) {
            a[i] = new long[c[i] + 1];
            a[i][c[i]] = i;
        }
        for (int i = 0; i < n; i++) {
            a[t[i].c][--c[t[i].c]] = -t[i].x;
        }
        for (int i = 0; i < z; i++) {
            Arrays.sort(a[i], 0, a[i].length - 1);
            for (int j = 0; j < a[i].length - 1; j++) {
                a[i][j] = -a[i][j];
            }
            for (int j = 1; j < a[i].length - 1; j++) {
                a[i][j] += a[i][j - 1];
            }
        }
        Arrays.sort(a, new Comparator<long[]>() {
            public int compare(long[] o1, long[] o2) {
                return o2.length - o1.length;
            }
        });
        long res = 0;
        int A = 0, B = 0, C = 0, D = 0;
        for (int cnt = n; cnt > 0; cnt--) {
            long best = (long) -1e18;
            int g = 0, h = 0;
            for (int i = 0; i < z; i++) {
                if (a[i].length < cnt) {
                    break;
                }
                int cc = Math.min(a[i].length - 1, cnt);
                long cur = a[i][cc - 1];
                if (res < best + cur) {
                    res = best + cur;
                    A = g;
                    B = h;
                    C = (int) a[i][a[i].length - 1];
                    D = cc;
                }
                if (best < cur) {
                    best = cur;
                    g = (int) a[i][a[i].length - 1];
                    h = cc;
                }
            }
        }
        println(res);
        println(B + D);
        Arrays.sort(t, new Comparator<T>() {
            public int compare(T o1, T o2) {
                return o2.x - o1.x;
            }
        });
        int c1 = B > D ? A : C, ind1 = 0, ind2 = 0;
        while (B + D > 0) {
            while (t[ind1].c != c1) {
                ind1++;
            }
            print(t[ind1++].i + " ");
            if (c1 == A) {
                B--;
            } else {
                D--;
            }
            c1 = A + C - c1;
            int f = ind1;
            ind1 = ind2;
            ind2 = f;
        }
        println("");

        if (fileIOMode) {
            System.out.println((System.nanoTime() - startTime) / 1e9);
        }
        out.close();
    }

    //-----------------------------------------------------------------------------------

    private static boolean fileIOMode;
    private static String problemName = "a";
    private static BufferedReader in;
    private static PrintWriter out;
    private static StringTokenizer tokenizer;

    public static void main(String[] args) throws Exception {
        fileIOMode = args.length > 0 && args[0].equals("!");
        if (fileIOMode) {
            in = new BufferedReader(new FileReader(problemName + ".in"));
            out = new PrintWriter(problemName + ".out");
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        tokenizer = new StringTokenizer("");

        new Thread(new A()).start();
    }

    private static String nextLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    private static String nextToken() {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    private static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    private static long nextLong() {
        return Long.parseLong(nextToken());
    }

    private static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    private static BigInteger nextBigInteger() {
        return new BigInteger(nextToken());
    }

    private static void print(Object o) {
        if (fileIOMode) {
            System.out.print(o);
        }
        out.print(o);
    }

    private static void println(Object o) {
        if (fileIOMode) {
            System.out.println(o);
        }
        out.println(o);
    }

    private static void printf(String s, Object... o) {
        if (fileIOMode) {
            System.out.printf(s, o);
        }
        out.printf(s, o);
    }
}