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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;


public class main {
	public static BufferedReader buffstdin = new BufferedReader(new InputStreamReader(System.in));
	static OutputStream out = new BufferedOutputStream ( System.out );
	
	static boat[] boats;

	public static void print(String s) throws IOException {
		s = s + "\n";
		out.write(s.getBytes());
	}
	public static void print(int s) throws IOException {
		print("" + s);
	}
	
	public static class boat implements Comparable<boat> {
		public int capacity;
		public int id;
		public double efficiency;
		
		public boat(int c, int v, int ID) {
			this.capacity = c;
			this.id = ID;
			this.efficiency = ((double) capacity)/((double) v);
		}

		public String toString() {
			return "Cap: " + capacity + "\t" + "ID: " + id + "\t";
		}
		
		@Override
		public int compareTo(boat otherBoat) {
			return otherBoat.capacity - this.capacity;
		}
	}
	
	public static void main(String[] args) throws IOException {
		String[] line = buffstdin.readLine().trim().split(" ");
		int n = Integer.parseInt(line[0]);
		int v = Integer.parseInt(line[1]);
		
		boats = new boat[n];
		
		int smIndex = 0;
		int lgIndex = n-1;
		for(int i=0; i<n; i++) {
			line = buffstdin.readLine().trim().split(" ");
			int cap = Integer.parseInt(line[1]);
			int vol = Integer.parseInt(line[0]);
			if(vol == 1) boats[smIndex++] = new boat(cap, vol, (i+1));
			if(vol == 2) boats[lgIndex--] = new boat(cap, vol, (i+1));
		}
		
		//long startTime = System.currentTimeMillis();
		
		int totalSmall = smIndex;
		int totalLarge = n;
		
		//print("TotalSmall: " + totalSmall + "\tTotalLarge: " + totalLarge);
		
		//long s1 = System.currentTimeMillis();
		Arrays.sort(boats, 0, totalSmall);
		Arrays.sort(boats, totalSmall, n);
		//long s2 = System.currentTimeMillis();
		
		/*for(boat b : boats) {
			print(b.toString());
		}*/
		ArrayList<Integer> usedBoats = new ArrayList<Integer>();
		
		int capacity = 0;
		int curBoatCap = 0;
		smIndex = 0;
		lgIndex = totalSmall;
		if(v % 2 == 1 && v>1) {
			v--;
			capacity += boats[smIndex++].capacity;
			usedBoats.add(boats[smIndex-1].id);
		}
		while(v > 0) {
			//get boat off top
			boolean lgEmpty = totalLarge == lgIndex;
			boolean smEmpty = totalSmall == smIndex;
			curBoatCap = 0;
			if(!lgEmpty && !smEmpty) {
				if(v == 1) {
					curBoatCap = boats[smIndex++].capacity;
					usedBoats.add(boats[smIndex-1].id);
					v--;
				}
				else {
					int lgboatCap = boats[lgIndex].capacity;
					int smboatCap;
					boolean enoughSmall = totalSmall-1 > smIndex;
					if(enoughSmall) {
						smboatCap = boats[smIndex].capacity + boats[smIndex+1].capacity;
					}
					else {
						smboatCap = boats[smIndex].capacity;
					}
					if(lgboatCap > smboatCap) {
						v-=2;
						if(v >=0) {
							curBoatCap = lgboatCap;
							lgIndex++;
							usedBoats.add(boats[lgIndex-1].id);
						}
					}
					else {
						curBoatCap = smboatCap;
						if(enoughSmall) {
							v-=2;
							if(v >= 0) {
								smIndex+=2;
								usedBoats.add(boats[smIndex-1].id);
								usedBoats.add(boats[smIndex-2].id);
							}							
						}
						else {
							v--;
							if(v >= 0) {
								smIndex++;
								usedBoats.add(boats[smIndex-1].id);
							}
						}
					}
				}
			}
			else if(lgEmpty && smEmpty) {
				break;
			}
			else if(lgEmpty) {
				//print("lgempty");
				v--;
				if(v >=0) {
					curBoatCap = boats[smIndex++].capacity;
					usedBoats.add(boats[smIndex-1].id);
				}				
			}
			else if(smEmpty) {
				//print("smempty");
				v-=2;
				if(v >= 0) {
					curBoatCap = boats[lgIndex++].capacity;
					usedBoats.add(boats[lgIndex-1].id);
				}
				else curBoatCap = 0;
			}
			else break;
			//check if boat fits
			if(v >= 0) {
				capacity += curBoatCap;
			}
		}
			
		//long s3 = System.currentTimeMillis();

		//print("Load: " + load +"\t" + "V: " + v);
		print(capacity);
		for(int item : usedBoats) {
			out.write((item + " ").getBytes());
		}
		//long endTime = System.currentTimeMillis();
		/*print("Time: " + (endTime - startTime));
		print("Split 1: " + (s1 - startTime));
		print("Split 2: " + (s2 - s1));
		print("Split 3: " + (s3 - s2));
		print("Split 4: " + (endTime - s3));*/
		out.flush();
	}
}