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 lwc626
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		MyInputReader in = new MyInputReader(inputStream);
		MyOutputWriter out = new MyOutputWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    public void solve(int testNumber, MyInputReader in, MyOutputWriter out) {
        int n = in.nextInt();
        HashMap<Integer, ArrayList<Pair<Integer, Integer>>> My = new HashMap<Integer, ArrayList<Pair<Integer, Integer>>>();

        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (!My.containsKey(a)) {
                My.put(a, new ArrayList<Pair<Integer, Integer>>());
            }
            My.get(a).add(Pair.makePair(b, i + 1));
        }

        int cnt = My.size();
        ArrayList<Pair<Integer, Integer>> order = new ArrayList<Pair<Integer, Integer>>();
        for (Integer p : My.keySet()) {
            ArrayList<Pair<Integer, Integer>> o = My.get(p);
            Collections.sort(o, new Comparator<Pair<Integer, Integer>>() {
                @Override
                public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
                    return o2.first.compareTo(o1.first);
                }
            });
            order.add(Pair.makePair(o.size(), p));
        }

        Collections.sort(order, new Comparator<Pair<Integer, Integer>>() {
            @Override
            public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
                return o1.first.compareTo(o2.first);
            }
        });

        int now = 0;
        int[] index = new int[cnt];
        long[] height = new long[cnt + 1];
        int[] idx = new int[cnt + 1];

        Arrays.fill(index, 0);
        Arrays.fill(height, 0);

        long ret = 0;
        int ans1 = 0, ans2 = 0;

        while ( now < cnt - 1){
            int sz = order.get(now).first;
            for( int j = now ; j < cnt ; j ++){
                int id = order.get( j ).second ;
                int st = Math.min( sz+1 , order.get(j).first);
                while ( index[j] < st )
                   Add( height, idx,cnt,j+1,My.get(id).get(index[j]++).first);
            }
            do{
                int q = Query(height, idx, now + 2, cnt);
                // out.printLine( now + 1 , q );
                if (height[now + 1] + height[q] > ret) {
                    ret = height[now + 1] + height[q];
                    ans1 = order.get(now).second;
                    ans2 = order.get(q - 1).second;
                }
                now++;
            }while (now  < cnt - 1 && order.get(now).first.equals(sz));
        }


        int r = Math.min(My.get(ans1).size(), My.get(ans2).size());

        ArrayList<Integer> ans = new ArrayList<Integer>();

        long ret1 = 0;
        if (My.get(ans1).size() > My.get(ans2).size()) {
            ret1 = put(ans, My.get(ans1), My.get(ans2), r);
        } else {
            ret1 = put(ans, My.get(ans2), My.get(ans1), r);
        }
        if (My.get(ans1).size() != r){
            ans.add(My.get(ans1).get(r).second);
            ret1 += My.get(ans1).get(r).first;
        }
        if (My.get(ans2).size() != r){
            ans.add(My.get(ans2).get(r).second);
            ret1 += My.get(ans2).get(r).first;
        }
        out.printLine(ret1);
        out.printLine(2 * r + (My.get(ans1).size() != My.get(ans2).size() ? 1 : 0));
        for (int i = 0; i < ans.size(); i++) {
            if (i != 0) out.print(" ");
            out.print(ans.get(i));
        }
        out.printLine();
    }

    private long put(ArrayList<Integer> ans, ArrayList<Pair<Integer, Integer>> pairs, ArrayList<Pair<Integer, Integer>> pairs1, int r) {
        long ret = 0;
        for (int i = 0; i < r; i++) {
            ans.add(pairs.get(i).second);
            ret += pairs.get(i).first;
            ans.add(pairs1.get(i).second);
            ret += pairs1.get(i).first;
        }
        return ret;
    }

    private int Query(long[] height, int[] idx, int l, int r) {
        int ret = r;
        while (true) {
            ret = height[ret] > height[r] ? ret : r;
            if (r == l) break;
            for (r -= 1; r - l >= lowbit(r); r -= lowbit(r)) {
                ret = height[ret] > height[idx[r]] ? ret : idx[r];
            }
        }
        return ret;
    }

    private void Add(long[] height, int[] idx, int k, int d, Integer v) {
        height[d] += v;
        for (int i = d; i <= k; i += lowbit(i)) {
            idx[i] = height[idx[i]] > height[d] ? idx[i] : d;

            for (int j = 1; j < lowbit(i); j <<= 1) {
                idx[i] = height[idx[i]] > height[idx[i - j]] ? idx[i] : idx[i - j];
            }
        }
    }

    private int lowbit(int x) {
        return x & (-x);
    }

}

class MyInputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public MyInputReader(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 MyOutputWriter {
    private final PrintWriter writer;

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

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

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

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

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

}

class Pair<U, V> implements Comparable<Pair<U, V>> {
    public final U first;
    public final V second;

    public Pair(U first, V second) {
        this.first = first;
        this.second = second;
    }

    public static <U, V> Pair<U, V> makePair(U first, V second) {
        return new Pair<U, V>(first, second);
    }

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

    public int hashCode() {
        int result = first != null ? first.hashCode() : 0;
        return 31 * result + (second != null ? second.hashCode() : 0);
    }

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

    public int compareTo(Pair<U, V> o) {
        return 1;
        //int value = ((Comparable<U>) second).compareTo(o.second);
        //if (value != 0)
        //    return -value;
        //return -((Comparable<V>) first).compareTo(o.first);
    }

}