AlgoUniversity
  • Go Back
Discussion
Max Min Subarrays :

Author

Ayush Gangwani

Difficulty Level : Medium

Submissions : 505

Asked In : Oracle

Marks :15

: 20 | : 0

We have a number sequence $$$A=[A_1​,A_2​,…,A_N​]$$$ of length $$$N$$$ and integers $$$X$$$ and $$$Y$$$. Find the number of pairs of integers $$$(L,R)$$$ satisfying all the following conditions :

  • $$$1 \le L \le R \le N$$$
  • The maximum value of $$$A_L​,A_{L+1}​,…,A_R​$$$ is $$$X$$$, and the minimum is $$$Y$$$.

Input

The first line of input contains three space separated integers $$$N \hspace{2pt} (1 \le N \le 2 \times 10^5)$$$, $$$X$$$ and $$$Y$$$ $$$(1 \le Y \le X \le 2 \times 10^5)$$$ — the number of elements in the array $$$A$$$ and the values $$$X$$$ and $$$Y$$$ specified in the problem statement.

The second line of input contains $$$n$$$ space separated integers $$$A_1, A_2, ... A_N$$$ $$$(1 \le A_i \le 2 \times 10^5)$$$ — the elements of array $$$A$$$.

Output

Print a single integer — the answer to the problem in a single line.

Examples

Input
4 3 1
1 2 3 1
Output
4 
Input
5 2 1
1 3 2 4 1
Output
0 
Input
5 1 1
1 1 1 1 1
Output
15 
Input
10 8 1
2 7 1 8 2 8 1 8 2 8
Output
36 

Note

In sample test case 1, $$$4$$$ pairs satisfy the conditions: $$$(L,R)=(1,3),(1,4),(2,4),(3,4)$$$.

In sample test case 2, No pair $$$(L,R)$$$ satisfies the condition.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.