This page is still under construction.

Parts of this page are still being built. What you see may change.

On-Call

Interview

Time limit2sMemory limit512 MB

Summary
Count how many times an alert turns on given a stream of per-minute error counts, a high threshold U, a low threshold L, and a window length D.
Level

Medium5 of 10

Topics
Simulation, Sliding window, Implementation, Array
Solved
No attempts yet

Problem

Fox Jiro works for a company that runs a social networking site for programmers. His duty is to recover the service as soon as possible when it becomes unavailable.

His predecessor developed a monitoring system that detects service unavailability based on the frequency of server error responses such as "502 Bad Gateway" and "503 Service Unavailable". The system records the frequency of server error responses per minute. If the frequency stays high for a while, an alert is triggered and Fox Jiro receives a phone call. After that, if the frequency stays low for a while, the alert is resolved.

In more detail, alerts are triggered and resolved as follows.

  • Initially, no alert is triggered.
  • An alert is triggered when no alert is triggered and the frequency of server error responses for each of the last DD consecutive minutes is greater than or equal to UU.
  • The alert is resolved when the frequency of server error responses for each of the last DD consecutive minutes is less than or equal to LL.

Fox Jiro can receive compensation from the company according to the number of times he received phone calls due to the alerts. Last month he received so many phone calls that he forgot how many times the alerts were triggered. Your task is to count the number of alerts triggered based on the record of server error responses.

Input

The input consists of a single test case of the following format.

NN UU LL DD

x_1x\_1 x_2x\_2 …\dots x_Nx\_N

The first line consists of four integers NN, UU, LL, and DD. NN represents the length of the record of the frequency of server error responses. UU, LL, and DD are the settings that determine the behavior of the monitoring system as explained above. Here, NN and DD satisfy 1≤N,D≤2×1051 \le N, D \le 2 \times 10^5. UU and LL satisfy 0≤L<U≤2×1050 \le L < U \le 2 \times 10^5.

The second line consists of NN integers. The ii-th integer represents the frequency of server error responses that occurred in the ii-th minute. Each of the integers in the second line is between 0 and 2×1052 \times 10^5 inclusive.

Output

Print the number of times the alerts were triggered in one line.

Examples2

  1. Example 1

    Input
    15 1 0 3
    1 1 1 1 0 0 0 1 1 0 0 0 1 1 1
    
    Expected output
    2
    
  2. Example 2

    Input
    24 3 1 3
    1 1 3 2 3 1 1 1 3 3 3 3 1 3 3 3 1 1 1 2 1 3 3 3
    
    Expected output
    2