#P6334. [COCI 2007/2008 #1] SREDNJI

[COCI 2007/2008 #1] SREDNJI

Problem Description

Given a permutation a1,,ana_1, \dots, a_n of 1n1 \sim n with length nn, find how many subarrays of odd length have median BB.

  • 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,Bn, B.

The second line contains nn integers, a permutation of 1n1 \sim n.

Output Format

Output the number of odd-length subarrays whose median is BB.

5 4
1 2 3 4 5
2
6 3
1 2 4 5 6 3
1
7 4
5 7 2 4 3 1 6
4

Hint

Explanation for Sample 33

All possible cases are: 4 7 2 4 5 7 2 4 3 5 7 2 4 3 1 6.

Constraints

For 100%100\% of the testdata, it is guaranteed that 1n1051 \le n \le 10^5, 1Bn1 \le B \le n.

Notes

This problem is translated from COCI2007-2008 CONTEST #1 T5 SREDNJI

Translated by ChatGPT 5