package com.silverduner.codejam;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;

public class Dancing {
	public static void main(String[] args) throws Exception {
		File input = new File("B-small-attempt0.in");
		BufferedReader in = new BufferedReader(new FileReader(input));

		File output = new File("1.out");
		BufferedWriter out = new BufferedWriter(new FileWriter(output));

		// parse input
		int N = Integer.parseInt(in.readLine());
		for(int i=0;i<N;i++) {
			String str = in.readLine();
			out.write("Case #"+(i+1)+": ");
			System.out.println("-------");
			String[] words = str.split(" ");
			int n = Integer.parseInt(words[0]);
			int suprise = Integer.parseInt(words[1]);
			int threshold = Integer.parseInt(words[2]);
			int[] scores = new int[n];
			for(int j=0;j<n;j++) {
				scores[j] = Integer.parseInt(words[3+j]);
			}
			int count = 0;
			for(int score : scores) {
				int a,b,c;
				boolean find = false;
				boolean sfind = false;
				for(a = 10; a>=0 && !find; a--) {
					if(3*a-4>score)
						continue;
					for(b = a; b>=0 && b >=a-2 && !find; b--) {
						for(c = b; c>=0 && c >=b-2 && c >=a-2 && !find; c--) {
							System.out.println(a+","+b+","+c);
							if(a+b+c==score) {
								if(a >= threshold) {
									if(a-c <= 1){
										count++;
										find = true;
										System.out.println("find!");
									}
									else if(a-c == 2){
										sfind = true;
										System.out.println("suprise!");
									}
								}
							}
							
						}
					}
				}
				if(!find && sfind && suprise > 0)
				{
					count++;
					suprise --;
				}
			}
			int maxCount = count;
			out.write(maxCount+"\n");
		}
		out.flush();
		out.close();
		in.close();
	}
}

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Googlers {

	public static void main(String[] args) throws FileNotFoundException {
		new Googlers().doProcessing(new File("D:\\codejam\\B\\small.txt"));
	}

	public void doProcessing(File inputFile) throws FileNotFoundException {
		Scanner scanner = new Scanner(inputFile).useDelimiter("\n");
		if (scanner != null) {
			int totalCases = Integer.parseInt(scanner.next().trim());
			int k = 1 ;
			if (totalCases > 0) {
				while (scanner.hasNext()) {
					String[] rowValues = scanner.next().trim().split(" ");

					int totalGooglers = Integer.parseInt(rowValues[0]);
					// System.out.println("Total Googlers : " + totalGooglers);
					int totalSuprisingCases = Integer.parseInt(rowValues[1]);
					// System.out.println("Total Surprising Cases : " +
					// totalSuprisingCases);

					int averageScore = Integer.parseInt(rowValues[2]);
					// System.out.println("Total Success Cases : " +
					// averageScore);
					// System.out.println("Total Length : " + rowValues.length);

					int[] totalMarks = new int[totalGooglers];
					int j = 0;
					for (int i = 3; i < rowValues.length; i++) {
						totalMarks[j] = Integer.parseInt(rowValues[i].trim());
						// System.out.println("Value Put : " + totalMarks[j]);
						j++;
					}
					int successCase = getSuccessCase(totalGooglers,
							averageScore, totalSuprisingCases, totalMarks);
					System.out.println("Case #" + k++ + ": " + successCase);
				}

			}
		}
		scanner.close();
	}

	public boolean doNormalCase(int totalScore, int averageScore) {
		boolean success = false;
		int X3value = averageScore * 3;
		if (totalScore >= X3value) {
			success = true;
		} else if ((totalScore >= X3value - 1) || (totalScore >= X3value + 1)) {
			success = true;
		} else if ((totalScore >= X3value - 2) || (totalScore >= X3value + 2)) {
			success = true;
		} else {
			success = false;
		}
		return success;
	}

	public boolean doSurprisingCase(int totalScore, int averageScore) {
		boolean success = false;
		int X3value = averageScore * 3;
		// System.out.println("Total Score : " + totalScore);
		// System.out.println("Average Score : " + X3value);
		if (((totalScore >= X3value - 3) || (totalScore >= X3value + 3))
				&& totalScore > averageScore) {
			success = true;
		} else if (((totalScore >= X3value - 4) || (totalScore >= X3value + 4))
				&& totalScore > averageScore) {
			success = true;
		} else {
			success = false;
		}
		return success;
	}

	public int getSuccessCase(int totalCses, int averageScore,
			int surprisingCase, int[] caseValues) {
		int totalSuccess = 0;
		for (int i = 0; i < totalCses; i++) {
			// System.out.println("----------------------Value Put : " +
			// totalCses);
			boolean normalCaseSuccess = doNormalCase(caseValues[i],
					averageScore);
			if (!normalCaseSuccess) {
				if (surprisingCase > 0) {
					boolean surprisingCaseSuccess = doSurprisingCase(
							caseValues[i], averageScore);
					if (surprisingCaseSuccess) {
						// System.out.println("Surprising Success..." +
						// caseValues[i]);
						totalSuccess++;
						surprisingCase--;
					}
				}
			} else {
				totalSuccess++;
			}
		}
		return totalSuccess;
	}

}
