#USACOC1111A. Above the Median

Above the Median

Farmer John has lined up his NN cows in a row to measure their heights; cow ii has height HiH_i nanometers--FJ believes in precise measurements! He wants to take a picture of some contiguous subsequence of the cows to submit to a bovine photography contest at the county fair.

The fair has a very strange rule about all submitted photos: a photograph is only valid to submit if it depicts a group of cows whose median height is at least a certain threshold XX.

For purposes of this problem, we define the median of an array A0KA_{0\ldots K} to be AK2A_{\lceil \frac{K}{2}\rceil} after AA is sorted, where K2\lceil \frac{K}{2}\rceil gives K2\frac{K}{2} rounded up to the nearest integer (or K2\frac{K}{2} itself, it K2\frac{K}{2} is an integer to begin with). For example the median of {7,3,2,6}\{7, 3, 2, 6\} is 66, and the median of {5,4,8}\{5, 4, 8\} is 55.

Please help FJ count the number of different contiguous subsequences of hiscows that he could potentially submit to the photography contest.

  • 1N100,0001 \leqslant N \leqslant 100,000
  • 1Hi1,000,000,0001 \leqslant H_i \leqslant 1,000,000,000
  • 1X1,000,000,0001 \leqslant X \leqslant 1,000,000,000

Input Format

  • Line 11: Two space-separated integers: NN and XX.
  • Lines 2..N+12..N+1: Line i+1i+1 contains the single integer HiH_i.

Output Format:

  • Line 11: The number of subsequences of FJ's cows that have median at least XX. Note this may not fit into a 32-bit integer.
4 6
10
5
6
2
7

Sample Details

Input Details:

FJ's four cows have heights 1010, 55, 66, 22. We want to know how many contiguous subsequences have median at least 66.

Output Details:

There are 1010 possible contiguous subsequences to consider. Of these, only 77 have median at least 66. They are {10}\{10\}, {6}\{6\}, {10,5}\{10, 5\}, {5,6}\{5, 6\}, {6,2}\{6, 2\}, {10,5,6}\{10, 5, 6\}, {10,5,6,2}\{10, 5, 6, 2\}.