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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class Googlers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		
		String fichier ="C:\\result.txt";
		int compteurlignes = 0;
		int nombreCas ;
		ArrayList<String> googlers = new ArrayList<String>();
		ArrayList<String> results = new ArrayList<String>();
		//lecture du fichier texte	
		try
		{
			InputStream ips=new FileInputStream(fichier); 
			InputStreamReader ipsr=new InputStreamReader(ips);
			BufferedReader br=new BufferedReader(ipsr);
			String ligne;
			while ((ligne=br.readLine())!=null){
				compteurlignes++;
				//System.out.println(ligne);
				if (compteurlignes ==1)
				{
					nombreCas = Integer.valueOf(ligne);
				}
				else
				{
					googlers.add(ligne);
					//System.out.println(ligne);
				}
				
			}
			br.close(); 
			
		
			
			
			//traitement par ligne
			ArrayList<String> nombres = new ArrayList<String>();
			for(int i = 0; i < googlers.size();i++)
			{
				 ligne = googlers.get(i);
				 
				 
				 //get numbers
				 StringTokenizer st = new StringTokenizer(ligne, " ");
				    while (st.hasMoreTokens())
				    {
				      nombres.add(st.nextToken());
				      
				    }
				    
				    int numberGooglers = Integer.parseInt(nombres.get(0));
				    int surprises = Integer.parseInt(nombres.get(1));
				    int chiffre = Integer.parseInt(nombres.get(2));
				    int value = 0;
				    
				    int totalNumber = chiffre *3;
				    
				    for(int x = 0; x < numberGooglers; x++)
				    {
				    	int totalMark = Integer.parseInt(nombres.get(x+3));
				    	
				    	if(totalNumber ==0)
				    	{
				    		value++;
				    	}
				    	else if(totalMark <= totalNumber+2 && totalMark >= totalNumber-2)
				    	{
				    		value++;
				    	}
				    	else if(totalMark == totalNumber-3 || totalMark == totalNumber-4)
				    	{
				    		if (surprises >0 && totalMark != 0)
				    		{
				    			surprises--;
				    			value++;
				    		}
				    	}
				    	else if(totalMark >= totalNumber+3) value++;
				    }
				    
				    results.add(String.valueOf(value));
				    System.out.println("result : "+value);
				    //clean arrayList
				    nombres = new ArrayList<String>();
			}
		
		
		
		}
		catch (Exception e)
		{
			System.out.println(e.toString());
		
		}
		
		
		
		
		
		//écrire dans le fichier
		try 
		{
			FileWriter fw = new FileWriter (fichier);
			BufferedWriter bw = new BufferedWriter (fw);
			PrintWriter fichierSortie = new PrintWriter (bw); 
			for (int w =0; w<results.size();w++)
			{
				fichierSortie.println ("Case #"+(w+1)+": "+results.get(w)); 
			}
			fichierSortie.close();
			System.out.println("Le fichier " + fichier + " a été créé!"); 
		}
		catch (Exception e)
		{
			System.out.println(e.toString());
		}	

	}

}
