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.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * 
 * 34 29 22 2 32 35 17 31 5 48 15 50 33 16 11 19 25 10 46 14 4 38 18 8

   34 29 22 2 32 35 17 31 5 48 15 50 33 16 11 19 25 10 46 14 4 41 38 18 6 
  * @author pttrung
 */
public class D {

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int v = in.nextInt();
        ArrayList<Boat> one = new ArrayList();
        ArrayList<Boat> two = new ArrayList();
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            int b = in.nextInt();  
           // System.out.println("Index " + (i + 1) + " size " + a + " cap " + b);
            if (a == 1) {
                one.add(new Boat(b, i + 1));
            } else {
                two.add(new Boat(b, i + 1));
            }
        }
        Collections.sort(one);
        Collections.sort(two);
        int a = one.size() - 1;
        int b = two.size() - 1;
        int result = 0;
        int count = 0;
        StringBuilder builder = new StringBuilder();
        while (v > 0 && a >= 0 && b >= 0) {
            //System.out.println(v + " " + a + " " + b);
            
            if (v %2 == 1 || one.get(a).c >= two.get(b).c) {
                
                result += one.get(a).c;
                builder.append(one.get(a).index).append(" ");
                a--;
                v--;
            } else {
                if (a > 0) {
                    int x = one.get(a).c;
                    int y = one.get(a - 1).c;
                    
                    if (x + y > two.get(b).c) {
                        //System.out.println("Index " + one.get(a).index + " " + one.get(a - 1).index);
                        result += x + y;                        
                        
                        builder.append(one.get(a).index).append(" ").append(one.get(a - 1).index).append(" ");
                        a -= 2;
                        v -= 2;
                    } else {
                        result += two.get(b).c;                        
                        builder.append(two.get(b).index).append(" ");
                        b--;
                        v -= 2;
                    }
                } else {
                    result += two.get(b).c;
                    count++;
                    builder.append(two.get(b).index).append(" ");
                    b--;
                    v -= 2;
                }
            }
        }
        // System.out.println("result " + result);
        if (a >= 0) {
           
            while (v > 0 && a >= 0) {                 
                result += one.get(a).c;
                builder.append(one.get(a).index).append(" ");
                a--;
                v--;

            }
        }
        if (b >= 0) {
            
            while (v > 1 && b >= 0) {                
                result += two.get(b).c;
                builder.append(two.get(b).index).append(" ");
                b--;
                v -= 2;

            }
        }
        out.println(result);
        out.println(builder.toString());
        out.close();
    }

    static class Boat implements Comparable<Boat> {

        int c, index;

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

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

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}