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

public class DancingWithTheGooglers
{
    public DancingWithTheGooglers()
    {
        Scanner inFile = null;
        try
        {
            inFile = new Scanner(new File("inputB.txt"));
        }
        catch(Exception e)
        {
            System.out.println("Problem opening input file. Exiting...");
			System.exit(0);
        }
        int t = inFile.nextInt();
        
        int [] results = new int [t];
        DancingWithTheGooglersMax [] rnc = new DancingWithTheGooglersMax[t];
        
        int i, j;
        int [] scores;
        int s, p;
        for(i = 0; i < t; i++)
        {
            scores = new int [inFile.nextInt()];
            s = inFile.nextInt();
            p = inFile.nextInt();
            for(j = 0; j < scores.length; j++)
                scores[j] = inFile.nextInt();
            
            rnc[i] = new DancingWithTheGooglersMax(i, scores, s, p, results);
            rnc[i].start();
        }
        inFile.close();
        
        boolean done = false;
        
        while(!done)
        {
            done = true;
            for(i = 0; i < t; i++)
                if(rnc[i].isAlive())
                {
                    done = false;
                    break;
                }
        }
        
        PrintWriter outFile = null;
        try
        {
            outFile = new PrintWriter(new File("outputB.txt"));
        }
        catch(Exception e)
        {
            System.out.println("Problem opening output file. Exiting...");
			System.exit(0);
        }
        
        for(i = 0; i < results.length; i++)
            outFile.printf("Case #%d: %d\n", i+1, results[i]);
        outFile.close();
    }
    
    public static void main(String [] args)
    {
        new DancingWithTheGooglers();
    }
    
    private class DancingWithTheGooglersMax extends Thread
    {
        int id;
        int s, p;
        int [] results, scores;
        
        public DancingWithTheGooglersMax(int i, int [] aScores, int aS, int aP,int [] res)
        {
            id = i;
            s = aS;
            p = aP;
            results = res;
            scores = aScores;
        }
        
        public void run()
        {
            int a = 0, b = 0;
            
            if(p == 0)
                results[id] = scores.length;
            else if(p == 1)
            {
                int y;
                y = 3*p - 3;
                
                for(int i = 0; i < scores.length; i++)
                    if(scores[i] > y)
                        a++;
                    else if(scores[i] > 0)
                        b++;
                
                b = Math.min(b, s);
                results[id] = a+b;
            }
            else
            {
                int y, z;
                y = 3*p - 3;
                z = 3*p - 5;
                
                for(int i = 0; i < scores.length; i++)
                    if(scores[i] > y)
                        a++;
                    else if(scores[i] > z)
                        b++;
                
                b = Math.min(b, s);
                results[id] = a+b;
            }
        }
    }
}
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

public class DancingProblem {

    private static final String INPUT_FILE_NAME = "/home/rponnu/codebase/codejam/first_round/data/input.txt";
    private static final String OUTPUT_FILE_NAME = "/home/rponnu/codebase/codejam/first_round/data/output.txt";

    public static void main(String args[]) throws IOException {
        List<String> lines = readFile(INPUT_FILE_NAME);
        Integer noOfInputs = readInputData(lines.get(0)).get(0);
        System.out.println("No of Inputs:"+ noOfInputs);


        List<String> outputLines = new ArrayList<String>();

        for(int index=1;index<=noOfInputs.intValue();index++){
            List<Integer> inputData = readInputData(lines.get(index));
            outputLines.add("Case #"+index+": "+getNoOfBestResult(inputData));
        }
        File f = new File(OUTPUT_FILE_NAME);
        FileUtils.writeLines(f,outputLines);
    }

    private static int getNoOfBestResult(List<Integer> inputData) {
        Iterator<Integer> iterator = inputData.iterator();
        Integer noOfPlayers = iterator.next();
        Integer noOfSurprises = iterator.next();
        Integer bestResult = iterator.next();

        int noOfMaxScores = 0;
        int count= 0;
        int noOfMaxScoresWithSurprises = 0;

        int maxValueForScore = getMaxValueForScore(bestResult);
        int maxValueForScoreWithSurprises = getMaxValueForScoreWithSurprises(bestResult);

        while (iterator.hasNext()){
            int scoreSum = iterator.next();
            if(scoreSum >= maxValueForScore) {
                noOfMaxScores ++;
            } else if( (maxValueForScore != maxValueForScoreWithSurprises) &&  scoreSum >= maxValueForScoreWithSurprises){
                    noOfMaxScoresWithSurprises ++;
                }
            }

        count = noOfMaxScores;

        if (noOfMaxScoresWithSurprises >= noOfSurprises) {
            count += noOfSurprises;
        } else if (noOfMaxScoresWithSurprises < noOfSurprises){
            count += noOfMaxScoresWithSurprises;
        }

        return count;
    }

    private static int getMaxValueForScore(int bestScore){
        int maxValue = bestScore;
        if(bestScore-1 > 0) {
             maxValue += 2 *(bestScore-1);
        }
        return maxValue;
    }

    private static int getMaxValueForScoreWithSurprises(int bestScore){
        int maxVal = bestScore;
        if(bestScore -2 > 0){
            maxVal +=2 *(bestScore-2);
        }
        return maxVal;
    }



    private static List<Integer> readInputData(String line){
        List<Integer> values = new ArrayList<Integer>();
        StringTokenizer stringTokenizer = new StringTokenizer(line.trim());
        while(stringTokenizer.hasMoreElements()){
            values.add(Integer.parseInt((String) stringTokenizer.nextElement()));
        }
        return values;
    }


    private static List<String> readFile(String path) throws IOException {
        List<String> lines = FileUtils.readLines(new File(path));
        return lines;
    }
}
