/*
 * 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);
    }
}

package ru.guredd.codejam;

import java.util.StringTokenizer;

public class Qualification2012B {
    public void solve() {
        int count = Integer.valueOf(Main.inputData.get(0));
        for (int i = 0; i < count; i++) {
            int result = 0;

            String data = Main.inputData.get(i + 1);

            StringTokenizer st = new StringTokenizer(data, " ");
            int N = Integer.parseInt(st.nextToken());
            int S = Integer.parseInt(st.nextToken());
            int P = Integer.parseInt(st.nextToken());

            for (int j = 0; j < N; j++) {
                int tScore = Integer.parseInt(st.nextToken());

                if (tScore == 0) {
                    if(P == 0) result++;
                } else {
                    int d = tScore / 3;
                    if (d + 1 == P && tScore % 3 == 0 && S > 0) {
                        S--;
                        result++;
                    } else if (d + 1 >= P && !(d + 1 == P && tScore % 3 == 0)) {
                        result++;
                    } else if (d + 2 == P && tScore % 3 == 2 && S > 0) {
                        S--;
                        result++;
                    }
                }
            }
            Main.outputData.add("Case #" + (i + 1) + ": " + result);
        }
    }
}
