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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;

/* by Skyly */

public class VKCup2012_Qual2_ProblemE {
    static HashMap<Integer, Integer> hashMap;

    static class Cube implements Comparable<Cube> {
        final int c;
        final int s;
        final int id;
        
        Cube(int c, int s, int id) {
            this.c = c;
            this.s = s;
            this.id = id;
        }
        public int compareTo(Cube cube) {
            return -(new Integer(s).compareTo(cube.s));
        }
    }
    
    static class HeightList {
        final ArrayList<Cube> list = new ArrayList<Cube>();
        
        public void add(Cube cube) {
            list.add(cube);
        }
        public Cube get(int index) {
            return list.get(index);
        }
        public void sort() {
            Collections.sort(list);
        }
        public int size() {
            return list.size();
        }
    }
    
    static class Prefix implements Comparable<Prefix> {
        final int c;
        final int len;
        final long hSum;
        
        Prefix(int c, int len, long hSum) {
            this.c = c;
            this.len = len;
            this.hSum = hSum;
        }
        public int compareTo(Prefix prefix) {
            return -(new Long(hSum).compareTo(prefix.hSum));
        }
    }
    
    static class PrefixList {
        final ArrayList<Prefix> list = new ArrayList<Prefix>();
        
        public void add(Prefix val) {
            list.add(val);
        }
        public void sort() {
            Collections.sort(list);
        }
        public Prefix get(int k) {
            if (list.size() < k) return null;
            else return list.get(k - 1);
        }
    }
    
    private void solve() throws IOException {
        int n = nextInt();
        Cube[] cube = new Cube[n];
        hashMap = new HashMap<Integer, Integer>();
        for (int i = 0; i < n; ++i) {
            int c = nextInt();
            int s = nextInt();
            if (!hashMap.containsKey(c)) {
                int currSize = hashMap.size();
                hashMap.put(c, currSize);
            }
            c = hashMap.get(c);
            cube[i] = new Cube(c, s, i + 1);
        }
        int X = hashMap.size();
        HeightList[] hList = new HeightList[X];
        for (int i = 0; i < X; ++i) {
            hList[i] = new HeightList();
        }
        for (int i = 0; i < n; ++i) {
            hList[cube[i].c].add(cube[i]);
        }
        int maxLen = 0;
        for (int i = 0; i < X; ++i) {
            hList[i].sort();
            maxLen = Math.max(maxLen, hList[i].size());
        }
        PrefixList[] prefixList = new PrefixList[maxLen];
        for (int i = 0; i < maxLen; ++i) {
            prefixList[i] = new PrefixList();
        }
        for (int i = 0; i < X; ++i) {
            long hSum = 0;
            for (int j = 0; j < hList[i].size(); ++j) {
                hSum += hList[i].get(j).s;
                prefixList[j].add(new Prefix(i, j, hSum));
            }
        }
        for (int i = 0; i < maxLen; ++i) {
            prefixList[i].sort();
        }
        long ans = 0;
        Prefix[] sel = new Prefix[2];
        //same amount for both colors
        for (int i = 0; i < maxLen; ++i) {
            Prefix pA = prefixList[i].get(1);
            Prefix pB = prefixList[i].get(2);
            if (pA == null || pB == null) continue;
            long tmp = pA.hSum + pB.hSum;
            if (tmp > ans) {
                ans = tmp;
                sel[0] = pA;
                sel[1] = pB;
            }
        }
        //one more cube than the other color
        for (int i = 1; i < maxLen; ++i) {
            Prefix pA = prefixList[i].get(1);
            Prefix pB = prefixList[i - 1].get(1);
            if (pA == null || pB == null) continue;
            if (pA.c != pB.c) {
                long tmp = pA.hSum + pB.hSum;
                if (tmp > ans) {
                    ans = tmp;
                    sel[0] = pA;
                    sel[1] = pB;
                }
            } else {
                pA = prefixList[i].get(1);
                pB = prefixList[i - 1].get(2);
                if (pA != null && pB != null) {
                    long tmp = pA.hSum + pB.hSum;
                    if (tmp > ans) {
                        ans = tmp;
                        sel[0] = pA;
                        sel[1] = pB;
                    }
                }
                pA = prefixList[i].get(2);
                pB = prefixList[i - 1].get(1);
                if (pA != null && pB != null) {
                    long tmp = pA.hSum + pB.hSum;
                    if (tmp > ans) {
                        ans = tmp;
                        sel[0] = pA;
                        sel[1] = pB;
                    }
                }
            }
        }
        writer.println(ans);
        writer.println(sel[0].len + sel[1].len + 2);
        for (int i = 0; i <= Math.max(sel[0].len, sel[1].len); ++i) {
            for (int j = 0; j < 2; ++j) {
                if (i <= sel[j].len) writer.print(hList[sel[j].c].get(i).id + " ");
            }
        }
        writer.println();
    }
    
    public static void main(String[] args) {
        new VKCup2012_Qual2_ProblemE().run();
    }

    BufferedReader reader;
    PrintWriter writer;
    StringTokenizer tokenizer;

    public void run() {
        try {
            //long startTime = System.currentTimeMillis();
            reader = new BufferedReader(new InputStreamReader(System.in));
            writer = new PrintWriter(System.out);
            tokenizer = null;
            solve();
            writer.flush();
            reader.close();
            writer.close();
            //System.err.println("Execution time: " + (System.currentTimeMillis() - startTime) + " ms");
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
    
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    public char[] nextCharArray() throws IOException {
        return nextToken().toCharArray();
    }
    public char nextChar() throws IOException {
        String buffer = nextToken();
        if (buffer.length() > 1) throw new IOException();
        return buffer.charAt(0);
    }
    public String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
    
}