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 B;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class B3_Lorry_2 {
    public static void main(String args[]) throws IOException {
        int vehiclesCount;
        int freeSpace;
        List<Kayak> kayaks = new ArrayList<>();
        List<Catamaran> catamarans = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String[] firstArgs = br.readLine().split(" ");
            vehiclesCount = Integer.parseInt(firstArgs[0]);
            freeSpace = Integer.parseInt(firstArgs[1]);
            for (int i = 0; i < vehiclesCount; i++) {
                String[] line = br.readLine().split(" ");
                if (Integer.parseInt(line[0]) == 1) {
                    kayaks.add(new Kayak(i + 1, Integer.parseInt(line[1])));
                } else {
                    catamarans.add(new Catamaran(i + 1, Integer.parseInt(line[1])));
                }
            }
        }
        Collections.sort(kayaks);
        Collections.sort(catamarans);
        int kayakCount = 1;
        for (Kayak kayak : kayaks) {
//            System.out.println(kayakCount + ") kayak number: " + kayak.number + ". kayak capacity: " + kayak.capacity);
            kayakCount++;
        }
        int catamaranCount = 1;
        for (Catamaran catamaran : catamarans) {
//            System.out.println(catamaranCount + ") catamaran number: " + catamaran.number + ". catamaran capacity: " + catamaran.capacity);
            catamaranCount++;
        }
//        int sum = 0;
//        for (int i = 0; i < 25; i++) {
//            sum = sum + kayaks.get(i).capacity;
//        }
//        int kayaksum = sum;
////        System.out.println("KAYAK SUM: " + kayaksum);
//        for (int i = 0; i < 1; i++) {
//            sum = sum + catamarans.get(i).capacity;
//        }
//        System.out.println("CATAMARAN SUM: " + (sum - kayaksum));
        int currentCapacity = 0;
        int maxCapacity;
        int resultCatamaran;
        int resultKayak;
//        System.out.println("currentCapacity " + currentCapacity);
        int currentKayak = -1;
        while (freeSpace > 0 && currentKayak < kayaks.size() - 1) {
            currentCapacity = currentCapacity + kayaks.get(currentKayak + 1).capacity;
            freeSpace--;
            currentKayak++;
        }
        int currentCatamaran = -1;
        if (freeSpace > 0) {
            while (freeSpace > 1 && currentCatamaran < catamarans.size() - 1) {
                currentCapacity = currentCapacity + catamarans.get(currentCatamaran + 1).capacity;
                freeSpace = freeSpace - 2;
                currentCatamaran++;
            }
        }

        maxCapacity = currentCapacity;
        resultKayak = currentKayak;
        resultCatamaran = currentCatamaran;
        List<Integer> result = new ArrayList<>();
        if (currentKayak < kayaks.size() - 1 || currentCatamaran < catamarans.size() - 1) {
            if (currentCatamaran == catamarans.size() - 1) {
                for (int i = 0; i < currentCatamaran; i++) {
                    result.add(catamarans.get(i).number);
                }
                for (int i = 0; i < currentKayak; i++) {
                    result.add(kayaks.get(i).number);
                }
            } else {
                while (currentKayak >= 0 && currentCatamaran < catamarans.size() - 1) {
                    currentCapacity = currentCapacity
                            - kayaks.get(currentKayak).capacity
                            + catamarans.get(currentCatamaran + 1).capacity;
                    currentKayak--;
                    freeSpace = freeSpace - 1;
                    // error
                    if (freeSpace < 0 && currentKayak >= 0) {
                        currentCapacity = currentCapacity - kayaks.get(currentKayak).capacity;
                        currentKayak--;
                        freeSpace++;
                    }
                    currentCatamaran++;
//                    System.out.println("currentCapacity: " + currentCapacity + ", currentKayak: " + currentKayak + ", currentCatamaran: " + currentCatamaran);
                    if (currentCapacity > maxCapacity) {
                        maxCapacity = currentCapacity;
                        resultCatamaran = currentCatamaran;
                        resultKayak = currentKayak;
//                        System.out.println("maxCapacity" + maxCapacity);
                    }
                }
                for (int i = 0; i <= resultCatamaran; i++) {
                    result.add(catamarans.get(i).number);
                }
                for (int i = 0; i <= resultKayak; i++) {
                    result.add(kayaks.get(i).number);
                }
            }
        } else {
            for (Catamaran catamaran : catamarans) {
                result.add(catamaran.number);
            }
            for (Kayak kayak : kayaks) {
                result.add(kayak.number);
            }
        }
//
//        System.out.println("kayaks: " + (resultKayak + 1));
//        System.out.println("catamarans: " + (resultCatamaran + 1));
        System.out.println(maxCapacity);
        for (Integer integer : result) {
            System.out.print(integer + " ");
        }
    }

    static class Kayak implements Comparable<Kayak>{
        int number;
        int capacity;

        public Kayak(int number, int capacity) {
            this.number = number;
            this.capacity = capacity;
        }

        @Override
        public int compareTo(Kayak o) {
            if (this.capacity > o.capacity) {
                return -1;
            } else if (this.capacity < o.capacity) {
                return 1;
            } else {
                return 0;
            }
        }
    }

    static class Catamaran implements Comparable<Catamaran>{
        int number;
        int capacity;

        public Catamaran(int number, int capacity) {
            this.number = number;
            this.capacity = capacity;
        }

        @Override
        public int compareTo(Catamaran o) {
            if (this.capacity > o.capacity) {
                return -1;
            } else if (this.capacity < o.capacity) {
                return 1;
            } else {
                return 0;
            }
        }
    }
}