import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class Dancing {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// read input file
		File file = new File("B-small-attempt4.in");
		//File file = new File("input.txt");
		BufferedReader br = new BufferedReader(new FileReader(file));
		String ln = "";
		int count = Integer.parseInt(br.readLine());

		// write output file
		File out = new File("outB.txt");
		BufferedWriter bw = new BufferedWriter(new FileWriter(out));
		
		int y = 0;
		for (int i=0; i < count; i++){
			ln = br.readLine();
			y = getY(ln);
			bw.write("Case #" + (i+1) + ": " + y);
			bw.newLine();
		}
		bw.close();
	}
	
	private static int getY(String str) {
		String[] data = str.split(" ");
		int n = Integer.parseInt(data[0]);
		int s = Integer.parseInt(data[1]);
		int p = Integer.parseInt(data[2]);
		int[] t = new int[n];
		for (int i=0; i < n; i++){
			t[i] = Integer.parseInt(data[i+3]);
		}
		int y = 0;
		int base = 0;
		for(int j=0; j < t.length; j++){
			base = t[j] / 3;
			if(base >= p) { y++; }
			else if(base == p-1){
				if(t[j] - (base+p) > base-1 && t[j] > 0){
					y++;
				} else if(s>0 && t[j] - (base+p) > base-2 && t[j] > 0){
					s -= 1;
					y++;
				}
			} else if(base == p-2){
				if(s > 0 && t[j] - (base+p) > base-1 && t[j] > 0){
					s -= 1;
					y++;
				}
			}
		}
		
		return y;
	}

}

package codejam2012qual;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;

import util.InputReader;

public class DancingGooglers implements Runnable {

	private InputReader in;
	private PrintWriter out;
	private static String delimiter = " ";
	
	public static void main(String[] args) {
		new Thread(new DancingGooglers()).start();
	}
	
	public DancingGooglers() {
		try {			
			BufferedReader buffer = new BufferedReader(new FileReader("d:\\B-small-attempt0.in")); 
			in = new InputReader(buffer);
			
			System.setOut(new PrintStream(new FileOutputStream("d:\\output.txt")));
			out = new PrintWriter(System.out);
			
		} catch (FileNotFoundException e) {
			throw new RuntimeException();
		}	
	}

	@Override
	public void run() {
		
		int numTests = in.readInt();
		
        for (int testNumber = 0; testNumber < numTests; testNumber++) {
        	
			out.print("Case #" + (testNumber + 1) + ": ");
        
			String line = in.readString();
			String[] strVector = line.split(delimiter);
			
			int numbers = Integer.parseInt(strVector[0]);
			if (numbers == 0) {
				out.println(0);
				continue;
			}
			
			int surTriplets = Integer.parseInt(strVector[1]);
			int target = Integer.parseInt(strVector[2]);
						
			int[] scores = new int[numbers];
			for(int i=0; i<numbers; i++) {
				scores[i] = Integer.parseInt(strVector[i+3]);
			}
			
			int counter = 0;
			Arrays.sort(scores);
			for(int i = scores.length-1; i>=0 && surTriplets>=0 ; i--) {
				//out.print(scores[i]/3.0+"\t");
				
				if((scores[i] - target) >= 2*(target-1) && (scores[i] - target)>=0)
					counter++;
				else if(surTriplets > 0) {
					if((scores[i] - target) >= 2*(target-2) && (scores[i] - target)>=0) {
						counter++;
						surTriplets--;
					}						
				}
				else
					break;
			}			
			out.println(counter);
		}
		out.close();
	}

}
