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:
//package com.company;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

//@author Maurice Saldivar
public class Main
{
    public static class Boat
    {
        int type;
        int capacity;
        int position;

        public Boat(int type, int capacity, int position)
        {
            this.type = type;
            this.capacity = capacity;
            this.position = position;
        }
    }
    static Comparator<Boat> comparator = new Comparator<Boat>() {
        @Override
        public int compare(Boat o1, Boat o2) {
            return o2.capacity - o1.capacity;
        }
    };

    static Comparator<Boat> comparator2 = new Comparator<Boat>() {
        @Override
        public int compare(Boat o1, Boat o2) {
            return o1.type - o2.type;
        }
    };


    public static void main(String[] args) throws IOException {
        BufferedReader aReader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter aWriter = new PrintWriter(System.out, true);
        int n = 0;
        int volume = 0;
        int type = 0;
        int carryCap = 0;
        int kayakLength = 0;
        int max = 0;
        String tokens[];
        tokens = aReader.readLine().split(" ");
        n = Integer.parseInt(tokens[0]);
        volume = Integer.parseInt(tokens[1]);
        ArrayList<Boat> boatList = new ArrayList<Boat>();

        for(int i = 0; i < n; i++)
        {
            tokens = aReader.readLine().split(" ");
            type = Integer.parseInt(tokens[0]);
            carryCap = Integer.parseInt(tokens[1]);

            if (type == 1)
            {
                boatList.add(new Boat(type, carryCap, i));
                kayakLength++;
            }
            else
                boatList.add(new Boat(type, carryCap, i));
        }

        //I sort the array first by type than by capacity for both types
        ArrayList<Boat> SortedBoatList = new ArrayList<Boat>(boatList);
        Collections.sort(SortedBoatList, comparator2);
        Collections.sort(SortedBoatList.subList(0, kayakLength), comparator);
        Collections.sort(SortedBoatList.subList(kayakLength, n), comparator);
        ArrayList<Boat> finalList = new ArrayList<Boat>();

        int start = 0;
        int end = kayakLength;
        int finalLength = n;

        //to get true length
        while(volume > 0)
        {
            if(volume == 1)
            {
                if(start < kayakLength)
                {
                    max += SortedBoatList.get(start).capacity;
                    finalList.add(SortedBoatList.get(start));
                    start++;
                    volume--;
                }else
                    break;
            }else
            {
                if(start < kayakLength && end < finalLength)
                {
                    //add two kayaks together and see if the sum is greater than one catamarans. Since two kayaks equal one catamarans. I only want to add a
                    //catamarans if its capacity is greater than the two kayaks.
                    if (start + 1 < kayakLength)
                        if (SortedBoatList.get(start).capacity + SortedBoatList.get(start + 1).capacity > SortedBoatList.get(end).capacity) {
                            max += SortedBoatList.get(start).capacity;
                            finalList.add(SortedBoatList.get(start));
                            start++;
                            volume--;
                        } else if (SortedBoatList.get(start).capacity > SortedBoatList.get(end).capacity) {
                            max += SortedBoatList.get(start).capacity;
                            finalList.add(SortedBoatList.get(start));
                            start++;
                            volume--;
                        } else {
                            max += SortedBoatList.get(end).capacity;
                            finalList.add(SortedBoatList.get(end));
                            end++;
                            volume -= 2;
                        }
                    else
                    {
                        max += SortedBoatList.get(end).capacity;
                        finalList.add(SortedBoatList.get(end));
                        end++;
                        volume -= 2;
                    }
                }else if(start < kayakLength) //only kayaks
                {
                    max += SortedBoatList.get(start).capacity;
                    finalList.add(SortedBoatList.get(start));
                    start++;
                    volume--;
                }else if ( end < finalLength ) //only catamarans
                {
                    max += SortedBoatList.get(end).capacity;
                    finalList.add(SortedBoatList.get(end));
                    end++;
                    volume -= 2;
                }else
                    break;
            }
        }


        aWriter.println(max);
        for (Boat val : finalList)
            aWriter.println(val.position + 1);


    }
}