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.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class B {

	static Reader reader;
	static char[][][] path;

	static class Reader {

		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[100000]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

	private static void initReader() {
		reader = new Reader();
	}
	
	private static void printList(List<Boat> boats) {
		for(Boat b: boats) {
			System.out.println(b.index+" "+b.vol+" "+b.capacity);
		}
	}

	public static void main(String[] args) throws IOException {
		initReader();

		int n, v;
		int b, c;
		
		List<Boat> kayaks = new ArrayList<Boat>();
		List<Boat> catamarans = new ArrayList<Boat>();
		
		List<Boat> result = new ArrayList<Boat>();
		
		n = reader.nextInt();
		v = reader.nextInt();
		
		for(int i=1; i<=n; i++) {
			b = reader.nextInt();
			c = reader.nextInt();
			
			if(b == 1)
				kayaks.add(new Boat(i, b, c));
			else
				catamarans.add(new Boat(i, b, c));
		}
		
		Collections.sort(kayaks);
		Collections.sort(catamarans);
		Collections.reverse(kayaks);
		Collections.reverse(catamarans);
		
		//printList(kayaks);
		//printList(catamarans);
		
		int lastKayak = -1;
		while(v != 0 && (kayaks.size() > 0 || catamarans.size() > 0)) {
			if(v == 1) {
				if(kayaks.size() > 0) {
					if(catamarans.size() > 0 && lastKayak != -1 && catamarans.get(0).capacity > result.get(lastKayak).capacity + kayaks.get(0).capacity) {
						kayaks.add(0, result.get(lastKayak));
						result.remove(lastKayak);
						result.add(catamarans.get(0));
						catamarans.remove(0);
					}
					else {
						result.add(kayaks.get(0));
						kayaks.remove(0);
						
						lastKayak = result.size() - 1;
					}
				}
				else {
					if(catamarans.size() > 0 && lastKayak != -1 && catamarans.get(0).capacity > result.get(lastKayak).capacity) {
						kayaks.add(0, result.get(lastKayak));
						result.remove(lastKayak);
						result.add(catamarans.get(0));
						catamarans.remove(0);
					}
				}
				v--;
			}
			else {
				if(kayaks.size() >= 2 && catamarans.size() >= 1 && (kayaks.get(0).capacity + kayaks.get(1).capacity > catamarans.get(0).capacity)) {
					result.add(kayaks.get(0));
					result.add(kayaks.get(1));
					kayaks.remove(0);
					kayaks.remove(0);
					
					lastKayak = result.size() - 1;
					
					v-=2;
				}
				else if(kayaks.size() >= 2 && catamarans.size() >= 1) {
					result.add(catamarans.get(0));
					catamarans.remove(0);
					v-=2;
				}
				else if(catamarans.size() == 0) {
					while(v != 0 && kayaks.size() > 0) {
						result.add(kayaks.get(0));
						kayaks.remove(0);
						
						lastKayak = result.size() - 1;
						
						v--;
					}
				}
				else if(kayaks.size() == 1) {
					if(kayaks.get(0).capacity > catamarans.get(0).capacity) {
						result.add(kayaks.get(0));
						kayaks.remove(0);
						
						lastKayak = result.size() - 1;
						
						v--;
					}
					else {
						result.add(catamarans.get(0));
						catamarans.remove(0);
						v-=2;
					}
				}
				else if(kayaks.size() == 0) {
					while(v > 1 && catamarans.size() > 0) {
						result.add(catamarans.get(0));
						catamarans.remove(0);
						v-=2;
					}
				}
			}
		}
		
		int max = 0;
		for(Boat boat: result) {
			max += boat.capacity;
		}
		
		System.out.println(max);
		for(Boat boat: result) {
			System.out.print(boat.index+" ");
		}
	}
}

class Boat implements Comparable<Boat>{
	int index;
	int vol;
	int capacity;
	
	Boat(int i, int v, int c){
		index = i;
		vol = v;
		capacity = c;
	}

	@Override
	public int compareTo(Boat arg0) {
		return this.capacity - arg0.capacity;
	}
}