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 de.johanneslauber.codejam;

import java.io.IOException;

/**
 * 
 * @author Johannes Lauber - joh.lauber@googlemail.com
 * 
 */
public class Main {

	/**
	 * @author Johannes Lauber - joh.lauber@googlemail.com
	 * @param Args
	 */
	public static void main(String[] Args) {
		// solveProblem("input/A-small-practice.in", "StoreCredit");
		// solveProblem("input/A-large-practice.in", "StoreCredit");
		// solveProblem("input/B-small-practice.in", "ReverseWords");
		// solveProblem("input/B-large-practice.in", "ReverseWords");
		// solveProblem("input/C-small-practice.in", "T9Spelling");
		// solveProblem("input/C-large-practice.in", "T9Spelling");
		// solveProblem("input/A-small-practice.in", "SpeakinginTongues");
		solveProblem("input/B-small-attempt.in", "DancingGooglers");
	}

	/**
	 * 
	 * @author Johannes Lauber - joh.lauber@googlemail.com
	 * @param fileName
	 * @param problemName
	 */
	private static void solveProblem(String fileName, String problemName) {
		CaseProvider caseProvider = new CaseProvider();
		try {
			try {
				caseProvider.importFile(
						fileName,
						Class.forName("de.johanneslauber.codejam.model.impl."
								+ problemName + "Case"));

				caseProvider.solveCases(Class
						.forName("de.johanneslauber.codejam.model.impl."
								+ problemName + "Problem"));
			} catch (ClassNotFoundException e) {
				System.out.println("Error finding implemented Case: "
						+ e.getMessage());
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		} catch (IOException e) {
			System.out.println("Error reading file: " + e.getMessage());
		}
	}
}