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;
    }
}

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


public class Dancers implements Solver {
	int N;
	int S;
	int p;
	List<Integer> dan = new ArrayList<Integer>();
	

	public Dancers(List<String> lineas) {
		String[] cosa = lineas.get(0).split(" ");
		N=Integer.parseInt(cosa[0]);
		S=Integer.parseInt(cosa[1]);
		p=Integer.parseInt(cosa[2]);
		for (int i=0; i<N; i++){
			dan.add(Integer.parseInt(cosa[i+3]));
		}
		// TODO Auto-generated constructor stub
	}


	@Override
	public String solve() {
		int conta=0;
		for (int i=0; i<N; i++){
			if (dan.get(i)>=p+p-1+p-1 && dan.get(i)>=p){
				conta++;
			}
			else if(dan.get(i)>=p+p-2+p-2 && dan.get(i)>=p && S>0){
				conta++;
				S--;
			}
		}
		// TODO Auto-generated method stub
		return conta+"";
	}

}
