P6334 [COCI 2007/2008 #1] SREDNJI
Description
Given a permutation $a_1, \dots, a_n$ of $1 \sim n$ with length $n$, find how many **subarrays** of odd length have median $B$.
- Definition of subarray: the remaining sequence after deleting some numbers from the beginning (possibly none) and some numbers from the end (possibly none) of this permutation.
- Definition of median: after sorting a sequence in increasing order, the number that is in the middle.
Input Format
The first line contains two integers $n, B$.
The second line contains $n$ integers, a permutation of $1 \sim n$.
Output Format
Output the number of odd-length subarrays whose median is $B$.
Explanation/Hint
#### Explanation for Sample $3$
All possible cases are: `4` `7 2 4` `5 7 2 4 3` `5 7 2 4 3 1 6`.
#### Constraints
For $100\%$ of the testdata, it is guaranteed that $1 \le n \le 10^5$, $1 \le B \le n$.
#### Notes
**This problem is translated from [COCI2007-2008](https://hsin.hr/coci/archive/2007_2008/) [CONTEST #1](https://hsin.hr/coci/archive/2007_2008/contest1_tasks.pdf) *T5 SREDNJI***
Translated by ChatGPT 5