/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package codejam.common;

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

/**
 *
 * @author Lance Chen
 */
public class CodeHelper {

    private static String FILE_ROOT = "D:/workspace/googlecodejam/meta";

    public static List<List<String>> loadInputsExcludes(String fileName) {
        List<List<String>> result = new ArrayList<List<String>>();
        List<String> lines = FileUtil.readLines(FILE_ROOT + fileName);
        int index = 0;
        for (String line : lines) {
            if (index == 0) {
                index++;
                continue;
            }
            if (index % 2 == 1) {
                index++;
                continue;
            }
            List<String> dataList = new ArrayList<String>();
            String[] dataArray = line.split("\\s+");
            for (String data : dataArray) {
                if (data.trim().length() > 0) {
                    dataList.add(data);
                }
            }
            result.add(dataList);
            index++;
        }
        return result;
    }

    public static List<List<String>> loadInputs(String fileName) {
        List<List<String>> result = new ArrayList<List<String>>();
        List<String> lines = FileUtil.readLines(FILE_ROOT + fileName);
        for (String line : lines) {
            List<String> dataList = new ArrayList<String>();
            String[] dataArray = line.split("\\s+");
            for (String data : dataArray) {
                if (data.trim().length() > 0) {
                    dataList.add(data);
                }
            }
            result.add(dataList);
        }
        return result;
    }

    public static List<String> loadInputLines(String fileName) {
        return FileUtil.readLines(FILE_ROOT + fileName);
    }

    public static void writeOutputs(String fileName, List<String> lines) {
        FileUtil.writeLines(FILE_ROOT + fileName, lines);
    }
}

/**
 * 
 * @author luoyuan
 *
 */
package codejam;

import java.util.ArrayList;
import static java.lang.Math.*;

public class Dancing {

	public static void bestResult(String inF,String outF) {
		InOutTool iot = new InOutTool(inF,outF);
		ArrayList<String> js = new ArrayList<String>();
		for(int i=1;i<iot.size();i++){
			String in = iot.get(i).trim();
			String[] num = in.split(" ");
			int n = Integer.parseInt(num[0]), s = Integer.parseInt(num[1]), p = Integer.parseInt(num[2]);
			int sup=0,count=0;
			for(int k=3;k<num.length;k++){
				int i_0=0,i_1=0,i_2=0;
				int temp = Integer.parseInt(num[k]);
				i_0 = temp/3;
				if(i_0>=p){
					count ++;
				}else{
					if(i_0<(p-2)||(temp-i_0)<p||(temp-i_0)>(2*p+2)||(temp-i_0)<(2*p-2)){
						//no case want
					}else{//maybe surprising cases
						i_1 = p; i_2 = temp - i_0 - i_1;
						count ++;
						if(abs(i_2-i_0)>1||abs(i_2-i_1)>1)sup ++;
					}
				}
			}
			if(sup>s)count -= (sup-s);
			js.add("Case #" + i + ": " + count);
		}
		iot.clear();iot.addAll(js);
		iot.outText();
	}
	public static void main(String...args){
		Dancing.bestResult("B-small-attempt0.in", "B-small-attempt0.out");
	}
}
