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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.google.common.base.Splitter;

public class ProblemB extends CodeJamRunner {

	
	private int nrOfCases;
	private int testCaseIndex;
	int numberOfGooglers;
	int surprisingTriplets;
	int personalBestBar;
	int maxAbovePersonalBestBar;

	private List<Integer> totalPoints = new ArrayList<Integer>();

	public void process(int lineNr, String line) {
		if (lineNr == 1) {
			nrOfCases = Integer.valueOf(line);
			resetForNextCase();
		} else {
			Iterator<String> split = Splitter.on(" ").split(line).iterator();
			numberOfGooglers = Integer.parseInt(split.next());
			surprisingTriplets = Integer.parseInt(split.next());
			personalBestBar = Integer.parseInt(split.next());
			while ( split.hasNext() ) {
				totalPoints.add(Integer.parseInt(split.next()));
			}
			calc();
			write();
			resetForNextCase();
		}
	}

	private void write() {
		String resultLine = "Case #" + testCaseIndex + ": " + maxAbovePersonalBestBar;
		printlnOutput(resultLine);
	}

	private void calc() {
		int normalAboveCount = 0;
		int surpriseAboveCount = 0;
		for ( int i : totalPoints ) {
			Triplet t = new Triplet( i );
			if ( t.calcMaxNormal() >= personalBestBar ){
				normalAboveCount++;
			}
			else if ( t.calcMaxSurprise() >= personalBestBar ){
				surpriseAboveCount++;
			}
		}
		int surprisesHappened = Math.min(surpriseAboveCount, surprisingTriplets );
		maxAbovePersonalBestBar = normalAboveCount + surprisesHappened;
	}

	private void resetForNextCase() {
		testCaseIndex++;
		totalPoints.clear();
	}

	public static void main(String args[]) {
		ProblemB ao = new ProblemB();
		ao.run(args);
	}

}
