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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

/**
 * http://codeforces.com/problemset/problem/3/B
 *
 */
public class Lorry {

	/**
	 * determines if it is used as an online submission or test.
	 */
	final static boolean ONLINE_SUBMISSION = System.getProperty("ONLINE_JUDGE") != null;

	static class Run implements Runnable {

		/**
		 * determines if output should be written to a file or to console when
		 * testing locally.
		 */
		final static boolean OUTPUT_TO_FILE = false;

		// Idea: start with 0 catamarans and max kayaks. Add catamarans and subtract kayaks and keep track of best
		// combo.
		@Override
		public void run() {

			// input
			int n = nextInt();
			long v = nextLong();
			List<Boat> kayaks = new ArrayList<Boat>(), catamarans = new ArrayList<Boat>();
			long kayaksCapacity = 0;
			for (int i = 0; i < n; i++) {
				int type = nextInt();
				int capacity = nextInt();
				if (type == 1) {
					kayaks.add(new Boat(i + 1, capacity));
					kayaksCapacity += capacity;
				} else {
					catamarans.add(new Boat(i + 1, capacity));
				}
			}
			Collections.sort(kayaks);
			Collections.sort(catamarans);

			// output variables
			long maxCapacity = 0;

			// calc variables
			int noKayaks = kayaks.size();
			int noCatamarans = catamarans.size();
			int kayaksLeft = noKayaks, selectedCatamarans = 0;
			long catamaransCapacity = 0;

			for (int i = 0; i <= noCatamarans; i++) {
				int j = (int) Math.min(v - i * 2, noKayaks); // choosing i catamarans -> j equals space left for kayaks.
				if (j < 0) { // no space for extra kayaks?
					break;
				}
				for (int k = kayaksLeft; k > j; k--) { // remove smallest kayaks (capacity of j best kayaks)
					kayaksCapacity -= kayaks.get(noKayaks - k).capacity;
				}
				if (i > 0) { // capacity of i best catamarans
					catamaransCapacity += catamarans.get(noCatamarans - i).capacity;
				}
				if (kayaksCapacity + catamaransCapacity > maxCapacity) { // current combo better than previous?
					maxCapacity = kayaksCapacity + catamaransCapacity;
					selectedCatamarans = i;
				}
				kayaksLeft = j; // current number of kayaks being used.
			}

			println(maxCapacity);
			for (int i = 0; i < Math.min(v - selectedCatamarans * 2, noKayaks); i++) {
				print(kayaks.get(noKayaks - i - 1).index + " ");
			}
			for (int i = 0; i < selectedCatamarans; i++) {
				print(catamarans.get(noCatamarans - i - 1).index + " ");
			}

		}

		// ==============================================================
		// ======== Everything below is used across all problems ========
		// ==============================================================
		final String className = getClass().getEnclosingClass().getSimpleName();
		final String inputFilename = "io/input-" + className + ".txt";
		final String outputFilename = "io/output-" + className + ".txt";
		BufferedReader in;
		PrintWriter out;
		StringTokenizer strTok;

		Run() {
			if (ONLINE_SUBMISSION) {
				initConsoleIO();
			} else {
				initFileIO();
			}
		}

		/**
		 * read input from console and write output to console.
		 */
		void initConsoleIO() {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		}

		/**
		 * read input from {@value #inputFilename} and write output to console
		 * or
		 * to {@value #outputFilename} depending on {@link #OUTPUT_TO_FILE}.
		 */
		void initFileIO() {
			try {
				in = new BufferedReader(new FileReader(inputFilename));
				if (OUTPUT_TO_FILE) {
					out = new PrintWriter(new FileWriter(outputFilename));
				} else {
					out = new PrintWriter(new OutputStreamWriter(System.out));
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		/**
		 * Close BufferedReader and PrintWriter.
		 */
		void close() {
			try {
				in.close();
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		float nextFloat() {
			return Float.parseFloat(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		String nextLine() {
			try {
				return in.readLine();
			} catch (IOException e) {
				return "__NULL";
			}
		}

		public int[] nextArr(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; ++i) {
				a[i] = nextInt();
			}
			return a;
		}

		String nextToken() {
			while (strTok == null || !strTok.hasMoreTokens()) {
				String line;
				try {
					line = in.readLine();
					strTok = new StringTokenizer(line);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			return strTok.nextToken();
		}

		/**
		 * output to console.
		 */
		void cout(Object o) {
			System.out.println(o);
		}

		/**
		 * writes to PrintWriter. See {@link java.io.PrintWriter#write(String)
		 * PrintWriter.write} for more details.
		 */
		void print(Object o) {
			out.write(o.toString());
		}

		/**
		 * writes to PrintWriter and add new line. See
		 * {@link java.io.PrintWriter#write(String)
		 * PrintWriter.write} for more details.
		 */
		void println(Object o) {
			out.write(o.toString() + '\n');
		}

		/**
		 * See documentation {@link java.io.PrintWriter#printf(String, Object)
		 * here}.
		 */
		void printf(String format, Object... args) {
			out.printf(format, args);
		}

		/**
		 * See documentation
		 * {@link java.text.MessageFormat#format(String, Object) here}.
		 */
		String sprintf(String format, Object... args) {
			return MessageFormat.format(format, args);
		}
	}

	public static void main(String[] args) throws IOException {
		Run run = new Run();
		Thread thread = new Thread(run);
		if (!ONLINE_SUBMISSION) {
			long start = System.currentTimeMillis();
			thread.run();
			System.out.println("Time elapsed: " + ((System.currentTimeMillis() - start) / 1000.0) + " sec\n");
		} else {
			thread.run();
		}
		run.close();
	}
}

class Boat implements Comparable<Boat> {

	int index;
	int capacity;

	public Boat(int index, int capacity) {
		this.index = index;
		this.capacity = capacity;
	}

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

	@Override
	public String toString() {
		return "Boat [index=" + index + ", capacity=" + capacity + "]";
	}

}