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

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

public class Dancing {

	/**
	 * @param args
	 */

	private static int[] values = null;
	private static int[] googlers= null;
	private static int total =0;
	
	public static void main(String[] args) {
		
		BufferedReader fin = null;
		int t = 0;
		StringTokenizer str = null;
		
		try {
			fin = new BufferedReader(new FileReader(new File("/home/bamdad/NetBeansProjects/Dancing/src/dancing/B-small-attempt0.in")));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
	
			
			try {
				t = Integer.parseInt(fin.readLine());
				//System.out.println(t);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			values = new int[3];
			
			
			for(int i=0;i<t;i++){
				System.out.print("Case #"+(i+1)+": ");
				try {
					total = 0;
					str=new StringTokenizer(fin.readLine());
					
					int ctr =0;
				while(ctr<3) {
					 
					values[ctr]=Integer.parseInt(str.nextToken());
					ctr++;
					
					}
				//System.out.print(values[0]+" "+values[1]+" "+values[2]+" ");
				ctr=0;
				googlers = new int[values[0]];
				while(str.hasMoreElements()){
					googlers[ctr]=Integer.parseInt(str.nextToken());
					//System.out.print(googlers[ctr]+" ");
					ctr++;
				}
				//System.out.println();
					
				} catch (IOException e) {
					e.printStackTrace();
				}
				
				calculate();
				
			}
	}


	private static void calculate() {
		
		int value = 0 ;
		int remainder = 0;
		for(int i=0;i<values[0];i++){			
			value = googlers[i]/3;
			remainder = googlers[i]%3;
			
			if (googlers[i]==0&&values[2]!=0)
				continue;
			
			if(value>=values[2])
				total++;
			else if(remainder==0&&values[1]>0&&(value+1)>=values[2]){
				values[1]--;
				total++;
			}
			else if(remainder>0&&(value+1)>=values[2])
				total++;
			
			else if(remainder==2&&(value+2)>=values[2]&&values[1]>0){
				total++;
				values[1]--;
			}	
		}
		System.out.println(total);
	}

}
