cswork / OAOpen practice workspace

MathWorksOA #6

Investable Periods

Estimated HardJudge-ready

Topics (AI-labelled)Two Pointers

Given daily prices, a target minimum price, and a target maximum price, count the contiguous subarrays whose minimum is exactly the target minimum price and whose maximum is exactly the target maximum price.

See below for this site's input/output protocol.

Input

The first line contains n min_price max_price, and the next line contains n prices. 1≤n≤100000, 1≤price[i]≤10^9, 1≤min_price≤max_price≤10^9.

Output

Output the number of qualifying contiguous ranges. The answer may exceed the range of a 32-bit signed integer, so use a 64-bit integer.

Example 1

Input:

5 3 5
4 5 3 3 1

Output:

4

Example 2

Input:

5 1 2
2 2 1 5 1

Output:

2

Example 3

Input:

4 2 3
1 2 3 2

Output:

3

Editorial

Loading solution…