import java.util.List;


public class Case implements Runnable {

	private int id;
	private String output;

	private int n;
	private int s;
	private int p;
	private List<Integer> g;

	public Case(int id) {
		this.id = id;
	}

	public Case(int id, int n, int s, int p, List<Integer> g) {
		super();
		this.id = id;
		this.n = n;
		this.s = s;
		this.p = p;
		this.g = g;
	}

	public String solve() {
		int res = 0;
		for (int googler : g) {
			int b = googler / 3;
			boolean div = googler % 3 == 0;
			if (b >= p) {
				res++;
				continue;
			}
			if (p == b+1) {
				if (div && s > 0 && b > 0) {
					res++;
					s--;
					continue;
				}
				if (!div) {
					res++;
					continue;
				}
			}
			if (p == b+2) {
				if (3*b+2 == googler && s > 0) {
					res++;
					s--;
				}
			}
		}
		return String.valueOf(res);
	}

	@Override
	public void run() {
		output = solve();
	}

	@Override
	public String toString() {
		return "Case #" + id + ": " + output;
	}

}
package qualification;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;

public class DancingWithGoogler {
	public static void main(String[] args) throws IOException{
		BufferedReader file = new BufferedReader(new FileReader(new File("src/input")));
		String firstline = file.readLine();
		int casenum = Integer.parseInt(firstline);
		StringWriter s= new StringWriter();
		for(int i=0;i<casenum;++i){
			int count = 0;
			String temp = file.readLine();
			int start=0,end=0;
			while(temp.charAt(end)!=' '){
				++end;
			}
			int number = Integer.parseInt(temp.substring(start, end));
			start = ++end;
			while(temp.charAt(end)!=' '){
				++end;
			}
			int surprise = Integer.parseInt(temp.substring(start, end));
			start=++end;
			while(temp.charAt(end)!=' '){
				++end;
			}
			int p = Integer.parseInt(temp.substring(start, end));
			start = ++end;
			for(int j = 0;j<number;++j){
				int googler = -1;
				if(j<number-1){
					while(temp.charAt(end)!=' '){
						++end;
					}
					googler = Integer.parseInt(temp.substring(start, end));
					start = ++end;
				}
				else{
					googler = Integer.parseInt(temp.substring(start));//end of line has no space
				}
				if(googler<2||googler>28){
					//no surprising
					int min = googler/3;
					if(min>=p)++count;
				}
				else{
					if(googler<3*p-4){
						;//no-op
					}
					else if(googler>3*p-3){
						++count;
					}
					else{//only when the sum is 3p-3 or 3p-4 we need a surprise
						if(surprise>0){
							--surprise;
							++count;
						}
					}
				}
			}
			s.append("Case #"+(i+1)+": "+count);
			s.append("\n");
		}
		
		FileWriter fout = new FileWriter("src/out.txt");
		fout.write(s.toString());
		fout.close();
	}
}
