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 com.renoux.gael.codejam.utils;

import java.io.Closeable;
import java.io.IOException;


/**
 * <p>
 * Cette classe comporte des mÃ©thodes utilitaires de gestion des flux d'entrÃ©e/sortie.
 * </p>
 * 
 * @author renouxg
 */
public class FluxUtils {

    /**
     * <p>
     * Constructeur privÃ© : cette classe utilitaire n'est pas destinÃ©e Ã  Ãªtre instanciÃ©e.
     * </p>
     */
    private FluxUtils() {
        // classe non instanciable
    }


    /**
     * <p>
     * Cette mÃ©thode utilitaire ferme tous les objets <code>Closeable</code> qui lui sont passÃ©s en paramÃ¨tre.
     * Les Ã©lÃ©ments nuls sont ignorÃ©s. Si la fermeture de l'un ou plusieurs d'entre eux renvoie une erreur, on
     * tÃ¢che nÃ©anmoins de fermer tous les flux ; la premiÃ¨re erreur survenue est ensuite relancÃ©e.
     * </p>
     * 
     * @param fluxArray les objets implÃ©mentant {@link Closeable} qu'il faut fermer.
     * @throws IOException toute exception qui peut se produire Ã  la fermeture d'un {@link Closeable}.
     */
    public static void closeCloseables(final Closeable... fluxArray) {
        IOException relaunch = null;

        for (Closeable flux : fluxArray) {
            if (flux == null) {
                continue;
            }

            try {
                flux.close();
            } catch (IOException lEx) {
                if (relaunch == null) {
                    relaunch = lEx;
                } else {
                    // Nouvelle exception, ignorÃ©e
                }
            }
        }

        if (relaunch != null) {
            throw new TechnicalException(relaunch);
        }
    }

}
