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.
The first line contains a pair of integer numbers *n* and *v* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>; 1 ≤ *v* ≤ 10<sup class="upper-index">9</sup>), 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 *t*<sub class="lower-index">*i*</sub>, *p*<sub class="lower-index">*i*</sub> (1 ≤ *t*<sub class="lower-index">*i*</sub> ≤ 2; 1 ≤ *p*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">4</sup>), where *t*<sub class="lower-index">*i*</sub> is the vehicle type (1 – a kayak, 2 – a catamaran), and *p*<sub class="lower-index">*i*</sub> is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.
import operator


class Stone:
    """
    石头类：
        index 编号；
        value 价值；
        space 占用空间；
        rou   价值密度；
    """

    def __init__(self, index, value, space):
        self.index = index
        self.value = value
        self.space = space
        self.rou = self.value / self.space


class Bag:
    """
    背包类：
        space_left  剩余空间；
        stones_index已放入的石头编号；

        put_stones_in()将最大价值的石头放入背包
    """

    def __init__(self, space):
        self.values = 0
        self.space_left = space
        self.stones_index = set()
        self.i_last = -1  # 已装入背包的石头中最后一个体积为1的石头下标
        self.i_first = -1  # 未装入背包的石头中第一个体积为1的石头下标

    def get_value1(self, stone):
        if self.i_last == -1 & self.i_first == -1:
            return 0
        if self.i_last == -1 & self.i_first != -1:
            return stone[self.i_first].value
        if self.i_last != -1 & self.i_first == -1:
            return stone[self.i_last].value
        if self.i_last != -1 & self.i_first != -1:
            return stone[self.i_last].value + stone[self.i_first].value

    def put_stones_in(self, my_stones):
        for i in range(len(my_stones)):
            if self.space_left >= my_stones[i].space:
                self.stones_index.add(my_stones[i].index)
                self.values += my_stones[i].value
                self.space_left -= my_stones[i].space
            else:
                break

        # 石头装完了
        if (len(my_stones) == len(self.stones_index)) | (self.space_left == 0):
            return
        else:
            # 更新i_last&i_first
            for i in range(len(self.stones_index) - 1, 0, -1):
                if my_stones[i].space == 1:
                    self.i_last = i
                    break
            for i in range(len(self.stones_index), len(my_stones) - 1):
                if my_stones[i].space == 1:
                    self.i_first = i
                    break

            value1 = self.get_value1(my_stones)
            value2 = my_stones[len(self.stones_index)].value
            if value1 >= value2:
                if self.i_first != -1:
                    self.stones_index.add(my_stones[self.i_first].index)
                    self.values += my_stones[self.i_first].value
                    self.space_left -= 1
            else:
                if self.i_last != -1:
                    self.values -= my_stones[len(self.stones_index)].value
                    self.stones_index.add(my_stones[len(self.stones_index)].index)
                    self.stones_index.remove(my_stones[self.i_last].index)
                    self.values += my_stones[self.i_last].value
                    self.space_left -= 1


def get_stones(num):
    Stones = []
    for i in range(num):
        spv = input()
        Stones.append(Stone(i + 1, eval(spv.split(" ")[1]), eval(spv.split(" ")[0])))
    Stones.sort(key=operator.attrgetter('rou'), reverse=True)  # 按rou降序排序
    return Stones


nv = input()
n = eval(nv.split(" ")[0])  # 石头数量
bag = Bag(eval(nv.split(" ")[1]))  # 创建背包
stones = get_stones(n)  # 获取所有石头按照价值密度降序排序后的序列

bag.put_stones_in(stones)
print(f"{bag.values}")
for k in bag.stones_index:
    print(f"{k}", end=" ")


 		 					        		  			 	  			