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

public class Lorry {

	public static class WaterborneVehicle implements Comparable<WaterborneVehicle>{
		public int order;
		public int capacity = -1;
		
		@Override
		public int compareTo(WaterborneVehicle waterborneVehicle){
			return (waterborneVehicle.capacity - this.capacity);
		}

	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		String []strLine=br.readLine().split("\\s+");
		int vehiclesNum = Integer.parseInt(strLine[0]);
		int lorryVol = Integer.parseInt(strLine[1]);
		//WaterborneVehicle[] kayak= new WaterborneVehicle[vehiclesNum];
		//WaterborneVehicle[] catamaran= new WaterborneVehicle[vehiclesNum];
		ArrayList<WaterborneVehicle> kayak= new ArrayList<Lorry.WaterborneVehicle>();
		ArrayList<WaterborneVehicle> catamaran = new ArrayList<Lorry.WaterborneVehicle>();
		WaterborneVehicle waterborneVehicle;
		
		for (int i = 0; i < vehiclesNum; i++) {
			
			
			strLine=br.readLine().split("\\s+");
			waterborneVehicle= new WaterborneVehicle();
			waterborneVehicle.order= i+1;
			waterborneVehicle.capacity = Integer.parseInt(strLine[1]);
			if(strLine[0].equals("1")){
				//kayak[kayakSize]= new WaterborneVehicle();
				//kayak[kayakSize++]=waterborneVehicle;
				kayak.add(waterborneVehicle);
			}
			else{
				//catamaran[catamaranSize]= new WaterborneVehicle();
				//catamaran[catamaranSize++]=waterborneVehicle;
				catamaran.add(waterborneVehicle);
			}
				
		}
		int kayakSize=kayak.size();
		int catamaranSize=catamaran.size();
		Collections.sort(kayak);
	//	System.out.println("kayak");
	//	printVehicles(kayak);
		Collections.sort(catamaran);
	//	System.out.println("catamaran");
	//	printVehicles(catamaran);
		ArrayList<Integer> strVehicleTypesSet= new ArrayList<Integer>();
		int kayakCapcity, totCapacity=0, kayakIndex= 0, catamaranIndex=0;
		while(lorryVol >= 2)
		{
			if(kayakIndex >= kayakSize )
			{
				if(catamaranIndex < catamaranSize){
					strVehicleTypesSet.add(catamaran.get(catamaranIndex).order);
					totCapacity+=catamaran.get(catamaranIndex++).capacity;
					//catamaran.remove(0);
					lorryVol-= 2;
				}
				else
					lorryVol=0;
			}
			else if (catamaranIndex >= catamaranSize)
			{
				if (kayakIndex < kayakSize){
				strVehicleTypesSet.add(kayak.get(kayakIndex).order);
				totCapacity+=kayak.get(kayakIndex++).capacity;
				//kayak.remove(0);
				lorryVol-=1;
				}
				else
					lorryVol=0;
			}
			else
			{
					kayakCapcity=kayak.get(kayakIndex).capacity;
					if( (kayakIndex+1) < kayakSize )
						kayakCapcity+=kayak.get(kayakIndex+1).capacity;
					
					 if(kayakCapcity > catamaran.get(catamaranIndex).capacity)
					{
						 strVehicleTypesSet.add(kayak.get(kayakIndex).order);
						totCapacity+=kayak.get(kayakIndex++).capacity;
						//kayak.remove(0);
						lorryVol-=1;						
					}
					else
					{
						strVehicleTypesSet.add(catamaran.get(catamaranIndex).order);
						totCapacity+=catamaran.get(catamaranIndex++).capacity;
						//catamaran.remove(0);
						lorryVol-=2;
					}
					
			}
		}
/*		while(lorryVol > 0)
		{
			if(kayakIndex >= kayakSize )
			{
				if(lorryVol >= 2)
				{
					strVehicleTypesSet+=catamaran.get(catamaranIndex).order+" ";
					totCapacity+=catamaran.get(catamaranIndex++).capacity;
					//catamaran.remove(0);
					lorryVol-= 2;
				}
				else
					continue;
			}
			else if (catamaranIndex >= catamaranSize)
			{
				strVehicleTypesSet+=kayak.get(kayakIndex).order+" ";
				totCapacity+=kayak.get(kayakIndex++).capacity;
				//kayak.remove(0);
				lorryVol-=1;
			}
			else if(lorryVol >= 2)
			{
					kayakCapcity=kayak.get(kayakIndex).capacity;
					if( (kayakIndex+1) < kayakSize )
						kayakCapcity+=kayak.get(kayakIndex+1).capacity;
					
					 if(kayakCapcity > catamaran.get(catamaranIndex).capacity)
					{
						 strVehicleTypesSet+=kayak.get(kayakIndex).order+" ";
						totCapacity+=kayak.get(kayakIndex++).capacity;
						//kayak.remove(0);
						lorryVol-=1;						
					}
					else
					{
						strVehicleTypesSet+=catamaran.get(catamaranIndex).order+" ";
						totCapacity+=catamaran.get(catamaranIndex++).capacity;
						//catamaran.remove(0);
						lorryVol-=2;
					}
					
			}
			else //if(lorryVol ==1)
			{
				strVehicleTypesSet+=kayak.get(kayakIndex).order+" ";
				totCapacity+=kayak.get(kayakIndex++).capacity;
			//	kayak.remove(0);
				lorryVol-=1;
			}
		}*/
		if(lorryVol ==1 && kayakIndex < kayakSize)
		{
			strVehicleTypesSet.add(kayak.get(kayakIndex).order);
			totCapacity+=kayak.get(kayakIndex).capacity;
		}
		System.out.println(totCapacity);
		for (Integer integer : strVehicleTypesSet) {
			System.out.print(integer + " ");
		}	
		br.close();
		pw.close();
	}
	/*public static void printVehicles(List<WaterborneVehicle> waterborneVehicle){
		for (WaterborneVehicle waterborneVehicle2 : waterborneVehicle) {
			System.out.println(waterborneVehicle2.order+ " : "+ waterborneVehicle2.capacity);
		}
		
	}*/
}