Problem: A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres).

Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body.

Input

The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi (1 ≤ ti ≤ 2; 1 ≤ pi ≤ 104), where ti is the vehicle type (1 – a kayak, 2 – a catamaran), and pi is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.

Output

In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.

Examples

Input

3 2
1 2
2 7
1 3


Output

7
2

Solution (in JAVA):

Solution:


import java.util.Scanner;
import java.util.Vector;

public class Lorry {
    static void metod() throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int v = in.nextInt();

        Vector<Integer> v1 = new Vector<Integer>();
        Vector<Integer> v2 = new Vector<Integer>();
        Vector<Integer> v11 = new Vector<Integer>();
        Vector<Integer> v22 = new Vector<Integer>();
        Vector<Integer> vv = new Vector<Integer>();
        for (int i = 0; i < n; i++) {
            int k = in.nextInt();
            int x = in.nextInt();
            if (k == 1) {
                v1.add(x);
                v11.add(i + 1);
            } else {
                v2.add(x);
                v22.add(i + 1);
            }
            vv.add(x);
        }

        int[][] bm = new int[v1.size()][2];
        for (int i = 0; i < v1.size(); i++) {
            bm[i][0] = v1.get(i);
            bm[i][1] = v11.get(i);
        }

        int[][] km = new int[v2.size()][2];
        for (int i = 0; i < v2.size(); i++) {
            km[i][0] = v2.get(i);
            km[i][1] = v22.get(i);
        }

        qSort(bm);
        qSort(km);

        Vector<Integer> vb = new Vector<Integer>();
        Vector<Integer> vk = new Vector<Integer>();

        int max = 0;
        int b = bm.length;
        int k = km.length;

        while (v > 0) {

            if (v > 1) {
                if (k > 0) {
                    if (b > 1) {

                        if (km[k - 1][0] > bm[b - 1][0] + bm[b - 2][0]) {
                            v -= 2;
                            vk.add(km[k - 1][1]);
                            max += km[k - 1][0];
                            k--;
                        } else {
                            v -= 2;
                            vb.add(bm[b - 1][1]);
                            vb.add(bm[b - 2][1]);
                            max += bm[b - 1][0];
                            max += bm[b - 2][0];
                            b -= 2;
                        }
                    } else {
                        if (b == 1) {
                            if (km[k - 1][0] > bm[b - 1][0]) {
                                v -= 2;
                                vk.add(km[k - 1][1]);
                                max += km[k - 1][0];
                                k--;
                            } else {
                                v -= 1;
                                vb.add(bm[b - 1][1]);
                                max += bm[b - 1][0];
                                b -= 1;
                            }
                        } else {
                            v -= 2;
                            vk.add(km[k - 1][1]);
                            max += km[k - 1][0];
                            k--;
                        }
                    }
                } else {
                    if (b > 0) {
                        v -= 1;
                        vb.add(bm[b - 1][1]);
                        max += bm[b - 1][0];
                        b -= 1;
                    } else {
                        break;
                    }
                }
            } else {
                if (v == 1) {
                    if (k > 0) {
                        if (b > 0) {
                            
                            if (vb.size() != 0 && km[k - 1][0] > vv
                                    .get(vb.get(vb.size() - 1) - 1)
                                    + bm[b - 1][0]) {
                                max -= vv.get(vb.get(vb.size() - 1) - 1);
                                vb.remove(vb.size() - 1);
                                v -= 1;
                                vk.add(km[k - 1][1]);
                                max += km[k - 1][0];
                                k--;
                            } else {
                                v -= 1;
                                vb.add(bm[b - 1][1]);
                                max += bm[b - 1][0];
                                b -= 1;
                            }

                        } else {
                            if (vb.size() == 0) {
                                break;
                            } else {
                                max -= vv.get(vb.get(vb.size() - 1) - 1);
                                vb.remove(vb.size() - 1);
                                v -= 1;
                                vk.add(km[k - 1][1]);
                                max += km[k - 1][0];
                                k--;
                            }
                        }
                    } else {
                        if (b > 0) {
                            v -= 1;
                            vb.add(bm[b - 1][1]);
                            max += bm[b - 1][0];
                            b -= 1;
                        } else {
                            break;
                        }
                    }
                }
            }

        }
        System.out.println(max);

        for (int i = 0; i < vb.size(); i++) {
            System.out.print(vb.get(i) + " ");
        }
        for (int i = 0; i < vk.size(); i++) {
            System.out.print(vk.get(i) + " ");
        }

    }

    static int partition(int a[][], int p, int r) {
        int x = a[r][0];
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (a[j][0] <= x) {
                i++;
                exchange(a, i, j);
            }
        }
        exchange(a, i + 1, r);
        return i + 1;
    }

    static void exchange(int a[][], int x, int y) {
        int t = a[x][0];
        a[x][0] = a[y][0];
        a[y][0] = t;
        t = a[x][1];
        a[x][1] = a[y][1];
        a[y][1] = t;
    }

    static void quickSort(int a[][], int x, int y) {
        int q = 0;

        if (x < y) {
            q = partition(a, x, y);

            quickSort(a, x, q - 1);
            quickSort(a, q + 1, y);
        }
    }

    static void qSort(int a[][]) {
        quickSort(a, 0, a.length - 1);
    }

    public static void main(String[] args) throws Exception {
        Lorry.metod();
    }
}