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.util.stream.Collector;

public class J implements Runnable {

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

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

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }
        }
    }

    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());
    }

    int[] readIntArray(int size) throws IOException {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        //new Thread(null, new _Solution(), "", 128 * (1L << 20)).start();
        new J().run();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }


    class Cube implements Comparable<Cube> {
        int color, size, index;

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

        @Override
        public int compareTo(Cube o) {
            return o.size - size;
        }
    }

    class CubeArray implements Comparable<CubeArray> {
        long sumCost;
        List<Cube> list;

        public CubeArray(long sumCost, List<Cube> list) {
            this.sumCost = sumCost;
            this.list = list;
        }

        @Override
        public int compareTo(CubeArray o) {
            return Long.compare(o.sumCost, sumCost);
        }
    }

    private void print(List<Cube> a, List<Cube> b) {
        if (a.size() < b.size()) {
            List<Cube> temp = a;
            a = b;
            b = temp;
        }
        for (int i = 0; i < a.size() + b.size(); i++) {
            if (i % 2 == 0) {
                out.print(a.get(i / 2).index + " ");
            } else {
                out.print(b.get(i / 2).index + " ");
            }
        }
    }

    CubeArray answerA, answerB;

    void aggregate(CubeArray a, CubeArray b) {
        if (a == null || b == null) return;
        if (a.list.get(0).color == b.list.get(0).color) return;
        if (answerA == null || a.sumCost + b.sumCost > answerA.sumCost + answerB.sumCost) {
            answerA = a;
            answerB = b;
        }
    }

    private void solve() throws IOException {
        HashMap<Integer, List<Cube>> map = new HashMap<>();
        int n = readInt();
        for (int i = 0; i < n; i++) {
            Cube cube = new Cube(readInt(), readInt(), i + 1);
            List<Cube> cubes = map.computeIfAbsent(cube.color, k -> new ArrayList<>());
            cubes.add(cube);
        }
        int MAX = 100000;
        CubeArray[] first = new CubeArray[MAX + 1];
        CubeArray[] second = new CubeArray[MAX + 1];
        for (Map.Entry<Integer, List<Cube>> e : map.entrySet()) {
            Collections.sort(e.getValue());
            List<Cube> list = e.getValue();
            long sum = 0;
            for (int i = 0; i < e.getValue().size(); i++) {
                sum += list.get(i).size;
                CubeArray cubeArray = new CubeArray(sum, list.subList(0, i + 1));
                if (first[i] == null) {
                    first[i] = cubeArray;
                } else if (first[i].sumCost < cubeArray.sumCost) {
                    second[i] = first[i];
                    first[i] = cubeArray;
                } else if (second[i] == null) {
                    second[i] = cubeArray;
                } else if (second[i].sumCost < cubeArray.sumCost) {
                    second[i] = cubeArray;
                }
            }
        }

        for (int i = 0; i < MAX; i++) {
            aggregate(first[i], second[i]);
            aggregate(first[i], second[i + 1]);
            aggregate(first[i], first[i + 1]);
            aggregate(second[i], second[i + 1]);
            aggregate(second[i], first[i + 1]);
        }
        out.println(answerA.sumCost + answerB.sumCost);
        out.println(answerA.list.size() + answerB.list.size());
        print(answerA.list, answerB.list);
    }

}