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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Main {

	public static void main(String[] args) throws IOException {
		File file = new File("B-small-attempt0.in");
		FileReader fr = new FileReader(file);
		BufferedReader in = new BufferedReader(fr);

		String line = in.readLine();
		String[] tokens;
		int num = Integer.parseInt(line);
		int i = 1, N, s, p, t, minAlways, minSurprising, always, surprising, finalCount;
		while (i <= num) {
			line = in.readLine();
			tokens = line.split(" ");
			N = Integer.parseInt(tokens[0]);
			s = Integer.parseInt(tokens[1]);
			p = Integer.parseInt(tokens[2]);
			if (p >= 2) {
				minAlways = 3 * p - 2;
				minSurprising = 3 * p - 4;
			} else {
				minAlways = p;
				minSurprising = 1;
			}

			always = 0;
			surprising = 0;

			for (int j = 0; j < N; j++) {
				t = Integer.parseInt(tokens[3 + j]);
				if (t >= minAlways) {
					always++;
				} else if (t >= minSurprising) {
					surprising++;
				}
			}

			finalCount = always + Math.min(s, surprising);

			System.out.println("Case #" + i + ": " + finalCount);
			i++;
		}
	}

}
