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.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nova
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {

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

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

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

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int[] size = new int[n];
        int[] color = new int[n];
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < n; i++) {
            color[i] = in.nextInt();
            size[i] = in.nextInt();
            map.put(color[i], 0);
        }

        // Roi rac hoa gia tri Color[i]
        int cntColors = 0;
        for (Integer key : map.keySet())
            map.put(key, cntColors++);
        for (int i = 0; i < n; i++)
            color[i] = map.get(color[i]);

        final ArrayList<Cube>[] cubes = new ArrayList[cntColors];
        for (int i = 0; i < cntColors; i++)
            cubes[i] = new ArrayList<Cube>();
        for (int i = 0; i < n; i++)
            cubes[color[i]].add(new Cube(size[i], color[i], i + 1));

        Integer[] ids = new Integer[cntColors];
        for (int i = 0; i < cntColors; i++) {
            Collections.sort(cubes[i]);
            ids[i] = i;
        }
        Arrays.sort(ids, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return -(cubes[o1].size() - cubes[o2].size());
            }
        });

        long[] biggest = new long[n + 1];
        int[] biggestId = new int[n + 1];
        Arrays.fill(biggest, -1);
        Arrays.fill(biggestId, -1);

        long best = 0;
        int cnt1 = -1, cnt2 = -1;
        int best1 = -1, best2 = -1;

        for (int i = 0; i < cntColors; i++) {
            int cur = ids[i];
            int count = cubes[cur].size();

            long sum = 0;
            for (Cube c : cubes[cur]) sum += c.size;

            int mode = 2;
            long curBest = -1;
            for (int j = -1; j <= 1; j++) {
                if (curBest < biggest[count + j]) {
                    mode = j;
                    curBest = biggest[count + mode];
                }
            }
            if (curBest != -1) {
                if (best < curBest + sum) {
                    int otCount = count + mode;
                    best = curBest + sum;
                    cnt1 = count;
                    cnt2 = otCount;
                    best1 = cur;
                    best2 = biggestId[otCount];
                }
            }

            sum = 0;
            for (int j = 0; j < cubes[cur].size(); j++) {
                sum += cubes[cur].get(j).size;
                if (biggest[j + 1] < sum) {
                    biggest[j + 1] = sum;
                    biggestId[j + 1] = cur;
                }
            }
        }

        out.println(best);
        out.println(cnt1 + cnt2);
        if (cnt1 > cnt2) out.print(cubes[best1].get(cnt1 - 1).id + " ");
        for (int i = 0; i < Math.min(cnt1, cnt2); i++)
            out.print(cubes[best2].get(i).id + " " + cubes[best1].get(i).id + " ");
        if (cnt2 > cnt1) out.print(cubes[best2].get(cnt2 - 1).id);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    }

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            writer.print(objects[i]);
        }
    }

    public void println(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
}