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.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Lorry_3B {
	private static class Boat implements Comparable<Boat> {
		int volume;
		int no;

		Boat(int volume, int no) {
			this.volume = volume;
			this.no = no;
		}

		public int compareTo(Boat b) {
			if (this.volume > b.volume)
				return 1;
			else if (this.volume == b.volume)
				return 0;
			else
				return -1;
		}
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int v = s.nextInt();

		List<Boat> kayaks = new ArrayList<>(n);
		List<Boat> catamarans = new ArrayList<>(n);
		int type, volume = 0; // inicijalizirao sam zbog errora da možda neće
								// biti inicijalizirana
		for (int i = 0; i < n; i++) {
			type = s.nextInt();
			volume = s.nextInt();
			if (type == 1) {
				kayaks.add(new Boat(volume, i + 1));
			} else if (type == 2) {
				catamarans.add(new Boat(volume, i + 1));
			}
		}
		Collections.sort(kayaks);
		Collections.sort(catamarans);
		int totalKayaks = kayaks.size();
		int totalCatamarans = catamarans.size();
		Boat[] kayaksArray = kayaks.toArray(new Boat[totalKayaks]);
		Boat[] catamaransArray = catamarans.toArray(new Boat[totalCatamarans]);
		int maxVol, vol = 0;
		int maxKay, maxCat;

		if (2 * totalCatamarans + totalKayaks <= v) {
			for (int i = 0; i < totalKayaks; i++) {
				vol += kayaksArray[i].volume;
			}
			for (int j = 0; j < totalCatamarans; j++) {
				vol += catamaransArray[j].volume;
			}
			System.out.println(vol);
			for (int i = 0; i < totalKayaks; i++) {
				System.out.print(kayaksArray[i].no + " ");
			}
			for (int j = 0; j < totalCatamarans; j++) {
				System.out.print(catamaransArray[j].no + " ");
			}
		} else {
			// inicijalno uzimamo najveći mogući broj katamarana i minimalni
			// kajaka
			// te u sljedećim kombinacijama povećavamo broj kajaka i smanjujemo
			// katamarana
			int noOfCats = 0;
			while ((2 * noOfCats <= v) && (noOfCats <= totalCatamarans))
				noOfCats++;
			noOfCats--; // jer smo gore prekoračili za 1, morali smo zbog
						// lijevog
						// uvjeta;
			int noOfKays = v - (2 * noOfCats);
			try {
				for (int i = 0; i < noOfKays; i++) {
					vol += kayaksArray[totalKayaks - 1 - i].volume;
				}
			} catch (IndexOutOfBoundsException exc) {

			}
			for (int i = 0; i < noOfCats; i++) {
				vol += catamaransArray[totalCatamarans - 1 - i].volume;
			}
			maxVol = vol;
			maxKay = noOfKays;
			maxCat = noOfCats;
			for (int i = totalCatamarans - noOfCats, j = totalKayaks - noOfKays - 1; i < totalCatamarans
					&& j >= 1; i++, j -= 2) {
				vol -= catamaransArray[i].volume;
				vol += kayaksArray[j].volume;
				vol += kayaksArray[j - 1].volume;
				if (vol > maxVol) {
					maxVol = vol;
					maxKay = totalKayaks - j + 1;
					maxCat = totalCatamarans - i - 1;
				}
			}

			// if (volume % 2 == 1) {
			// maxKay = 1;
			// }
			// boolean kayakEnd = false;
			// for (int catNo = v / 2, kayNo = 0; catNo >= 0; catNo--, kayNo +=
			// 2) {
			// if (catNo > totalCatamarans - 2)
			// continue;
			// vol = 0;
			// for (int i = 0; i < catNo; i++) {
			// vol += catamaransArray[totalCatamarans - 1 - i].volume;
			// if (kayNo != 0) {
			// if (totalKayaks - 1 - 2 * i - 1 < 0) {
			// kayakEnd = true;
			// break;
			// }
			//
			// try {
			// vol += (kayaksArray[totalKayaks - 1 - 2 * i].volume
			// + kayaksArray[totalKayaks - 1 - 2 * i - 1].volume);
			// } catch (IndexOutOfBoundsException exc) {
			// kayakEnd = true;
			// break;
			// }
			// }
			// }
			// if (kayakEnd)
			// break;
			// if (vol > maxVol) {
			// maxVol = vol;
			// maxKay += kayNo;
			// maxCat = catNo;
			// }
			//
			// // if (kayakEnd)
			// // break;
			// }
			System.out.println(maxVol);
			try {
				for (int i = totalKayaks - maxKay; i < totalKayaks; i++) {
					System.out.print(kayaksArray[i].no + " ");
				}
			} catch (IndexOutOfBoundsException exc) {
			}
			try {
				for (int j = totalCatamarans - maxCat; j < totalCatamarans; j++) {
					System.out.print(catamaransArray[j].no + " ");
				}
			} catch (IndexOutOfBoundsException exc) {
			}
		}
		s.close();
	}
}