package util.graph;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

public class DynDjikstra {
    public static State FindShortest(Node start, Node target) {
        PriorityQueue<Node> openSet = new PriorityQueue<>();
        Set<Node> closedSet = new HashSet<>();
        openSet.add(start);
        while (!openSet.isEmpty()) {
            Node current = openSet.poll();
            for (Edge edge : current.edges) {
                Node end = edge.target;
                if (closedSet.contains(end)) {
                    continue;
                }
                State newState = edge.travel(current.last);
                //if (end.equals(target)) {
                    //return newState;
                //}
                if (openSet.contains(end)) {
                    if (end.last.compareTo(newState)>0) {
                        end.last = newState;
                    }
                } else {
                    openSet.add(end);
                    end.last = newState;
                }
            }
            closedSet.add(current);
            if (closedSet.contains(target)) {
                return target.last;
            }
        }

        return target.last;
    }
}

package googlers;

import java.io.File;

import io.Reader;

public class DanceParty {
	public static void main(String[] args){
		new DanceParty();
	}
	
	
	
	public DanceParty(){
		String[] lines = Reader.getInput(new File("B-small-attempt1.in"));
		//String[] lines = Reader.getInput(new File("danceInput.in"));
		
		
		for (int i = 0; i < lines.length; i++){
			String line = lines[i];
			String[] peicesString = line.split(" ");
			int[] peices = new int[peicesString.length];
			for(int j = 0; j<peices.length; j++){
				peices[j] = Integer.parseInt(peicesString[j]);
			}
			
			int numGooglers = peices[0];
			int numSurprises = peices[1];
			int minBestResult = peices[2];
			int numPossible = 0;
			int numPossibleSurprises = 0;
			
			int N = 3*minBestResult-2;
			
			for (int j = 3; j < peices.length; j++){
				int sc = peices[j];
				if (sc>=N){
					numPossible++;
				}
				else if (numPossibleSurprises<numSurprises && sc>=N-2 && sc>=minBestResult){
					numPossibleSurprises++;
				}
			}
			
			numPossible+=numPossibleSurprises;
			if (numPossible>numGooglers)numPossible=numGooglers;
			if (numPossible<0)numPossible=0;
			
			System.out.println("Case #"+(i+1)+": "+numPossible);
		}
		
		
	}
}
