Problem:
Problem A. On-Call
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 has 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 remains high for a while, an alert is triggered and Fox Jiro receives a phone call. After that, if the frequency of server error responses remains low for a while, the alert will be 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 response for each of the last $D$ consecutive
minutes is greater than or equal to $U$.
The alert is resolved when the frequency of server error responses for each of the last $D$ consecutive minutes is less than or equal to $L$.
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 phone calls so many times that he forgot how many times the alerts were triggered. Your task is counting 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.
$N$ $U$ $L$ $D$
$x_1$ $x_2$ ... $x_N$
The first line consists of four integers $N$, $U$, $L$, and $D$. $N$ represents the length of the record of the frequency of server error responses.
$U$, $L$, and $D$ are the settings that determine the behavior of the monitoring system as explained above. Here, $N$ and $D$ satisfy
$1 \leq N, D \leq 2 \times 10^5$. $U$ and $L$ satisfy $0 \leq L < U \leq 2 \times 10^5$.
The second line consists of $N$ integers. The $i$-th integer represents the frequency of server error responses that occurred in the $i$-th minute. Each of the integers in the second line is between $0$ and $2 \times 10^5$ inclusive.
Output
Print the number of times the alerts were triggered in one line.
Examples
Input 1
15 1 0 3
1 1 1 1 0 0 0 1 1 0 0 0 1 1 1
Output 1
2
Input 2
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
Output 2
2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)

int main(){
    ll n, u, l, d;
    cin >> n >> u >> l >> d;
    queue<ll> q;
    ll cntu = 0, cntl = 0;
    ll ans = 0;
    bool alert = false;
    rep(i, n){
        ll x;
        cin >> x;
        q.push(x);
        if(x >= u)cntu++;
        if(x <= l)cntl++;
        if(q.size() > d){
            if(q.front() >= u)cntu--;
            if(q.front() <= l)cntl--;
            q.pop();
        }
        if(cntu == d){
            if(!alert){
                alert = true;
                ans++;
            }
        }
        if(cntl == d){
            alert = false;
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4688
final_rank: 7

code_snippet: #include<bits/extc++.h>
#define rep(i,n) for(int i = 0; i<(n); i++)
#define all(a) begin(a),end(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 998244353;
const int inf = (1<<30);
const ll INF = (1ull<<62);
const int dx[8] = {1,0,-1,0,1,1,-1,-1};
const int dy[8] = {0,1,0,-1,1,-1,1,-1};
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b){ return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b){ return a > b && (a = b, true);}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    ll n,u,l,d; cin>>n>>u>>l>>d;
    int minsum = d;
    int maxsum = 0;
    vector<ll> a(d+n);
    int p = 0;
    ll ans = 0;
    rep(i,n) cin>>a[i+d];

    for(int i = d; i<n+d; i++){
        if(a[i-d] >= u) maxsum--; 
        else if(a[i-d] <= l) minsum--; 

        if(a[i] >= u) maxsum++; 
        else if(a[i] <= l) minsum++; 
        if(maxsum == d && p == 0){
            ans++;
            p = 1;
        }else if(minsum == d && p == 1){
            p = 0;
        }
        //cout<<i-d<<" "<<maxsum<<" "<<minsum<<" "<<ans<<" "<<p<<endl;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 5808
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

using ll = long long;
const int INF = 1e9+7;

using vc = vector<char>;
using vvc = vector<vc>;

void solve(){
    int n, u, l, d;
    cin>>n>>u>>l>>d;

    vector <int> v(n);
    for(int i=0; i<n; i++)
        cin>>v[i];

    map <int, int> m;
    for(int i=0; i<d; i++)
        m[v[i]]++;
    
    int res=0;
    bool b=false;
    if(m.begin()->first>=u){
        res++;
        b=true;
    }

    // for(auto x : m)
    //     cerr<<x.first<<" "<<x.second<<"\n";

    int le=0, r=d;
    while(r<n){
        if(m.find(v[r])==m.end())
            m[v[r]]=0;
        m[v[r]]++;
        m[v[le]]--;
        if(m[v[le]]==0)
            m.erase(v[le]);
        
        if(b){
            if(m.rbegin()->first<=l)
                b=false;
        }
        else{
            if(m.begin()->first>=u){
                b=true;
                res++;
            }
        }

        le++; r++;
    }

    cout<<res<<"\n";
}

int main(){
    // map <int, int> m;
    // m.erase(0);
    // m[0]=1;
    // cout<<m[0]
    int t=1;
    while(t--)
        solve();
}
accuracy: 1
time_ms: 120
memory_kb: 9268
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
 
int main () {
    int N, U, D, L;
    cin >> N >> U >> L >> D;

    vi x(N);
    for (int i = 0; i < N; i++) { cin >> x[i]; }

    int alert = 0;
    bool inalert = false;
    bool repeat = false;
    int countu = 0;
    int countl = 0;

    for (int i = 0; i < N; i++)
    {
        if (x[i] >= U) { countu++; countl = 0;}
        else if (x[i] <= L) { countl++; countu = 0;}
        else { countu = countl = 0; }

        if (countu == D) { inalert = true; }
        if (countl == D) { inalert = false; repeat = false; }
        if (inalert == true && repeat == false)
        {
            alert++;
            repeat = true;
        }
        
    }
    
    cout << alert << '\n';

}
accuracy: 1
time_ms: 30
memory_kb: 3924
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
 
int main () {
    int N, U, D, L;
    cin >> N >> U >> L >> D;

    vi x(N);
    for (int i = 0; i < N; i++) { cin >> x[i]; }

    int alert = 0;
    bool inalert = false;
    bool repeat = false;
    int countu = 0, countl = 0;

    for (int i = 0; i < N; i++)
    {
        if (x[i] >= U) { countu++; countl = 0;}
        else if (x[i] <= L) { countl++; countu = 0;}
        else { countu = countl = 0; }

        if (countu == D) { inalert = true; }
        if (countl == D) { inalert = false; repeat = false; }
        if (inalert == true && repeat == false)
        {
            alert++;
            repeat = true;
        }
        
    }
    
    cout << alert<<endl;

}
accuracy: 1
time_ms: 30
memory_kb: 3736
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
	int N, U,L,D;

    cin >> N >> U >> L >> D;

    int cons_u =1;
    int cons_l =1;

    bool alert = false;
    int sum =0;
    int x2, x;

    cin >> x2;

    for(int i =0; i< N-1; i++){

        cin >> x;

        if(x >= U && x2 >= U){
            cons_u++;
            cons_l =1;
        }

        else if(x <= L && x2 <= L){
            cons_l++;
            cons_u =1;
        }

        else{
            cons_u =1;
            cons_l =1;
        }

        if(cons_l >= D){
            alert = false;
        }

        if(cons_u >= D && !alert){
            sum++;
            alert = true;
        }

        x2 = x;

    }
    
    cout << sum << endl;


}
accuracy: 0.2692307692307692
time_ms: 20
memory_kb: 3404
final_rank: 16

code_snippet: #include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    #define prq priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    #define all(a) (a).begin(), (a).end()
    
    /*
    
    */
    ll N,L,U,D;
    ll X[200009];
    ll S1[200009];
    ll S2[200009];
    int main(){  
        cin>>N>>U>>L>>D;
        for(int i=1; i<=N; i++){
            cin>>X[i];
            S1[i]+=S1[i-1]+(X[i]>=U);
            S2[i]+=S2[i-1]+(X[i]<=L);
        }
        bool flag=false;
        int cnt=0;
        for(int i=D; i<=N; i++){
            ll sum1=S1[i]-S1[i-D];
            ll sum2=S2[i]-S2[i-D];

            if(!flag){
                if(sum1==D){
                    flag=true;
                    cnt++;
                }
            }
            else{
                if(sum2==D){
                    flag=false;
                }
            }
        }
        cout<<cnt<<endl;
    }
accuracy: 1
time_ms: 30
memory_kb: 7948
final_rank: 11

code_snippet: #include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    #define prq priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    #define all(a) (a).begin(), (a).end()
    
    /*
    
    */
    ll N,L,U,D;
    ll X[200009];
    ll S1[200009];
    ll S2[100009];
    int main(){  
        cin>>N>>U>>L>>D;
        for(int i=1; i<=N; i++){
            cin>>X[i];
            S1[i]+=S1[i-1]+(X[i]>=U);
            S2[i]+=S2[i-1]+(X[i]<=L);
        }
        bool flag=false;
        int cnt=0;
        for(int i=D; i<=N; i++){
            ll sum1=S1[i]-S1[i-D];
            ll sum2=S2[i]-S2[i-D];

            if(!flag){
                if(sum1==D){
                    flag=true;
                    cnt++;
                }
            }
            else{
                if(sum2==D){
                    flag=false;
                }
            }
        }
        cout<<cnt<<endl;
    }
accuracy: 0.23076923076923078
time_ms: 20
memory_kb: 6528
final_rank: 18

code_snippet: #include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    #define prq priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    #define all(a) (a).begin(), (a).end()
    
    /*
    
    */
    ll N,L,U,D;
    ll X[200009],S[200009];
    int main(){  
        cin>>N>>U>>L>>D;
        for(int i=1; i<=N; i++){
            cin>>X[i];
            S[i]+=S[i-1]+X[i];
        }
        bool flag=false;
        int cnt=0;
        for(int i=1; i<=N; i++){
            ll sum=S[i]-S[max(0LL,i-D)];
            ll len;
            if(i<D)len=i;
            else len=D;
            if(!flag){
                
                if(sum>=U*len){
                    flag=true;
                    cnt++;
                }
            }
            else{
                if(sum<=L*len){
                    flag=false;
                }
            }
        }
        cout<<cnt<<endl;
    }
accuracy: 0.07692307692307693
time_ms: 20
memory_kb: 5004
final_rank: 19

code_snippet: #include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    #define prq priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    #define all(a) (a).begin(), (a).end()
    
    /*
    
    */
    ll N,L,U,D;
    ll X[200009],S[200009];
    int main(){  
        cin>>N>>U>>L>>D;
        for(int i=1; i<=N; i++){
            cin>>X[i];
            S[i]+=S[i-1]+X[i];
        }
        bool flag=false;
        int cnt=0;
        for(int i=1; i<=N; i++){
            ll sum=S[i]-S[max(0LL,i-D)];
            
            if(!flag){
                if(sum>=U*D){
                    flag=true;
                    cnt++;
                }
            }
            else{
                if(sum<=L*D){
                    flag=false;
                }
            }
        }
        cout<<cnt<<endl;
    }
accuracy: 0.07692307692307693
time_ms: 20
memory_kb: 5016
final_rank: 20

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n,U,L,D;cin >> n >> U >> L >> D;
  vi x(n);cin >> x;
  multiset<int> mst;
  int res = 0,alt = 0;
  rep(i,0,n){
    mst.insert(x[i]);
    if(i-D >= 0)mst.erase(mst.find(x[i-D]));
    if(sz(mst) >= D){
      if(alt == 0){
        if(*mst.begin() >= U)res++,alt = 1;
      }else{
        if(*mst.rbegin() <= L)alt = 0;
      }
    }
  }
  cout << res << endl;
  

  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 13224
final_rank: 13

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
namespace ranges = std::ranges;
namespace views = std::views;
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"


#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa

#include <concepts>

namespace zawa {

namespace concepts {

template <class T>
concept Semigroup = requires {
    typename T::Element;
    { T::operation(std::declval<typename T::Element>(), std::declval<typename T::Element>()) } -> std::same_as<typename T::Element>;
};

} // namespace concepts

} // namespace zawa





namespace zawa {

namespace concepts {

template <class T>
concept Identitiable = requires {
    typename T::Element;
    { T::identity() } -> std::same_as<typename T::Element>;
};

template <class T>
concept Monoid = Semigroup<T> and Identitiable<T>;

} // namespace

} // namespace zawa


namespace zawa {

namespace concepts {

template <class T>
concept SWAGable = requires {
    typename T::Element;
    typename T::Fold;
    typename T::Fold::Element;
    { T::convert(std::declval<typename T::Element>()) } -> std::same_as<typename T::Fold::Element>;
    { T::pushBack(std::declval<typename T::Fold::Element>(), std::declval<typename T::Element>()) } -> std::same_as<typename T::Fold::Element>;
    { T::pushFront(std::declval<typename T::Fold::Element>(), std::declval<typename T::Element>()) } -> std::same_as<typename T::Fold::Element>;
};

} // namespace concepts

template <concepts::Semigroup S>
class SemigroupSWAGable {
public:
    using Element = typename S::Element;
    using Fold = S;
    using F = Fold::Element;
    static F convert(Element v) {
        return v;
    }
    static F pushBack(F f, Element v) {
        return S::operation(f, v);
    }
    static F pushFront(F f, Element v) {
        return S::operation(v, f);
    }
    static F operation(F l, F r) {
        return S::operation(l, r);
    }
};

template <concepts::Monoid S>
class MonoidSWAGable {
public:
    using Element = typename S::Element;
    using Fold = S;
    using F = Fold::Element;
    static F convert(Element v) {
        return v;
    }
    static F pushBack(F f, Element v) {
        return S::operation(f, v);
    }
    static F pushFront(F f, Element v) {
        return S::operation(v, f);
    }
    static F identity() {
        return S::identity();
    }
    static F operation(F l, F r) {
        return S::operation(l, r);
    }
};

} // namespace zawa

#include <optional>

namespace zawa {

template <concepts::SWAGable S>
class FoldableQueue {
public:

    using V = typename S::Element;
    using Fold = typename S::Fold;
    using F = typename Fold::Element;

    FoldableQueue() = default;

    usize size() const noexcept {
        return m_front.size() + m_back.size();
    }

    bool empty() const noexcept {
        return size() == 0u;
    }

    void push(const V& v) {
        m_raw.push_back(v);
        m_back.push_back(m_back.size() ? S::pushBack(m_back.back(), v) : S::convert(v));
    }

    void pop() {
        assert(size());
        move();
        m_front.pop_back();
    }

    std::pair<F, F> get() const requires concepts::Identitiable<typename S::Fold> {
        return {
            m_front.empty() ? Fold::identity() : m_front.back(),
            m_back.empty() ? Fold::identity() : m_back.back()
        };
    }

    std::pair<std::optional<F>, std::optional<F>> get() const {
        return {
            m_front.empty() ? std::nullopt : std::optional<F>{m_front.back().first},
            m_back.empty() ? std::nullopt : std::optional<F>{m_back.back().first}
        };
    }

    F product() const requires concepts::Monoid<typename S::Fold> {
        auto [f, b] = get();
        return Fold::operation(f, b);
    }

    F product() const requires concepts::Semigroup<typename S::Fold> {
        assert(m_front.size() or m_back.size());
        if (m_front.empty()) return m_back.back().first;
        if (m_back.empty()) return m_front.back().first;
        return S::Fold::operation(m_front.back().first, m_back.back().first);
    }
    
private:
    std::vector<F> m_front{}, m_back{};
    std::vector<V> m_raw{};

    void move() {
        if (m_front.size()) return;
        while (m_back.size()) {
            m_back.pop_back();
            V v{m_raw.back()};
            m_raw.pop_back();
            m_front.push_back(m_front.size() ? S::pushFront(m_front.back(), v) : S::convert(v));
        }
    }
};

} // namespace zawa

#include <iterator>
#include <type_traits>

namespace zawa {

template <concepts::Semigroup S>
std::vector<typename S::Element> EnumerateStaticLengthProduct(const std::vector<typename S::Element>& A, usize K) {
    assert(K > 0);
    if (A.size() < K) return {};
    std::vector<typename S::Element> res(A.size() - K + 1);
    FoldableQueue<SemigroupSWAGable<S>> que{};
    for (usize i{} ; i < K ; i++) {
        que.push(A[i]);
    }
    for (usize i{} ; i < A.size() - K ; i++) {
        res[i] = que.product();
        que.pop();
        que.push(A[i + K]);
    }
    res[A.size() - K] = que.product();
    return res;
}

} // namespace zawa
using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
struct S {
    using Element = std::pair<int, int>;
    static Element identity() {
        return {(int)1e9, 0};
    }
    static Element operation(Element L, Element R) {
        return {std::min(L.first, R.first), std::max(L.second, R.second)};
    }
};
int N, U, L, D;
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> U >> L >> D;
    std::vector<std::pair<int, int>> X(N);
    for (auto& [p, q] : X) {
        std::cin >> p;
        q = p;
    }
    int ans = 0, cur = 0;
    for (const std::pair<int, int>& v : EnumerateStaticLengthProduct<S>(X, D)) {
        if (cur == 0 and v.first >= U) {
            ans++;
            cur = 1;
        }
        if (v.second <= L) cur = 0;
    }
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 11564
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i < (ll)(n); i++)
#define rrep(i, s, e) for(ll i=s; i>= (ll)(e); i--)
#define repn(i, e) for (ll i=0; i <= (ll)(e); i++)
#define reps(i, s,e) for(ll i=s; i < (ll)(e); i++ )
#define repsn(i,s,e) for(ll i=s; i<=(ll)(e); i++)
#define each(p,a) for(auto &p: a)
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll,ll>> vpll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef tuple<ll, ll, ll> tpl3;
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll)x.size()
template<class T> bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) { if (a < b) {a =b; return true;} return false;}
vector<ll> _ta = {0,0,1,-1,1,1,-1,1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll i, ll j, ll h, ll w) {return (0 <= i && i < h && 0 <= j && j < w);}
ll INF = 1LL << 60;

int main() {
  ll n,u,l,d;cin >> n >> u >> l >> d;
  vll x(n);
  rep(i,n) {
    cin >> x[i];
  }
  multiset<ll> se;
  rep(i,d) {
    se.insert(x[i]);
  }
  bool ala = *se.begin() >= u;
  ll ans = ala;
  reps(i,d,n) {
    se.erase(se.find(x[i-d]));
    se.insert(x[i]);
    if (*se.begin() >= u) {
      if (!ala) {
        ans++;
      }
      ala = true;
    }
    if (*prev(se.end()) <= l) {
      ala = false;
    }
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 13172
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;

int main() {
    int n,u,l,d;
    cin >> n >> u >> l >> d;
    int ans = 0;
    vector<int> v(n);
    rep(i,n) {
        cin >> v[i];
    }

    vector<int> cum(n);
    rep(i,n) {
        if (!i) cum[i] = v[i];
        else {
            cum[i] = cum[i-1] + v[i];
            if (i >= d) {
                cum[i] -= v[i-d];
            }
        }
    }
    bool flag = false;
    int up = 0;
    int down = 0;
    rep(i,n) {
        if (v[i] >= u) {
            up++;
        }
        else {
            up = 0;
        }

        if (v[i] <= l) {
            down++;
        }
        else {
            down = 0;
        }

        if (flag) {
            if (down >= d) {
                flag = false;
            }
        }
        else {
            if (up >= d) {
                flag = true;
                ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4656
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    int N, U, L, D;
    cin >> N >> U >> L >> D;
    vector<int> X(N);
    rep(i,0,N) cin >> X[i];
    vector<int> A(N+1,0), B(N+1,0);
    rep(i,0,N) {
        if (X[i] >= U) A[i+1] = A[i]+1;
        else A[i+1] = 0;
        if (X[i] <= L) B[i+1] = B[i]+1;
        else B[i+1] = 0;
    }
    int ANS = 0, Cur = 0;
    rep(i,1,N+1) {
        if (A[i] >= D) {
            if (Cur == 0) ANS++;
            Cur = 1;
        }
        if (B[i] >= D) Cur = 0;
    }
    cout << ANS << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 5412
final_rank: 10

code_snippet: #include<bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 200000;
static int vect[MAX_N];
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
void test()
{
}

//------------------------------------------------------------------------------
int solve(int N, int U, int L, int D)
{
    //--------------------------------------------------------------------------
    // init params:
    //--------------------------------------------------------------------------
    // compute:
    int res = 0;
    bool triggered = false;    
    int start = 0;
    //--------------------------------------------------------------------------
    bool done = false;
    while (start < N && !done)
    {
        if (triggered)
        {
            int end = start;
            while (end < N && vect[end] > L) end++;
            if (vect[end] > L) { done = true; break; }
            start = end;

            while (end < N && vect[end] <= L) end++;
            if (vect[end] <= L)
            {
                if (end-start+1 >= D) { triggered = false; }
                done = true;
            }
            else if (end-start >= D) { triggered = false; }
            start = end;
        }
        else
        {
            int end = start;
            while (end < N && vect[end] < U) end++;
            if (vect[end] < L) { done = true; break; }
            start = end;

            while (end < N && vect[end] >= U) end++;
            if (vect[end] >= U)
            {
                if (end-start+1 >= D) { triggered = true; res++; }
                done = true;
            }
            else if (end-start >= D) { triggered = true; res++; }
            start = end;
        }
    }
    //--------------------------------------------------------------------------
    // report:
    //printf("%d\n", res);

    return res;
}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, U, L, D, num;
    num = scanf("%d %d %d %d ", &N, &U, &L, &D);
    for (int i=0; i<N; ++i) num = scanf("%d ", &vect[i]);
    int res = solve(N, U, L, D);
    printf("%d\n", res);
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 10
memory_kb: 4316
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

const ll mod = 1e9 + 7;


int main() {
    
    ll N,U,L,D;
    cin>>N>>U>>L>>D;
    ll an=0,c=0;
    bool alert=0;
    rep(i,N){
        ll x;
        cin>>x;
        if(x>=U){
            if(c<0)c=0;
            c++;
            if(c>=D&&alert==0){
                an++;
                alert=1;
            }
        }
        else if(x<=L){
            if(c>0)c=0;
            c--;
            if(-c>=D&&alert==1){
                // an++;
                alert=0;
            }
        }
        else c=0;
    }
    cout<<an<<endl;

}
accuracy: 1
time_ms: 30
memory_kb: 3456
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

const ll mod = 1e9 + 7;


int main() {
    
    ll N,U,L,D;
    cin>>N>>U>>L>>D;
    ll an=0,c=0;
    bool alert=0;
    rep(i,N){
        ll x;
        cin>>x;
        if(x>=U){
            if(c<0)c=0;
            c++;
            if(c>=D&&alert==0){
                an++;
                alert=1;
            }
        }
        if(x<=L){
            if(c>0)c=0;
            c--;
            if(-c>=D&&alert==1){
                // an++;
                alert=0;
            }
        }
    }
    cout<<an<<endl;

}
accuracy: 0.23076923076923078
time_ms: 20
memory_kb: 3436
final_rank: 17

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

template < class T > vector< T >& operator++(vector< T >& a) { for(T& x : a) x++; return a; }
template < class T > vector< T >& operator--(vector< T >& a) { for(T& x : a) x--; return a; }
template < class T > vector< T >  operator++(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x++; return res; }
template < class T > vector< T >  operator--(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x--; return res; }

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int N = in(), U = in(), L = in(), D = in();
    vector<int> x = in(N);

    vector<int> Ux(N), Lx(N);
    for(int i : rep(N)) {
        Ux[i] = (x[i] >= U);
        Lx[i] = (x[i] <= L);
    }
    vector<int> Usum(N + 1, 0), Lsum(N + 1, 0);
    for(int i : rep(N)) {
        Usum[i + 1] = Usum[i] + Ux[i];
        Lsum[i + 1] = Lsum[i] + Lx[i];
    }

    bool triggered = false;
    int ans = 0;
    for(int i : rep(N)) {
        if(0 <= i - D + 1) {
            if(not triggered and Usum[i + 1] - Usum[i + 1 - D] == D) {
                triggered = true;
                ans += 1;
            } else if(triggered and Lsum[i + 1] - Lsum[i + 1 - D] == D) {
                triggered = false;
            }
        }
    }
    print(ans);
}
accuracy: 1
time_ms: 10
memory_kb: 6928
final_rank: 8

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

template < class T > vector< T >& operator++(vector< T >& a) { for(T& x : a) x++; return a; }
template < class T > vector< T >& operator--(vector< T >& a) { for(T& x : a) x--; return a; }
template < class T > vector< T >  operator++(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x++; return res; }
template < class T > vector< T >  operator--(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x--; return res; }

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int N = in(), U = in(), L = in(), D = in();
    vector<int> x = in(N);

    vector<int> Ux(N), Lx(N);
    for(int i : rep(N)) {
        Ux[i] = (x[i] >= U);
        Lx[i] = (x[i] <= L);
    }
    vector<int> Usum(N + 1, 0), Lsum(N + 1, 0);
    for(int i : rep(N)) {
        Usum[i + 1] = Usum[i] + Ux[i];
        Lsum[i + 1] = Lsum[i] + Lx[i];
    }

    bool triggered = false;
    int ans = 0;
    for(int i : rep(N)) {
        if(0 <= i - D + 1) {
            if(not triggered and Usum[i + 1] - Usum[i + 1 - D] == D) {
                triggered = true;
                ans += 1;
            } else if(triggered and Lsum[i + 1] - Lsum[i + 1 - D] == D) {
                triggered = false;
            }
        }
    }
    print(ans);
}
accuracy: 1
time_ms: 10
memory_kb: 6928
final_rank: 8