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.*;
import java.io.*;

public class Driver {

    /* need to give 1's precedence,
    * try taking a ratio of capacity / type
    */
    public static class Vehicle {
        int type;
        int capacity;
        int position;
        double score;

        public Vehicle(int t, int c, int p) {
            this.type = t;
            this.capacity = c;
            this.position = p;
            this.score = (double) capacity / type;
        }
    }

    static Comparator<Vehicle> comparator = new Comparator<Vehicle>() {
        @Override
        public int compare(Vehicle v1, Vehicle v2) {
            return v2.capacity - v1.capacity;
        }
    };

    static Comparator<Vehicle> compareByScore = new Comparator<Vehicle>() {
        @Override
        public int compare(Vehicle v1, Vehicle v2) {
            return Double.compare(v2.score, v1.score);
        }
    };

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] file = br.readLine().split("\\s+");
        int n = Integer.parseInt(file[0]);
        int v = Integer.parseInt(file[1]);

        List<Vehicle> kayaks = new ArrayList<Vehicle>();
        List<Vehicle> catamarans = new ArrayList<Vehicle>();

        for(int i = 0; i < n; i++) {
            String[] line = br.readLine().split("\\s+");
            int type = Integer.parseInt(line[0]);
            int capacity = Integer.parseInt(line[1]);
            if(type == 1) {
                kayaks.add(new Vehicle(type, capacity, i + 1));
            }
            else {
                catamarans.add(new Vehicle(type, capacity, i + 1));
            }
        }

        List<Vehicle> sortedKayaks = new ArrayList<Vehicle>(kayaks);
        List<Vehicle> sortedCatamarans = new ArrayList<Vehicle>(catamarans);

        List<Vehicle> sortedVehicles = new ArrayList<Vehicle>();
        List<Vehicle> answerList = new ArrayList<Vehicle>();
        int kayaksLength = sortedKayaks.size();
        int catamaransLength = sortedCatamarans.size();

        Collections.sort(sortedKayaks,comparator);
        Collections.sort(sortedCatamarans,comparator);

        for(int j = 0; j < kayaksLength; j++) {
            sortedVehicles.add(sortedKayaks.get(j));
        }
        for(int k = 0; k < catamaransLength; k++) {
            sortedVehicles.add(sortedCatamarans.get(k));
        }

        // keep track of where we are in our array
        int smallBoatLength = kayaksLength;
        int bigBoatLength = n;
        int start = 0;
        int end = smallBoatLength;
        int maxVolume = 0;

        while (v > 0) {
            if (v == 1) {
                if (start < smallBoatLength) {
                    maxVolume += sortedVehicles.get(start).capacity;
                    answerList.add(sortedVehicles.get(start));
                    start++;
                    v--;
                } 
                else {
                    break;
                }
            } 
            else {
                if (start < smallBoatLength && end < bigBoatLength) {
                    if ((start + 1 < smallBoatLength ? sortedVehicles.get(start).capacity + sortedVehicles.get(start + 1).capacity : sortedVehicles.get(start).capacity) > sortedVehicles.get(end).capacity) {
                        maxVolume += sortedVehicles.get(start).capacity;
                        answerList.add(sortedVehicles.get(start));
                        start++;
                        v--;
                    } 
                    else {
                        maxVolume += sortedVehicles.get(end).capacity;
                        answerList.add(sortedVehicles.get(end));
                        end++;
                        v -= 2;
                    }
                } 
                else if (start < smallBoatLength) {
                    maxVolume += sortedVehicles.get(start).capacity;
                    answerList.add(sortedVehicles.get(start));
                    start++;
                    v--;
                } 
                else if (end < bigBoatLength) {
                    maxVolume += sortedVehicles.get(end).capacity;
                    answerList.add(sortedVehicles.get(end));
                    end++;
                    v -= 2;
                } 
                else
                    break;
            }
        }

        System.out.println(maxVolume);
        for(Vehicle vehicle : answerList) {
            System.out.print(vehicle.position + " ");
        }

        System.exit(0);
    }
}