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 gdwg;

import java.io.*;

/**
 *
 * @author alexho
 */
public class GDWG {
    
    private static int [] result;
    
    
    private void readInput (String infn) throws FileNotFoundException, IOException {
        String line = null;        
        int testCases = 0;
        BufferedReader bufRdr = null;      
        String delimiter = " ";
        File file = new File(infn);
        bufRdr = new BufferedReader(new FileReader(file));            

        testCases = Integer.valueOf(bufRdr.readLine());        
        GDWG.result = new int [testCases];
        
        int index=0;
                
        while ( (line = bufRdr.readLine()) != null ) {
                        
            String [] temp;            
            temp = line.split(delimiter);            
            this.computeMax(temp, index);            
            index++;

        }
        bufRdr.close();

        
    }
    
    private void output (String outfn) throws IOException {
        PrintWriter out = new PrintWriter(new FileWriter(outfn));
        for (int i=0;i<GDWG.result.length;i++) {
            out.println("Case #"+(i+1)+": "+GDWG.result[i]);

        }
        out.close();        
    }
    
    private void computeMax (String [] tempS, int index) {
        
        int N,S,p, max=0,Nti;
        N = Integer.valueOf(tempS[0]);
        S = Integer.valueOf(tempS[1]);
        p = Integer.valueOf(tempS[2]);
        
        for (int i=3;i<tempS.length;i++) {
            Nti = Integer.valueOf(tempS[i]);
            
            // 1st case
            if (p == 0) {
                max++;
            } else if (p > Nti) {
                // do nothing
            } else if (Nti/3 >= p) {
                max++;                
            } else if (p - Nti/3 <=2 && p - Nti/3 > 0 ) {
                if ( 3*p == Nti) {
                        max++;
                    } else if (3*p+1 == Nti) {
                        max++;
                    } else if (3*p-1 == Nti) {
                        max++;
                    } else if (3*p-2 == Nti) {
                        max++;
                    } else if (3*p+2 == Nti) {
                        max++;
                    } else if (3*p-3 == Nti && S > 0) {
                        S--;
                        max++;
                    } else if (3*p+3 == Nti && S > 0) {
                        S--;
                        max++;
                    } else if (3*p-4 == Nti && S > 0) {
                        S--;
                        max++;
                    } else if (3*p+4 == Nti && S > 0) {
                        S--;
                        max++;
                    }
                
            } else {
                
            }
            
            
                                                                           
        }
        GDWG.result[index]=max;
    }
    
    public GDWG () {
        
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        
        String infn = args[0];
        String outfn = args[1];
        GDWG gdwg = new GDWG();
        gdwg.readInput(infn);
        gdwg.output(outfn);
        for (int i=0;i<GDWG.result.length;i++) {
            System.out.println(GDWG.result[i]);
        }
        
    }
}
