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 
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Locale;
import java.util.HashMap;
import java.util.Comparator;
import java.io.OutputStream;
import java.util.RandomAccess;
import java.io.PrintWriter;
import java.util.AbstractList;
import java.io.Writer;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.util.Arrays;
import java.math.BigDecimal;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Set;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
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 {
    public static final long INF = Long.MAX_VALUE / 10;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        Map<Integer, List<Pair<Integer, Integer>>> map = new DefaultMap<Integer, List<Pair<Integer, Integer>>>(new DefaultFactory<List<Pair<Integer, Integer>>>() {
            public List<Pair<Integer, Integer>> create() {
                return new ArrayList<Pair<Integer, Integer>>();
            }
        });
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int color = in.nextInt();
            int size = in.nextInt();
            map.get(color).add(Pair.makePair(size, i + 1));
        }
        long[] maxSingle = new long[n + 2];
        int[] maxSingleId = new int[n + 2];
        Arrays.fill(maxSingle, -INF);
        Arrays.fill(maxSingleId, -1);
        int first = -1, second = -1;
        maxSingle[0] = 0;
        long answer = 0;
        List<Map.Entry<Integer, List<Pair<Integer, Integer>>>> entryList = new ArrayList<Map.Entry<Integer, List<Pair<Integer, Integer>>>>(map.entrySet());
        Collections.sort(entryList, new Comparator<Map.Entry<Integer, List<Pair<Integer, Integer>>>>() {
            public int compare(Map.Entry<Integer, List<Pair<Integer, Integer>>> o1, Map.Entry<Integer, List<Pair<Integer, Integer>>> o2) {
                return Integer.compare(o2.getValue().size(), o1.getValue().size());
            }
        });
        for (Map.Entry<Integer, List<Pair<Integer, Integer>>> entry : entryList) {
            List<Pair<Integer, Integer>> list = entry.getValue();
            Collections.sort(list, Collections.reverseOrder());
            int length = list.size();
            int[] sizes = new int[length];
            for (int i = 0; i < length; i++) {
                sizes[i] = list.get(i).first;
            }
            long[] sum = ArrayUtils.partialSum(sizes);
//            answer = Math.max(answer, sum[length] + Math.max(maxSingle[length], Math.max(maxSingle[length - 1], maxSingle[length + 1])));
            long temp = sum[length] + Math.max(maxSingle[length], Math.max(maxSingle[length - 1], maxSingle[length + 1]));
            if (answer < temp) {
                answer = temp;
                first = entry.getKey();
                if (temp == sum[length] + maxSingle[length]) {
                    second = maxSingleId[length];
                } else if (temp == sum[length] + maxSingle[length - 1]) {
                    second = maxSingleId[length - 1];
                } else {
                    second = maxSingleId[length + 1];
                }
            }
            for (int i = 0; i <= length; i++) {
                if (maxSingle[i] < sum[i]) {
                    maxSingle[i] = sum[i];
                    maxSingleId[i] = entry.getKey();
                }
            }
        }
        out.println(answer);
        List<Integer> list = join(map.get(first), map.get(second));
        out.println(list.size());
        out.printLine(list.toArray());
    }

    private List<Integer> join(List<Pair<Integer, Integer>> first, List<Pair<Integer, Integer>> second) {
        if (first.size() < second.size()) {
            List<Pair<Integer, Integer>> tmp = first;
            first = second;
            second = tmp;
        }
        List<Integer> result = new ArrayList<Integer>();
        for (int i = 0; i < second.size(); i++) {
            result.add(first.get(i).second);
            result.add(second.get(i).second);
        }
        if (first.size() > second.size()) {
            result.add(first.get(second.size()).second);
        }
        return result;
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

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

    public void println(long x) {
        writer.println(x);
    }

    public void println(int x) {
        writer.println(x);
    }

    public void print(Object obj) {
        writer.print(obj);
    }

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

    public void print(char c) {
        writer.print(c);
    }

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

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

    public void printLine(Object... items) {
        printItems(items);
        println();
    }

}

class Pair<A,B> implements Comparable<Pair<A, B>> {
    public final A first;
    public final B second;

    public Pair(A first, B second) {
        this.first = first;
        this.second = second;
    }

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

    public int compareTo(Pair<A, B> anotherPair) {
        @SuppressWarnings ("unchecked") int result = ((Comparable<A>)first).compareTo(anotherPair.first);
        if (result != 0) {
            return result;
        }
        //noinspection unchecked
        return ((Comparable<B>)second).compareTo(anotherPair.second);
    }


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

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Pair pair = (Pair) o;

        if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
        if (second != null ? !second.equals(pair.second) : pair.second != null) return false;

        return true;
    }

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

class DefaultMap<K, V> extends HashMap<K, V> {
    DefaultFactory<V> factory;

    public DefaultMap(DefaultFactory<V> factory) {
        this.factory = factory;
    }

    public V get(Object key) {
        if (!containsKey(key)) {
            //noinspection unchecked
            put((K) key, factory.create());
        }
        return super.get(key);
    }
}

interface DefaultFactory<T> {
    T create();
}

class ArrayUtils {



    public static long[] partialSum(int[] array) {
        int n = array.length;
        long[] result = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            result[i] = result[i - 1] + array[i - 1];
        }
        return result;
    }

}

