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.ArrayList;
import java.util.HashMap;
import java.awt.Point;
import java.util.Set;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Maxim Gladkikh 
 */
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);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
        HashMap<Integer, ArrayList<IntPair>> map = new HashMap<Integer, ArrayList<IntPair>>();
        int n = in.nextInt();
        for (int i = 0; i < n; ++i) {
            int c = in.nextInt();
            int len = in.nextInt();
            ArrayList<IntPair> list = map.get(c);
            if (list == null) {
                map.put(c, list = new ArrayList<IntPair>());
            }
            list.add(new IntPair(len, i));
        }
        for (ArrayList<IntPair> list : map.values()) {
            Collections.sort(list);
            Collections.reverse(list);
        }
        HashMap<Integer, Long> current = new HashMap<Integer, Long>(); 
        for (int id : map.keySet()) {
            current.put(id, map.get(id).get(0).a * 1l);
        }
        long ans = 0;
        int ansId1 = -1;
        int ansId2 = -1;
        int size1 = -1;
        int size2 = -1;
        for (int pos = 1; !current.isEmpty(); ++pos) {
            long curMax = 0;
            int curMaxId = -1;
            long curMax2 = 0;
            int curMaxId2 = -1;
            long nextMax = 0;
            int nextMaxId = 0;
            long nextMax2 = 0;
            int nextMaxId2 = -1;
            HashMap<Integer, Long> next = new HashMap<Integer, Long>();
            for (int id  : current.keySet()) {
                long val = current.get(id);
                if (val >= curMax) {
                    curMax2 = curMax;
                    curMaxId2 = curMaxId;
                    curMax = val;
                    curMaxId = id;
                }   else if (val > curMax2) {
                    curMax2 = val;
                    curMaxId2 = id;
                }
                ArrayList<IntPair> list = map.get(id);
                if (list.size() <= pos) {
                    continue;
                }
                long nextVal = val + list.get(pos).a;
                next.put(id, nextVal);
                if (nextVal >= nextMax) {
                    nextMax2 = nextMax;
                    nextMaxId = id;
                    nextMax = nextVal;
                } else if (nextVal > nextMax2) {
                    nextMax2 = nextVal;
                    nextMaxId2 = id;
                }
            }
            if (curMax2 > 0 && ans < curMax + curMax2) {
                ans = curMax + curMax2;
                ansId1 = curMaxId;
                ansId2 = curMaxId2;
                size1 = size2 = pos;
            }
            if (curMaxId == nextMaxId) {
                if (ans < curMax + nextMax2 && nextMax2 > 0) {
                    ans = curMax + nextMax2;
                    ansId1 = nextMaxId2;
                    ansId2 = curMaxId;
                    size1 = pos + 1;
                    size2 = pos;
                }
                if (ans < nextMax + curMax2 && curMax2 > 0 && nextMax > 0) {
                    ans = nextMax + curMax2;
                    ansId1 = nextMaxId;
                    ansId2 = curMaxId2;
                    size1 = pos + 1;
                    size2 = pos;
                }
                if (ans < nextMax + curMax2 && nextMax > 0 && curMax2 > 0) {
                    ans = nextMax + curMax2;
                    ansId1 = nextMaxId;
                    ansId2 = curMaxId2;
                    size1 = pos + 1;
                    size2 = pos;
                }
            } else if (ans < curMax + nextMax && nextMax > 0) {
                ans = curMax + nextMax;
                ansId1 = nextMaxId;
                ansId2 = curMaxId;
                size1 = pos + 1;
                size2 = pos;
            }
            current = next;
        }
        out.println(ans);
        out.println((size1 + size2));
        ArrayList[] lists = {map.get(ansId1), map.get(ansId2)};
        for (int i = 0; i < size1 + size2; ++i) {
            out.print((((IntPair)(lists[i % 2].get(i / 2))).b + 1) + " ");
        }
        out.println();
	}
}

class InputReader {
    private StringTokenizer tokenizer;
    private BufferedReader reader;

    public InputReader(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
    }

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

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

    }

class IntPair implements Comparable<IntPair> {
    public int a;
    public int b;

    public IntPair(int a, int b) {
        this.a = a;
        this.b = b;
    }

    public int compareTo(IntPair o) {
        if (a == o.a) {
            return b - o.b;
        }
        return a - o.a;
    }
}