package nai4;

import java.io.*;
import java.util.*;

/**
 * @author Daniel "3ICE" Berezvai
 */
public class Nai4{
  static File in=new File("src/i43_8");
  //static File in=new File("src/GOMBA.BE");
  static File out=new File("src/GOMBA.KI");
  static BufferedReader r;
  static PrintWriter w;
  static ArrayList<Mushroom> mushrooms=new ArrayList<>();
  static ArrayList<Mushroom> removeFromMushrooms=new ArrayList<>();
  static ArrayList<Mushroom> picked=new ArrayList<>();
  static ArrayList<Mushroom> C=new ArrayList<>();
  static ArrayList<Mushroom> R=new ArrayList<>();
  static ArrayList<Mushroom> L=new ArrayList<>();
  static int n;
  static int k;
  static int c;

  public static void main(String[] args) throws IOException{
    r=new BufferedReader(new InputStreamReader(new FileInputStream(in)));
    w=new PrintWriter(out);
    //állomány első sorában a gombák száma van (maximum 1000)
    n=Integer.parseInt(r.readLine());
    //a másodikban pedig a zsák kapacitása (maximum 100000)
    k=Integer.parseInt(r.readLine());
    c=0;
    for(int i=1;i<=n;i++){
      //a többi sor mindegyikében egy gomba jellemzői vannak
      processOne(r.readLine());
    }
    if(mushrooms==null||mushrooms.isEmpty()){
      throw new NullPointerException("Empty input!");
    }
    //for(Mushroom mushroom : mushrooms){System.out.print(mushroom+" ");}System.out.println();
    sort(0, n-1);
    //for(Mushroom mushroom : mushrooms){System.out.print(mushroom+" ");}
    recurse(10);
    for(Mushroom p : picked){
      //C>R>L
      switch(p.type){
      case C:
        C.add(p);
        break;
      case R:
        R.add(p);
        break;
      case L:
        L.add(p);
        break;
      default:
        throw new AssertionError();
      }
    }
    int sumC=0;
    int sumR=0;
    int sumL=0;
    int countC=C.size();
    int countR=R.size();
    int countL=L.size();
    for(Mushroom mushroom : C){
      sumC+=mushroom.weight;
    }
    for(Mushroom mushroom : R){
      sumR+=mushroom.weight;
    }
    for(Mushroom mushroom : L){
      sumL+=mushroom.weight;
    }
    int rollingSum=sumC+sumR+sumL;
    int rollingCount=countC+countR+countL;
    System.out.println(rollingCount+" "+rollingSum);
    System.out.println(countC+" "+sumC);
    System.out.println(countR+" "+sumR);
    System.out.println(countL+" "+sumL);
    w.println(rollingCount+" "+rollingSum);
    w.println(countC+" "+sumC);
    w.println(countR+" "+sumR);
    w.println(countL+" "+sumL);
    w.println("");
    w.flush();
  }

  private static void processOne(String s){
    String[] p=s.split("\\s+");
    Type t=Mushroom.parseType(p[0]);
    mushrooms.add(new Mushroom(
            //a fajta (a következő karakterek valamelyike: C, R vagy L)
            t,
            //és a súly dekagrammban (1 és 100 között) egy szóközzel elválasztva
            Integer.parseInt(p[1])));
    //A. Mindaddig nem szed Lila pereszkét, amíg még van az erdőben Csiperke gomba.
    if(t==Type.C){
      c++;
    }

  }

  public static void sort(int low, int high){
    int i=low, j=high;
    // Get the pivot element from the middle of the list
    Mushroom pivot=mushrooms.get(low+(high-low)/2);

    // Divide into two lists
    while(i<=j){
      // If the current value from the left list is smaller then the pivot
      // element then get the next element from the left list
      while(mushrooms.get(i).lessThan(pivot)){
        i++;
      }
      // If the current value from the right list is larger then the pivot
      // element then get the next element from the right list
      while(mushrooms.get(j).greaterThan(pivot)){
        j--;
      }

      // If we have found a values in the left list which is larger than
      // the pivot element and if we have found a value in the right list
      // which is smaller than the pivot element then we exchange the
      // values.
      // As we are done we can increase i and j
      if(i<=j){
        Collections.swap(mushrooms, i, j);
        i++;
        j--;
      }
    }
    // Recursion
    if(low<j){
      sort(low, j);
    }
    if(i<high){
      sort(i, high);
    }
  }

  private static void pick(Mushroom m){
    //System.err.println("Picked "+m);
    //for(Mushroom m2 : mushrooms){System.err.print(" "+m2);}System.err.println();
    k-=m.weight;
    picked.add(m);
    removeFromMushrooms.add(m);
  }

  private static void recurse(int tries){
    for(Mushroom m : removeFromMushrooms){
      mushrooms.remove(m);
      //System.err.println("remove = "+m);
    }
    removeFromMushrooms.clear();
    for(Mushroom m : mushrooms){
      //System.err.println("check = "+m);
      if(k>=m.weight){
        if(c>0&&m.type==Type.L){
          //Amíg van csiperke, addig nem szed lila pereszkét.
          continue;
        }
        if(m.type==Type.C){
          c--;
          //System.err.println("c = "+c);
          if(c==0){
            pick(m);
            //System.err.println("Picked the last C!");
            //System.err.println("Breaking at"+tries);
            break;
          }
        }
        pick(m);
        //System.out.println("k = "+k);
      }
      //System.out.println(m);
    }
    //System.err.println("finished"+tries);
    //3ICE: If we have room and we successfully picked at least one mushroom this round, then go again!
    if(k>=0&&removeFromMushrooms.size()>0&&tries>0){
      //System.err.println("tries = " + tries);
      recurse(tries-1);
    }
  }
}
