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

/*
 * Dancing
 * Jason Bradley Nel
 * 16287398
 */
import java.io.*;

public class Dancing {

    public static void main(String[] args) {

        In input = new In("input.txt");
        int T = Integer.parseInt(input.readLine());

        for (int i = 0; i < T; i++) {
            System.out.printf("Case #%d: ", i + 1);
            int N = input.readInt();
            int s = input.readInt();
            int p = input.readInt();
            int c = 0;//counter for >=p cases
            //System.out.printf("N: %d, S: %d, P: %d, R: ", N, s, p);
            
            for (int j = 0; j < N; j++) {
                
                int score = input.readInt();
                int q = score / 3;
                int m = score % 3;
                //System.out.printf("%2d (%d, %d) ", scores[j], q, m);
                                
                switch (m) {
                    case 0:
                        if (q >= p) {
                            c++;
                        } else if (((q + 1) == p) && (s > 0) && (q != 0)) {
                            c++;
                            s--;
                        }
                        break;
                    case 1:
                        if (q >= p) {
                            c++;
                        } else if ((q + 1) == p) {
                            c++;
                        }
                        break;
                    case 2:
                        if (q >= p) {
                            c++;
                        } else if ((q + 1) == p) {
                            c++;
                        } else if (((q + 2) == p) && (s > 0)) {
                            c++;
                            s--;
                        }
                        break;
                }
            }
            //System.out.printf("Best result of %d or higher: ", p);
            System.out.println(c);
        }


    }
}

package com.sam.googlecodejam.speakingtoungue;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

import com.sam.googlecodejam.helper.InputReader;

/**
 * This class generates the mapping based on the samples that have been provided.
 * @author Saifuddin Merchant
 *
 */
public class TranslatorMapping {

	public Map<String, String> iAvalableLines = new HashMap<>(); 
	public Map<Character, Character> iLetterMapping = new TreeMap<>();

	public TranslatorMapping() {
		iAvalableLines.put("ejp mysljylc kd kxveddknmc re jsicpdrysi", "our language is impossible to understand");
		iAvalableLines.put("rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd", "there are twenty six factorial possibilities");
		iAvalableLines.put("de kr kd eoya kw aej tysr re ujdr lkgc jv", "so it is okay if you want to just give up");
	}
	
	public void mapLetters()
	{
		for(Entry<String , String> lineEntry: iAvalableLines.entrySet())
		{
			String keyLine = lineEntry.getKey();
			String keyValue = lineEntry.getValue();
			int index=0;
			for(Character keyChar:keyLine.toCharArray())
			{
				iLetterMapping.put(keyChar, keyValue.charAt(index++));
			}
		}
		iLetterMapping.put('z', 'q');//add the missing mappings
		iLetterMapping.put('q', 'z');//add the missing mappings
		//System.out.println(iLetterMapping.size());
		//System.out.println(iLetterMapping);
	}
	
	public void translate(String pInput)
	{
		for(Character translateChar:pInput.toCharArray())
		{
			System.out.print(iLetterMapping.get(translateChar));
		}
	}
	
	public static void main(String[] args) {
		TranslatorMapping mapping = new TranslatorMapping();
		mapping.mapLetters();
		
		InputReader reader = new InputReader("c://input.in");
		reader.readNextLine();	//read the line number off - we don't need it
		
		String lineRead = null;
		int i=1;
		while((lineRead=reader.readNextLine())!=null )
		{
			System.out.print("Case #"+i+": "); i++;
			mapping.translate(lineRead);
			System.out.println();
		}
	}
}
