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.*;

public class Qual2Task5 implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(null, new Qual2Task5(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            if (System.getProperty("ONLINE_JUDGE") != null) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
    // solution
    boolean[] init;

    void solve() throws IOException {
        int n = readInt();
        Brick[] brick = new Brick[n];
        for (int i = 0; i < n; i++) {
            int f = readInt();
            int s = readInt();
            brick[i] = new Brick(f, s, i + 1);
        }
        Arrays.sort(brick);
        long[] bestRes = new long[n + 3];
        int[] bestId = new int[n + 3];
        init = new boolean[n + 3];

        long sum = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (i == 0 || brick[i].color != brick[i - 1].color) {
                if (count > 0 && bestRes[count] < sum) {
                    bestRes[count] = sum;
                    bestId[count] = brick[i - 1].color;
                    init[count] = true;
                }
                sum = 0;
                count = 0;
            }
            sum += brick[i].size;
            count++;
            //System.err.println("Status " + i + " " + sum + " " + count);
            if (init[count - 1]) {
                compareWithOptimal(sum + bestRes[count - 1], brick[i].color, bestId[count - 1], count, count - 1);
            }
            if (init[count]) {
                compareWithOptimal(sum + bestRes[count], brick[i].color, bestId[count], count, count);
            }
            if (init[count + 1]) {
                compareWithOptimal(sum + bestRes[count + 1], bestId[count + 1], brick[i].color, count + 1, count);
            }

            if (count > 1 && bestRes[count - 1] < sum - brick[i].size) {
                bestRes[count - 1] = sum - brick[i].size;
                bestId[count - 1] = brick[i].color;
                init[count - 1] = true;
            }
        }

        int s1 = 0;
        int s2 = 0;
        for (int i = 0; i < n; i++)//it's 4 am, ok? :)
        {
            if (brick[i].color == start1) {
                s1 = i;
                break;
            }
        }

        for (int i = 0; i < n; i++) {
            if (brick[i].color == start2) {
                s2 = i;
                break;
            }
        }

        StringBuilder res = new StringBuilder();
        out.println(bestSum);
        out.println(length1 + length2);
        //System.err.println(length1 + " " + length2 + " " + s1 + " " + s2);
        while (length1 > 0) {
            if (length1-- > 0) {
                res.append(brick[s1++].id).append(' ');
            }
            if (length2-- > 0) {
                res.append(brick[s2++].id).append(' ');
            }
        }
        out.println(res.toString());
    }
    long bestSum = 0;
    long start1 = 0;
    long start2 = 0;
    long length1 = 0;
    long length2 = 0;

    private void compareWithOptimal(long sum, int id1, int id2, int len1, int len2) {
        if (len1 <= 0 || len2 <= 0 || len1 + len2 < 2) {
            return;
        }
        //System.err.println("cwo " + sum + " " + id1 + " " + id2 + " " + len1 + " " + len2);
        if (bestSum < sum) {
            bestSum = sum;
            start1 = id1;
            start2 = id2;
            length1 = len1;
            length2 = len2;
            //System.err.println("+");
        }
    }

    class Brick implements Comparable<Brick> {

        int color;
        long size;
        int id;

        Brick(int color, long size, int id) {
            this.color = color;
            this.size = size;
            this.id = id;
        }

        @Override
        public int compareTo(Brick t) {
            if (this.color == t.color) {
                return (((Long) t.size).compareTo(this.size));
            } else {
                return (this.color - t.color);
            }
        }
    }
}