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

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

    static class EZebraTower {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            HashMap<Integer, List<Pii>> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int c = in.nextInt();
                int s = in.nextInt();
                if (!map.containsKey(c))
                    map.put(c, new ArrayList<>(0));
                map.get(c).add(Pii.of(s, i + 1));
            }
            for (List<Pii> l : map.values()) {
                l.sort(Comparator.reverseOrder());
            }
            HashMap<Integer, List<Pii>> orig = new HashMap<>(map);

            Map<Integer, Long> tots = new HashMap<>();
            int cPrev = -1;
            int cPrev2 = -1;
            long tPrev = 0;
            long tPrev2 = 0;
            Pii best = null;
            long score = 0;
            for (int i = 0; i < n; i++) {
                List<Integer> toRemove = new ArrayList<>();

                int c1 = -1, c2 = -1;
                for (int c : map.keySet()) {
                    List<Pii> l = map.get(c);
                    if (l.size() <= i) {
                        toRemove.add(c);
                        continue;
                    }
                    tots.merge(c, (long) l.get(i).first, Long::sum);
                    long t = tots.get(c);

                    if (c1 == -1 || t >= tots.get(c1)) {
                        c2 = c1;
                        c1 = c;
                    } else if (c2 == -1 || t >= tots.get(c2)) {
                        c2 = c;
                    }
                }

                if (c1 == -1)
                    break;

                for (int c : toRemove) {
                    map.remove(c);
                }

                long t1 = tots.get(c1);
                long t2 = c2 == -1 ? Long.MIN_VALUE : tots.get(c2);
//            System.out.println("c1 = " + c1);
//            System.out.println("t1 = " + t1);
//            System.out.println("c2 = " + c2);
//            System.out.println("t2 = " + t2);
//            System.out.println("cPrev = " + cPrev);
//            System.out.println("tPrev = " + tPrev);

                if (c1 != -1 && c2 != -1) {
                    long s = t1 + t2;
                    if (s > score) {
                        best = Pii.of(c1, c2);
                        score = s;
                    }
                }
                if (c1 != cPrev && cPrev != -1) {
                    long s = t1 + tPrev;
                    if (s > score) {
                        best = Pii.of(c1, cPrev);
                        score = s;
                    }
                }
//            if (c2 != -1 && c2 != cPrev && cPrev != -1) {
//                long s = t2 + tPrev;
//                if (s > score) {
//                    best = Pii.of(c2, cPrev);
//                    score = s;
//                }

                if (c1 != cPrev2 && c1 != -1 && cPrev2 != -1) {
                    long s = t1 + tPrev2;
                    if (s > score) {
                        best = Pii.of(c1, cPrev2);
                        score = s;
                    }
                }

                cPrev = c1;
                tPrev = t1;
                cPrev2 = c2;
                tPrev2 = t2;
            }

            out.println(score);
            List<Integer> ans = new ArrayList<>();
            List<Pii> l1 = orig.get(best.first);
            List<Pii> l2 = orig.get(best.second);
            for (int i = 0; i < l1.size() && i < l2.size() + 1; i++) {
                ans.add(l1.get(i).second);
                score -= l1.get(i).first;
                if (i < l2.size()) {
                    ans.add(l2.get(i).second);
                    score -= l2.get(i).first;
                }
            }
            out.println(ans.size());
            out.println(Util.join(ans));
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }

    }

    static class Pii implements Comparable<Pii> {
        public final int first;
        public final int second;

        public Pii(int first, int second) {
            this.first = first;
            this.second = second;
        }

        public static Pii of(int first, int second) {
            return new Pii(first, second);
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pii pair = (Pii) o;
            return first == pair.first && second == pair.second;
        }

        public int hashCode() {
            return Arrays.hashCode(new int[]{first, second});
        }

        public String toString() {
            return "(" + first + ", " + second + ')';
        }

        public int compareTo(Pii o) {
            if (first != o.first)
                return Integer.compare(first, o.first);
            return Integer.compare(second, o.second);
        }

    }

    static class Util {
        public static String join(Iterable i) {
            StringBuilder sb = new StringBuilder();
            for (Object o : i) {
                sb.append(o);
                sb.append(" ");
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - 1);
            }
            return sb.toString();
        }

        private Util() {
        }

    }
}