Problem:
Score : 200 points

Problem Statement

You have written N problems to hold programming contests.
The i-th problem will have a score of P_i points if used in a contest.

With these problems, you would like to hold as many contests as possible under the following condition:

A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.

The same problem should not be used in multiple contests.
At most how many contests can be held?

Constraints

3 \leq N \leq 100

1 \leq P_i \leq 20 (1 \leq i \leq N)

1 \leq A < B < 20

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A B
P_1 P_2 ... P_N

Output

Print the answer.

Sample Input 1

7
5 15
1 10 16 2 7 20 12

Sample Output 1

2

Two contests can be held by putting the first, second, third problems and the fourth, fifth, sixth problems together.

Sample Input 2

8
3 8
5 5 5 10 10 10 15 20

Sample Output 2

0

No contest can be held, because there is no problem with a score of A = 3 or less.

Sample Input 3

3
5 6
5 6 10

Sample Output 3

1

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static int n;
        static int a;
        static int b;

        static void Main(string[] args)
        {
            //[summary]B - Contests
            n = int.Parse(Console.ReadLine());

            var line = ReadLine();
            a = line[0];
            b = line[1];

            var p = ReadLine().OrderBy(x => x).ToArray();
            int count = CountContests(p);

            Console.WriteLine(count);
        }

        static int CountContests(int[] p)
        {
            var isUsed = new bool[n];
            int count = 0;

            while (true)
            {
                bool isFound = false;

                for (int i = 0; i < n; i++)
                {
                    if (p[i] <= a && !isUsed[i])
                    {
                        isFound = true;

                        for (int j = i + 1; j < n; j++)
                        {
                            if (p[j] > a && p[j] <= b && !isUsed[j])
                            {
                                for (int k = j + 1; k < n; k++)
                                {
                                    if (p[k] > b && !isUsed[k])
                                    {
                                        count++;

                                        isUsed[i] = true;
                                        isUsed[j] = true;
                                        isUsed[k] = true;
                                    }
                                }
                            }
                        }
                    }

                    if (!isFound)
                    {
                        return count;
                    }
                }
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}