package codejam;

import fixjava.Pair;

public class Utils {

	public static long minLong(long firstVal, long... otherVals) {
		long minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static int minInt(int firstVal, int... otherVals) {
		int minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static float minFloat(float firstVal, float... otherVals) {
		float minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	/**
	 * ArgMin returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMin(int[] arr) {
		int min = arr[0];
		int argMin = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < min) {
				min = arr[i];
				argMin = i;
			}
		}
		return new Pair<Integer, Integer>(argMin, min);
	}

	/**
	 * ArgMax returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMax(int[] arr) {
		int max = arr[0];
		int argMax = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] > max) {
				max = arr[i];
				argMax = i;
			}
		}
		return new Pair<Integer, Integer>(argMax, max);
	}

}

package com.codejam.twelve;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ProbB {
	public static void main(String[] args) throws IOException {
		FileReader fr = new FileReader(
				"D:\\Dev\\Workspaces\\Android\\codejam\\io\\qualification\\B-large.in");
		FileWriter fw = new FileWriter(
				"D:\\Dev\\Workspaces\\Android\\codejam\\io\\qualification\\B-large.out");
		BufferedReader br = new BufferedReader(fr);
		BufferedWriter bw = new BufferedWriter(fw);

		int t = Integer.parseInt(br.readLine());

		for (int i = 1; i <= t; i++) {
			String s = br.readLine();
			bw.append("Case #" + i + ": ");

			String ss[] = s.split(" ");
			int nn[] = new int[ss.length];
			for (int j = 0; j < ss.length; j++) {
				nn[j] = Integer.parseInt(ss[j]);
			}

			int N = nn[0];
			int S = nn[1];
			int P = nn[2];
			int sa=0;
			int na=0;

			for (int j = 0; j < N; j++) {
				int trip = nn[3+j];
				int remain = trip-P;
				if(remain<0)
					continue;
				int other = P-(remain/2);
				
				if(other==2){
					sa++;					
				}
				else if(other<2){
					na++;
				}
			}
			
			if(sa>=S)
				sa=S;

			bw.append(""+(na+sa));
			
			bw.newLine();
		}

		bw.flush();
		bw.close();
		br.close();
	}
}
