import java.io.*;
import java.util.*;


public class AUC {

	static int n;
	static PrintWriter w;
	static float[][] ins;
	static float[][] sorted_ins;
	static int dimension=2;
	static int FP;
	static int TP;
	static int N;
	static int P;
	static float Area;
	static String output_name="out2.txt";
	static String filename="in2.txt";
	static int count=0;

	static float[][] RocPoints;

	public static void main(String[] args){

		StringTokenizer st;
		RandomAccessFile in = null;

		try {
			in = new RandomAccessFile(filename, "r");
		} catch(FileNotFoundException e) {
			System.err.println("Unable to open input file");
			System.exit(1);
		}

		try {
			String line;
			line = in.readLine();
			n=Integer.parseInt(line);
			System.out.println(n);

			line = in.readLine();
			N=Integer.parseInt(line);
			System.out.println(N);
			line = in.readLine();
			P=Integer.parseInt(line);
			System.out.println(P);

			ins=new float[n][2];
			RocPoints=new float[n+3][2];
			for(int i=0;i<n;i++){
				line = in.readLine();
				st= new StringTokenizer(line);
				ins[i][0]=Float.parseFloat(st.nextToken());

				if(st.nextToken().equals("p")){
					ins[i][1]=1;
					}
				else{
					ins[i][1]=0;
				}
				System.out.println(ins[i][0]);
			}
			in.close();
		} catch(IOException e) {
			System.err.println("Error reading from input file");
		}
		sorted_ins=sort2(ins,0);

		doAUC();
	}


	public static void doAUC(){

		FP=0;
		TP=0;
		int fp=0;
		int tp=0;
		Area=0;
		float Threshold=-1;
		int e=1;
		while (e<(n+1)){
			if(sorted_ins[n-e][0]!=Threshold){
				Area=Area+trapezoid_area((float)FP/N,(float)fp/N,(float)TP/P,(float)tp/P);

//				Area=Area+trapezoid_area(FP,fp,TP,tp);

				Threshold=sorted_ins[n-e][0];
				fp=FP;
				tp=TP;

			}

			if(sorted_ins[n-e][1]==1){
				TP++;
			}else{
				FP++;
			}
			e++;
		}

		//		Area=Area+trapezoid_area(1,fp,1,tp);

		Area=Area+trapezoid_area(1,(float)fp/N,1,(float)tp/P);
		System.out.println("Area  : "+Area);

		//Area=(Area/(P*N));
		System.out.println("Area under ROC graph is : "+Area);

	}

	public static float trapezoid_area(float x1,float x2,float y1, float y2){
		count++;
		//System.out.println(" trap number "+count);
		float Base=Math.abs(x1-x2);
		//System.out.println(" base "+ Base);

		float Height=(float) (y1+y2)/2;
		//System.out.println("  height "+ Height);

		return Base*Height;
	}

	public static float[][] sort2(float[][] input,int d){

		float[][] temp=new float[input.length][dimension];
		if(input.length==1){
			return input;
		}
		else{
			int middle = (int)Math.floor((input.length)/2);
			float[][] l=new float [middle][dimension];
			float[][] r= new float[(input.length) - middle][dimension];

			for(int counter = 0; counter < middle; counter++){
				for(int w = 0; w < dimension; w++){
					l[counter][w] = input[counter][w];
				}
			}
			for(int counter = middle; counter < input.length; counter++){
				for(int w = 0; w < dimension; w++){
					r[counter - middle][w] = input[counter][w];
				}
			}
			l = sort2(l,d);
			r = sort2(r,d);

			temp = merge2(l,r,d);
			}
		return temp;
	}

	public static float[][] merge2(float[][] a, float[][] b , int d){

		int size = a.length + b.length;
		float[][] all=new float[size][dimension];
		int pointer_a=0;
		int pointer_b=0;
		for(int o = 0 ;o<size ;o++){
			if((pointer_a < a.length)&&(pointer_b < b.length)){

				if(a[pointer_a][d] < b[pointer_b][d]){
					for(int h=0;h<dimension;h++){
						all[o][h]=a[pointer_a][h];
					}
					pointer_a++;
				}
				else{
					for(int h=0;h<dimension;h++){
						all[o][h]=b[pointer_b][h];
					}
					pointer_b++;
				}
			}
			else{
				if(pointer_a == a.length){
					for(int h=0;h<dimension;h++){
						all[o][h]=b[pointer_b][h];
					}
					pointer_b++;
				}else{
					for(int h=0;h<dimension;h++){
						all[o][h]=a[pointer_a][h];
					}
					pointer_a++;
				}
			}
		}
		return all;
	}
}
