/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 3/3/12
 * Time: 11:00 AM
 * To change this template use File | Settings | File Templates.
 */

import SRMLib.MathLibrary;
import SRMLib.TestSRMLib;
import com.sun.org.apache.bcel.internal.generic.F2D;

import java.io.*;
import java.util.*;
import java.util.zip.Inflater;

public class SRM {
    public static void main(String[] args) throws IOException {
        //TestSRMLib.run();
        codeJam1.main();

        return;
    }
}
class codeJam1 {
    public static void main() throws IOException {
        String inputPath = "E:\\input.txt";
        String outputPath = "E:\\output.txt";
        BufferedReader input = new BufferedReader(new FileReader(inputPath));
        BufferedWriter output = new BufferedWriter(new FileWriter(outputPath));

        String line;
        line = input.readLine();
        int T = Integer.parseInt(line);
        for (int i = 1; i <= T; ++i) {
            line = input.readLine();
            String[] words = line.split(" ");
            int N = Integer.parseInt(words[0]);
            int S = Integer.parseInt(words[1]);
            int p = Integer.parseInt(words[2]);
            int n = 0;
            int res = 0;

            for (int j = 3; j < words.length; ++j) {
                if (p == 0) {
                    res++;
                    continue;
                }

                int t = Integer.parseInt(words[j]);
                if (p == 1) {
                    if (t > 0)
                        res++;
                    continue;
                }
                if (t >= 3 * p - 2)
                    res++;
                else if (t >= 3 * p - 4)
                    n++;
            }

            res += Math.min(n, S);
            output.write("Case #" + i + ": " + res);
            output.newLine();
        }

        input.close();
        output.close();
    }
}

package b;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class Dancing {
	List<Integer> ss = new ArrayList<>();
	int n;
	int min;
	int sp;
	int cnt = 0;
	
	public Dancing(int min, int sp, int[] sc) {
		this.min = min;
		this.n = sc.length;
		this.sp = sp;
		for(int s : sc) {
			ss.add(s);
		}
	}

	public static void main(String[] args) throws IOException {
//		System.out.println(new Dancing(5, 1, new int[] {15, 13, 11}).solve());
//		System.out.println(new Dancing(8, 0, new int[] {23, 22, 21}).solve());
//		System.out.println(new Dancing(1, 1, new int[] {8, 0}).solve());
//		System.out.println(new Dancing(8, 2, new int[] {29, 20, 8, 18, 18, 21}).solve());
		
		BufferedReader br = new BufferedReader(new FileReader("src/b/B-small-attempt0.in"));
		BufferedWriter bw = new BufferedWriter(new FileWriter("src/b/out"));
		
		int row = Integer.parseInt(br.readLine());
		System.out.println("ROW : " + row);
		
		for(int i=0; i<row; i++) {
			String[] line = br.readLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int sp = Integer.parseInt(line[1]);
			int min = Integer.parseInt(line[2]);
			int[] sc = new int[n];
			for(int j=0; j<n; j++) {
				sc[j] = Integer.parseInt(line[3+j]);
			}
			
			String res = "Case #" + (i+1) + ": " + new Dancing(min, sp, sc).solve();
			bw.write(res + "\n");
			System.out.println(res);
		}
		
		bw.close();
		br.close();
	}

	private int solve() {
		for(Iterator<Integer> it = ss.iterator(); it.hasNext();) { 
			int s = it.next();
			int rest = s - min;
			if (rest < 0) continue;
			if (rest /2 >= Math.max(min-1,0)) {
				cnt++;
				it.remove();
			}
		}
		
		Collections.sort(ss, new Comparator<Integer>() {
			public int compare(Integer o1, Integer o2) {
				return o2- o1;
			}
		});
		
		for(Iterator<Integer> it = ss.iterator(); it.hasNext();) {
			int s = it.next();
			int rest = s - min;
			if (rest < 0) continue;
			if (rest / 2 >=  Math.max(min-2, 0) && sp > 0) {
				cnt++;
				sp--;
				it.remove();
			}
		}
		
		return cnt;
	}
}
