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:
//package codeforces;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class E implements Closeable {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

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

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    final int MOD = 1000 * 1000 * 1000 + 7;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    int pow(int x, int k) {
        int result = 1;
        while (k > 0) {
            if (k % 2 == 1) {
                result = product(result, x);
            }
            x = product(x, x);
            k /= 2;
        }
        return result;
    }

    @SuppressWarnings("unchecked")
    void solve() throws IOException {
        int n = nextInt();
        class Cube {
            int color, size, id;

            public Cube(int color, int size, int id) {
                this.color = color;
                this.size = size;
                this.id = id;
            }
        }
        Cube[] cubes = new Cube[n];
        for(int i = 0; i < n; i++) {
            cubes[i] = new Cube(nextInt(), nextInt(), i + 1);
        }
        Arrays.sort(cubes, new Comparator<Cube>() {
            @Override
            public int compare(Cube o1, Cube o2) {
                return -Integer.compare(o1.size, o2.size);
            }
        });
        Map<Integer, List<Cube>> colorToCubes = new HashMap<>();
        Map<Integer, Long> colorToSizeSum = new HashMap<>();
        class CubeSubListInfo implements Comparable<CubeSubListInfo> {
            int color;
            long sizeSum;
            int cubesCount;

            public CubeSubListInfo(int color, long sizeSum, int cubesCount) {
                this.color = color;
                this.sizeSum = sizeSum;
                this.cubesCount = cubesCount;
            }

            @Override
            public int compareTo(CubeSubListInfo o) {
                return Long.compare(sizeSum, o.sizeSum);
            }
        }
        List<Queue<CubeSubListInfo>> tops = new ArrayList<>(n + 1);
        for(int i = 0; i <= n; i++) {
            tops.add(new PriorityQueue<CubeSubListInfo>());
        }
        for (Cube cube : cubes) {
            List<Cube> cubeList = colorToCubes.get(cube.color);
            if(cubeList == null) {
                cubeList = new ArrayList<>();
                colorToCubes.put(cube.color, cubeList);
            }
            Long currentSizeSum = colorToSizeSum.get(cube.color);
            if(currentSizeSum == null) {
                currentSizeSum = 0l;
            }
            cubeList.add(cube);
            currentSizeSum += cube.size;
            colorToSizeSum.put(cube.color, currentSizeSum);
            final Queue<CubeSubListInfo> q = tops.get(cubeList.size());
            q.offer(new CubeSubListInfo(cube.color, currentSizeSum, cubeList.size()));
            if(q.size() > 2) {
                q.poll();
            }
        }
        long best = 0;
        CubeSubListInfo c1 = null, c2 = null;
        for(int q = 2; q <= n; q++) {
            int l1 = q / 2;
            int l2 = q - l1;
            for (CubeSubListInfo ci : tops.get(l1)) {
                for (CubeSubListInfo cj : tops.get(l2)) {
                    if(ci.color != cj.color && ci.sizeSum + cj.sizeSum > best) {
                        best = ci.sizeSum + cj.sizeSum;
                        c1 = cj;
                        c2 = ci;
                    }
                }
            }
        }
        writer.println(best);
        writer.println(c1.cubesCount + c2.cubesCount);
        final List<Cube> cubes1 = colorToCubes.get(c1.color);
        final List<Cube> cubes2 = colorToCubes.get(c2.color);
        for(int i = 0; i < c1.cubesCount + c2.cubesCount; i++) {
            if(i % 2 == 0) {
                writer.print(cubes1.get(i / 2).id + " ");
            } else {
                writer.print(cubes2.get(i / 2).id + " ");
            }
        }
    }

    public static void main(String[] args) throws IOException {
        try(E e = new E()) {
            e.solve();
        }
    }

    @Override
    public void close() throws IOException {
        reader.close();
        writer.close();
    }
}