package problem1;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;





public class Problem1 {

    public static void main(String[] args) throws FileNotFoundException, IOException{
        try {
             TextIO.readFile("L:\\Coodejam\\Input\\Input.txt");
        }
        catch (IllegalArgumentException e) {
              System.out.println("Can't open file ");
              System.exit(0);
         }
        
        FileOutputStream fout = new FileOutputStream("L:\\Coodejam\\Output\\output.txt");
        PrintStream ps=new PrintStream(fout);
        
        int cases=TextIO.getInt();
        int googlers=0,surprising=0,least=0;
        for(int i=0;i<cases;i++){
            int counter=0;
            googlers=TextIO.getInt();
            surprising=TextIO.getInt();
            least=TextIO.getInt();
            int score[]=new int[googlers];
            for(int j=0;j<googlers;j++){
                score[j]=TextIO.getInt();
                 }
            
            
            
            
            Arrays.sort(score);
            int temp=0;
            int sup[]=new int[surprising];
            
          for(int j=0;j<googlers && surprising>0;j++){
               if(biggestNS(score[j])<least && biggestS(score[j])==least){
                   surprising--;
                   counter++;
                }
               }
           
            for(int j=0;j<googlers;j++){
                if(surprising==0)temp=biggestNS(score[j]);
                    
                else {
                    temp=biggestS(score[j]);
                    surprising--;     
                } 
                   if(temp>=least)counter++;
           
             }
            
             ps.println("Case #"+(i+1)+": "+counter);
        }
    }
    
   static int biggestNS(int x){
       if(x==0)return 0;
       if(x==1)return 1;
       return ((x-1)/3)+1;
   }
   
   static int biggestS(int x){
       if(x==0)return 0;
       if(x==1)return 1;
       return ((x-2)/3)+2;
   }
}
package googleJam;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class GoogleDancers 
{

	public static void main(String[] args) 
	{
		Scanner scan = null;
		try
		{
			scan = new Scanner(new File(args[0]));
		}
		catch (FileNotFoundException e)
		{
			System.err.println("File not found!");
			return;
		}
		if (!scan.hasNext())
		{
			System.err.println("Nothing in File!");
			return;
		}
		int testCases = Integer.parseInt(scan.nextLine());
		String[] line;
		String str;
		int theFabulousGoogleDancers;
		int soManySurprises;
		int whoIsBetterThanMe;
		int itsAStretch;
		int noSurpriseNeeded;
		int iAmBetterThanYou;
		int canReachWithSurprise;
		int number = 1;
		int combined;
		while (scan.hasNext())
		{
			System.out.print("Case #" + number + ": ");
			iAmBetterThanYou = 0;
			itsAStretch = 0;
			str = scan.nextLine();
			line = str.split(" ");
			theFabulousGoogleDancers = Integer.parseInt(line[0]);
			soManySurprises = Integer.parseInt(line[1]);
			whoIsBetterThanMe = Integer.parseInt(line[2]);
			noSurpriseNeeded = (whoIsBetterThanMe + (whoIsBetterThanMe-1) + (whoIsBetterThanMe-1));
			canReachWithSurprise = (whoIsBetterThanMe + (whoIsBetterThanMe-2) + (whoIsBetterThanMe - 2));
			if (whoIsBetterThanMe == 1)
			{
				noSurpriseNeeded = 1;
				canReachWithSurprise = 1;
			}
			if (whoIsBetterThanMe == 0)
			{
				noSurpriseNeeded = 0;
				canReachWithSurprise = 0;
			}
			for (int score = 3; score < line.length; score++)
			{
				if ((Integer.parseInt(line[score])) >= canReachWithSurprise && Integer.parseInt(line[score]) < noSurpriseNeeded)
				{
					itsAStretch++;
				}
				else if (Integer.parseInt(line[score]) >= noSurpriseNeeded)
				{
					iAmBetterThanYou++;
				}
			}
			if (itsAStretch <= soManySurprises)
			{
				combined = iAmBetterThanYou + itsAStretch;
			}
			else
			{
				combined = iAmBetterThanYou + soManySurprises;
			}

			System.out.print(combined);
			if(scan.hasNext())
			{
				System.out.println();
			}
			number++;
		}
	}

}
