## Mock CCC '18 Contest 5 J3/S1 - Carol's Cute Center

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 1G

Author:
Problem type

Mastering the art of counting spikes was a tough activity for Carol, but she did it gracefully and uneventfully.

Even though she was successfully able to count the spikes on all of the cacti and figure out the most frequent counts of spikes for her cacti, she still did not feel as though this provided her with an adequate reservoir of cuteness that she could rely on.

Desperate for more statistics from which she can derive cuteness, Carol starts attempting to study math. She learns about how to compute the mean of a sequence of integers, but does not like the word mean since it could have other implications.

In pursuit of the perfect statistics, Carol ended up finding balance in the one statistic that is the most resistant - the median. She chooses not to think too hard about the fact that mean is a subsequence of median.

A refresher for those who are unfamiliar with median - given values through in sorted order, the median is .

Not one to easily switch out of nurturing mode, Carol wants to select three cacti such that the median number of spikes among the three cacti is . Given all of the cacti that Carol owns, count how many distinct sets of three cacti Carol can select such that the median number of spikes on the three cacti is . Keep in mind that even if cacti have the same number of spikes, that does not make them identical.

#### Input Specification

The first line of the input consists of two space-separated integers, and .

The next line contains space-separated integers, the values through representing the number of spikes on the th cactus.

#### Output Specification

Output, on a single line, the number of sets of three cacti Carol can select such that the median number of spikes among the selected three cacti is .

#### Sample Input

4 1
1 1 2 2

#### Sample Output

2