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;
            }
        }
    }
}
package small;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;

public class DancingGooglers {
	private static int noOfCases;
	private static int[] noOfGooglers;
	private static int[] noOfSurprisingTriplets;
	private static int[] bestResult;
	private static int[][] scores;
	private static String[] result;

	public static void main(String[] args) {

		readInputFile();
		result = new String[noOfCases];

		for (int i = 0; i < noOfCases; i++) {
			int totalSum = 0;
			int surprisingCount = 0;
			for (int j = 0; j < noOfGooglers[i]; j++) {
				// System.out.print(" "+scores[i][j]);
				if (scores[i][j] >= bestResult[i]) {
					if ((scores[i][j] - bestResult[i]) / 2 >= bestResult[i] - 2) {
						totalSum++;
						if ((scores[i][j] - bestResult[i]) / 2 == bestResult[i] - 2) {
							surprisingCount++;
						}
					}
				}

			}

			if (surprisingCount > noOfSurprisingTriplets[i]) {
				totalSum = totalSum
						- (surprisingCount - noOfSurprisingTriplets[i]);
			}
			System.out.println();
			System.out.println("Case #" + (i + 1) + ": " + totalSum);
			result[i] = "Case #" + (i + 1) + ": " + totalSum;

		}

		writeToFile(result);

	}

	private static void readInputFile() {

		try {
			FileInputStream fstream = new FileInputStream("B-large.in");
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));

			noOfCases = Integer.parseInt(br.readLine());
			String strLine;
			scores = new int[noOfCases][];
			noOfGooglers = new int[noOfCases];
			noOfSurprisingTriplets = new int[noOfCases];
			bestResult = new int[noOfCases];
			for (int i = 0; i < noOfCases; i++) {
				strLine = br.readLine();
				String[] temp = strLine.split(" ");
				noOfGooglers[i] = Integer.parseInt(temp[0]);
				noOfSurprisingTriplets[i] = Integer.parseInt(temp[1]);
				bestResult[i] = Integer.parseInt(temp[2]);
				scores[i] = new int[noOfGooglers[i]];

				// System.out.println("No of Googlers: "+noOfGooglers);
				// System.out.println("No of surp trip: "+noOfSurprisingTriplets);
				// System.out.println("Best Result: "+bestResult);

				for (int j = 0; j < noOfGooglers[i]; j++) {
					scores[i][j] = Integer.parseInt(temp[3 + j]);
					System.out.println(scores[i][j]);
				}

			}

			in.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("Error: " + e.getMessage());
		}
	}

	public static void writeToFile(String args[]) {
		try {
			FileWriter fstream = new FileWriter("B-large.out");
			BufferedWriter out = new BufferedWriter(fstream);
			for (int i = 0; i < args.length; i++) {
				out.write(args[i]);
				if (i != args.length - 1)
					out.newLine();
			}
			out.close();
		} catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}
	}

}
