#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<< (ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}

template<typename T>
struct BinaryIndexedTree{
    vector<T> dat;
    BinaryIndexedTree(int n):dat(n+1,0){}
    void add(int i,T x){
        if (i==0) return;
        for (;i<=dat.size();i+=(i&-i)) dat[i]+=x;
    }
    T sum(int i){
        T res=0;
        for (;i>0;i-=(i&-i)) res+=dat[i];
        return res;
    }
    T query(int l,int r){ //[l,r)
        return sum(r-1)-sum(l-1);
    }
    int lower_bound(T x){
        if (x<=0) return 0;
        int lb=0,r=1;
        while(r<dat.size()) r<<=1;
        for (;r>0;r>>=1){
            if (lb+r<dat.size()&&dat[lb+r]<x){
                x-=dat[lb+r]; lb+=r;
            }
        }
        return lb+1;
    }
    void add0(int i,T x){add(i+1,x);}
    T sum0(int i){return sum(i+1);}
    T query0(int l,int r){return sum(r)-sum(l);}
};

const int MAX=2e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> a(n),b(n+1,0),c(n+1,0),d(n+1),e(n+1);
    for (int i=0;i<n;++i){
        cin >> a[i];
        b[i+1]=(a[i]<=m?1:0);
        c[i+1]=(a[i]<=m-1?1:0);
    }
    for (int i=0;i<=n;++i){
        if (i){
            b[i]+=b[i-1];
            c[i]+=c[i-1];
        }
        d[i]=2*b[i]-i+MAX;
        e[i]=2*c[i]-i+MAX;
    }
    BinaryIndexedTree<int> BIT0(MAX*2),BIT1(MAX*2);
    ll ans0=0,ans1=0;
    for (int i=0;i<=n;++i){
        ans0+=BIT0.sum(d[i]);
        ans1+=BIT1.sum(e[i]);
        BIT0.add(d[i],1);
        BIT1.add(e[i],1);
    }
    cout << ans0-ans1 << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
struct BinaryIndexedTree{
    vector<T> dat;
    BinaryIndexedTree(int n):dat(n+1,0){}
    void add(int i,T x){
        if (i==0) return;
        for (;i<=dat.size();i+=(i&-i)) dat[i]+=x;
    }
    T sum(int i){
        T res=0;
        for (;i>0;i-=(i&-i)) res+=dat[i];
        return res;
    }
    T query(int l,int r){ //[l,r)
        return sum(r-1)-sum(l-1);
    }
    int lower_bound(T x){
        if (x<=0) return 0;
        int lb=0,r=1;
        while(r<dat.size()) r<<=1;
        for (;r>0;r>>=1){
            if (lb+r<dat.size()&&dat[lb+r]<x){
                x-=dat[lb+r]; lb+=r;
            }
        }
        return lb+1;
    }
    void add0(int i,T x){add(i+1,x);}
    T sum0(int i){return sum(i+1);}
    T query0(int l,int r){return sum(r)-sum(l);}
};

const int MAX=2e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> a(n),b(n+1,0),c(n+1,0);
    for (int i=0;i<n;++i){
        cin >> a[i];
        b[i+1]=(a[i]<=m?1:0);
        c[i+1]=(a[i]<=m-1?1:0);
        b[i+1]+=b[i];
        c[i+1]+=c[i];
    }
    for (int i=0;i<=n;++i){
        b[i]=2*b[i]-i+MAX;
        c[i]=2*c[i]-i+MAX;
    }
    BinaryIndexedTree<int> BIT0(MAX*2),BIT1(MAX*2);
    ll ans0=0,ans1=0;
    for (int i=0;i<=n;++i){
        ans0+=BIT0.sum(b[i]);
        ans1+=BIT1.sum(c[i]);
        BIT0.add(b[i],1);
        BIT1.add(c[i],1);
    }
    cout << ans0-ans1 << '\n';
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int a[maxn];
ll c[maxn];
int lb(int x){return x&(-x);}
void add(int x)
{
    for(int i = x; i <= 400005; i += lb(i))
        c[i]++;
}
ll get(int x)
{
    ll ans = 0;
    for(int i = x; i >= 1; i -= lb(i))
    ans += c[i];
    return ans;
}
int main()
{
   int n,m;
   while(cin>>n>>m)
   {
       for(int i = 1; i <= n; ++i)cin>>a[i];
       int x = 0,y = 0;
       clr(c,0);
       int now = 200000;
       for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m?1:-1);
            x += get(now-1);
            if(now >= 200001)x++;
            //cout<<x<<"  "<<now<<endl;
            add(now);
        }
        clr(c,0);
        now = 200000;
        for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m+1?1:-1);
            y += get(now-1);
            if(now >= 200001)y++;
            add(now);
        }
        //cout<<x<<"  "<<y<<endl;
        cout<<x - y<<endl;
   }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int a[maxn];
ll c[maxn];
int lb(int x){return x&(-x);}
void add(int x)
{
    for(int i = x; i <= 400005; i += lb(i))
        c[i]++;
}
ll get(int x)
{
    ll ans = 0;
    for(int i = x; i >= 1; i -= lb(i))
    ans += c[i];
    return ans;
}
int main()
{
   int n,m;
   while(cin>>n>>m)
   {
       for(int i = 1; i <= n; ++i)cin>>a[i];
       ll x = 0,y = 0;
       clr(c,0);
       int now = 200001;
       for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m?1:-1);
            x += get(now-1);
            if(now >= 200002)x++;
            //cout<<x<<"  "<<now<<endl;
            add(now);
        }
        clr(c,0);
        now = 200001;
        for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m+1?1:-1);
            y += get(now-1);
            if(now >= 200002)y++;
            add(now);
        }
        //cout<<x<<"  "<<y<<endl;
        cout<<x - y<<endl;
   }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int a[maxn];
ll c[maxn];
int lb(int x){return x&(-x);}
void add(int x)
{
    for(int i = x; i <= 400005; i += lb(i))
        c[i]++;
}
ll get(int x)
{
    ll ans = 0;
    for(int i = x; i >= 1; i -= lb(i))
    ans += c[i];
    return ans;
}
int main()
{
   int n,m;
   while(cin>>n>>m)
   {
       for(int i = 1; i <= n; ++i)cin>>a[i];
       ll x = 0,y = 0;
       clr(c,0);
       int now = 200000;
       for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m?1:-1);
            x += get(now-1);
            if(now >= 200001)x++;
            //cout<<x<<"  "<<now<<endl;
            add(now);
        }
        clr(c,0);
        now = 200000;
        for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m+1?1:-1);
            y += get(now-1);
            if(now >= 200001)y++;
            add(now);
        }
        //cout<<x<<"  "<<y<<endl;
        cout<<x - y<<endl;
   }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int a[maxn];
ll c[maxn];
int lb(int x){return x&(-x);}
void add(int x)
{
    for(int i = x; i <= 400000; i += lb(i))
        c[i]++;
}
ll get(int x)
{
    ll ans = 0;
    for(int i = x; i >= 1; i -= lb(i))
    ans += c[i];
    return ans;
}
int main()
{
   int n,m;
   while(cin>>n>>m)
   {
       for(int i = 1; i <= n; ++i)cin>>a[i];
       int x = 0,y = 0;
       clr(c,0);
       int now = 200000;
       for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m?1:-1);
            x += get(now-1);
            if(now >= 200001)x++;
            //cout<<x<<"  "<<now<<endl;
            add(now);
        }
        clr(c,0);
        now = 200000;
        for(int i = 1; i <= n; ++i)
        {
            now += (a[i] >= m+1?1:-1);
            y += get(now-1);
            if(now >= 200001)y++;
            add(now);
        }
        //cout<<x<<"  "<<y<<endl;
        cout<<x - y<<endl;
   }
}


// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
#define rreps(i, s, n) for (int i = n - 1; (int)(s) <= i; --i)
// reps(s,n)[::-1]
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* _sep, const char* _term) : sep(_sep), term(_term) {}
        template <class... Args> void operator()(const Args&... args) const { print(args...); }
        template <typename T> void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T> void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++) std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail> void print(const T& head, const Tail&... tail) const {
            std::cout << head, print_rest(tail...);
        }
        template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const {
            std::cout << sep << head, print_rest(tail...);
        }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints print;

ll f(V<int> A, int m, int n) {
    rep(i, n) {
        if (A[i] <= m) {
            A[i] = 1;
        } else {
            A[i] = -1;
        }
    }
    int idx = n;
    atcoder::fenwick_tree<ll> fw(2 * n + 1);
    ll ans = 0;
    rep(i, n) {
        fw.add(idx, 1);
        idx += A[i];
        ans += fw.sum(0, idx + 1);
    }
    return ans;
}

void solve() {
    int n, m;
    cin >> n >> m;
    V<int> A(n);
    rep(i, n) cin >> A[i];
    print()(f(A, m, n) - f(A, m - 1, n));
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}


// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>

#include <cassert>
#include <numeric>
#include <type_traits>

namespace atcoder {

namespace internal {

#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

#else

template <class T> using is_integral = typename std::is_integral<T>;

template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;

#endif

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {

// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
template <class T> struct fenwick_tree {
    using U = internal::to_unsigned_t<T>;

  public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

}  // namespace atcoder

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
#define rreps(i, s, n) for (int i = n - 1; (int)(s) <= i; --i)
// reps(s,n)[::-1]
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* _sep, const char* _term) : sep(_sep), term(_term) {}
        template <class... Args> void operator()(const Args&... args) const { print(args...); }
        template <typename T> void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T> void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++) std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail> void print(const T& head, const Tail&... tail) const {
            std::cout << head, print_rest(tail...);
        }
        template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const {
            std::cout << sep << head, print_rest(tail...);
        }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints print;

ll f(V<int> A, int m, int n) {
    rep(i, n) {
        if (A[i] <= m) {
            A[i] = 1;
        } else {
            A[i] = -1;
        }
    }
    int idx = n;
    atcoder::fenwick_tree<ll> fw(2 * n + 1);
    ll ans = 0;
    rep(i, n) {
        fw.add(idx, 1);
        idx += A[i];
        ans += fw.sum(0, idx + 1);
    }
    return ans;
}

void solve() {
    int n, m;
    cin >> n >> m;
    V<int> A(n);
    rep(i, n) cin >> A[i];
    print()(f(A, m, n) - f(A, m - 1, n));
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}


#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))

namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
	bool IOerror=0;
	inline char nc() {
		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
		if(p1==pend) {
			p1=buf;
			pend=buf+fread(buf,1,BUF_SIZE,stdin);
			if(pend==p1) {
				IOerror=1;
				return -1;
			}
		}
		return *p1++;
	}
	inline bool blank(char ch) {
		return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
	}
	template<class T> inline bool read(T &x) {
		bool sign=0;
		char ch=nc();
		x=0;
		for(; blank(ch); ch=nc());
		if(IOerror)return false;
		if(ch=='-')sign=1,ch=nc();
		for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
		if(sign)x=-x;
		return true;
	}
	template<class T,class... U>bool read(T& h,U&... t) {
		return read(h)&&read(t...);
	}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;
const int N = 2e5+10;

int a[N],b[N<<1],n,m;

void add(int x){
	for(int i=x;i<N;i+=lowbit(i)) b[i]++;
}

int get(int x){
	int ans=0;
	for(int i=x;i;i-=lowbit(i)) ans+=b[i];
	return ans;
}

ll solve(int x){
	mem(b,0);
	int sum=n+1;
	ll ans=0;
	add(sum);
	for(int i=1;i<=n;i++){
		if(a[i]>=x) sum++;
		else sum--;
		ans+=get(sum-1);
		add(sum);
	}
	return ans;
}

int main() {

#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	cout<<solve(m)-solve(m+1)<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
	bool IOerror=0;
	inline char nc() {
		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
		if(p1==pend) {
			p1=buf;
			pend=buf+fread(buf,1,BUF_SIZE,stdin);
			if(pend==p1) {
				IOerror=1;
				return -1;
			}
		}
		return *p1++;
	}
	inline bool blank(char ch) {
		return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
	}
	template<class T> inline bool read(T &x) {
		bool sign=0;
		char ch=nc();
		x=0;
		for(; blank(ch); ch=nc());
		if(IOerror)return false;
		if(ch=='-')sign=1,ch=nc();
		for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
		if(sign)x=-x;
		return true;
	}
	template<class T,class... U>bool read(T& h,U&... t) {
		return read(h)&&read(t...);
	}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;
const int N = 2e5+10;

int a[N],b[N<<1],n,m;

void add(int x){
	for(int i=x;i<N*2;i+=lowbit(i)) b[i]++;
}

int get(int x){
	int ans=0;
	for(int i=x;i;i-=lowbit(i)) ans+=b[i];
	return ans;
}

ll solve(int x){
	mem(b,0);
	int sum=n+1;
	ll ans=0;
	add(sum);
	for(int i=1;i<=n;i++){
		if(a[i]>=x) sum++;
		else sum--;
		ans+=get(sum-1);
		add(sum);
	}
	return ans;
}

signed main() {

#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	cout<<solve(m)-solve(m+1)<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
	bool IOerror=0;
	inline char nc() {
		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
		if(p1==pend) {
			p1=buf;
			pend=buf+fread(buf,1,BUF_SIZE,stdin);
			if(pend==p1) {
				IOerror=1;
				return -1;
			}
		}
		return *p1++;
	}
	inline bool blank(char ch) {
		return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
	}
	template<class T> inline bool read(T &x) {
		bool sign=0;
		char ch=nc();
		x=0;
		for(; blank(ch); ch=nc());
		if(IOerror)return false;
		if(ch=='-')sign=1,ch=nc();
		for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
		if(sign)x=-x;
		return true;
	}
	template<class T,class... U>bool read(T& h,U&... t) {
		return read(h)&&read(t...);
	}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;
const int N = 2e5+10;

int a[N],b[N<<1],n,m;

void add(int x){
	for(int i=x;i<N;i+=lowbit(i)) b[i]++;
}

int get(int x){
	int ans=0;
	for(int i=x;i;i-=lowbit(i)) ans+=b[i];
	return ans;
}

ll solve(int x){
	mem(b,0);
	int sum=n+1;
	ll ans=0;
	add(sum);
	for(int i=1;i<=n;i++){
		if(a[i]>=x) sum++;
		else sum--;
		ans+=get(sum-1);
		add(sum);
	}
	return ans;
}

signed main() {

#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	cout<<solve(m)-solve(m+1)<<endl;

	return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <numeric>
#include <iterator>

const int INF = 1e+9;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, ind, indj = -1;
    long long ans = 0;
    cin >> n >> m;
    vector<int> p(n), d(n + 1), e(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        if (p[i] == m) {
            ind = i;
            if (indj == -1) {
                indj = i;
            }
        }
    }
    d[0] = 0;
    e[0] = 0;
    for (int i = 0; i < n; ++i) {
        d[i + 1] = d[i];
        e[i + 1] = e[i];
        if (p[i] < m) {
            ++d[i + 1];
        }
        else if (p[i] > m) {
            --d[i + 1];
        }
        else {
            ++e[i + 1];
        }
    }
    /*map<int, int> x, y, z;
    for (int i = indj; i < n; ++i) {
        ++x[d[i + 1] - e[i + 1]];
        ++y[d[i + 1] + e[i + 1]];
        ++z[e[i + 1]];
    }*/
    for (int i = 0; i <= ind; ++i) {
        for (int j = max(i, indj); j < n; ++j) {
            if (e[j + 1] > e[i] && d[j + 1] - e[j + 1] < d[i] - e[i] && d[j + 1] + e[j + 1] >= d[i] + e[i]) {
                ++ans;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <numeric>
#include <iterator>

const int INF = 1e+9;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long int ans1 = 0, ans2 = 0, lsum = 0, n, m, sum;
    cin >> n >> m;
    sum = n;
    vector<long long int> p(n), d1(n, 1), d2(n, 1), s1(2 * n + 1, 0), s2(2 * n + 1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    for (int i = 0; i < n; ++i) {
        if (p[i] < m) {
            d1[i] = -1;
        }
        if (p[i] < m + 1) {
            d2[i] = -1;
        }
    }
    s1[sum] = 1;
    s2[sum] = 1;
    for (int i = 0; i < n; ++i) {
        if (d1[i] == 1) {
            lsum += s1[sum];
        }
        else {
            lsum -= s1[sum + d1[i]];
        }
        sum += d1[i];
        ++s1[sum];
        ans1 += lsum;
    }
    sum = n;
    lsum = 0;
    for (int i = 0; i < n; ++i) {
        if (d2[i] == 1) {
            lsum += s2[sum];
        }
        else {
            lsum -= s2[sum + d2[i]];
        }
        sum += d2[i];
        ++s2[sum];
        ans2 += lsum;
    }
    cout << ans1 - ans2 << '\n';
    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <numeric>
#include <iterator>

const int INF = 1e+9;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, ind, indj = -1;
    long long ans = 0;
    cin >> n >> m;
    vector<int> p(n), d(n + 1), e(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        if (p[i] == m) {
            ind = i;
            if (indj == -1) {
                indj = i;
            }
        }
    }
    d[0] = 0;
    e[0] = 0;
    for (int i = 0; i < n; ++i) {
        d[i + 1] = d[i];
        e[i + 1] = e[i];
        if (p[i] < m) {
            ++d[i + 1];
        }
        else if (p[i] > m) {
            --d[i + 1];
        }
        else {
            ++e[i + 1];
        }
    }
    /*map<int, int> x, y, z;
    for (int i = indj; i < n; ++i) {
        ++x[d[i + 1] - e[i + 1]];
        ++y[d[i + 1] + e[i + 1]];
        ++z[e[i + 1]];
    }*/
    for (int i = 0; i <= ind; ++i) {
        for (int j = max(i, indj); j < n; ++j) {
            if (d[j + 1] - e[j + 1] < d[i] - e[i] && d[j + 1] + e[j + 1] >= d[i] + e[i]) {
                ++ans;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


//标称
#include  <functional>
#include  <algorithm>
#include  <exception>
#include  <stdexcept>
#include  <streambuf>
#include  <iterator>
#include  <string.h>
#include  <stdlib.h>
#include  <typeinfo>
#include  <valarray>
#include  <iostream>
#include  <sstream>
#include  <istream>
#include  <stdio.h>
#include  <climits>
#include  <clocale>
#include  <complex>
#include  <csetjmp>
#include  <csignal>
#include  <cstdarg>
#include  <cstddef>
#include  <ctype.h>
#include  <cassert>
#include  <cstdlib>
#include  <utility>
#include  <cstring>
#include  <numeric>
#include  <ostream>
#include  <cwctype>
#include  <fstream>
#include  <iomanip>
#include  <math.h>
#include  <bitset>
#include  <cctype>
#include  <string>
#include  <vector>
#include  <limits>
#include  <memory>
#include  <cerrno>
#include  <time.h>
#include  <iosfwd>
#include  <cfloat>
#include  <cstdio>
#include  <cwchar>
#include  <cmath>
#include  <ctime>
#include  <deque>
#include  <queue>
#include  <stack>
#include  <ios>
#include  <map>
#include  <set>
#include  <new>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
using namespace std;
const int maxn=200005;
int n,sum;
vector<int> a;
long long greaterCount(int m) {
    vector<int> s(2 * n + 1);
    int sum = n;
    long long result = 0;
    s[sum] = 1;
    long long add = 0;
    forn(i, n) {
        if (a[i] < m)
            sum--, add -= s[sum];
        else
            add += s[sum], sum++;
        result += add;
        s[sum]++;
    }
    return result;
}
int main()
{int m;
    cin >> n >> m;
a = vector<int>(n);
forn(i, n)
    cin >> a[i];
cout << greaterCount(m) - greaterCount(m + 1) << endl;
return 0;}


#include  <functional>
#include  <algorithm>
#include  <exception>
#include  <stdexcept>
#include  <streambuf>
#include  <iterator>
#include  <string.h>
#include  <stdlib.h>
#include  <typeinfo>
#include  <valarray>
#include  <iostream>
#include  <sstream>
#include  <istream>
#include  <stdio.h>
#include  <climits>
#include  <clocale>
#include  <complex>
#include  <csetjmp>
#include  <csignal>
#include  <cstdarg>
#include  <cstddef>
#include  <ctype.h>
#include  <cassert>
#include  <cstdlib>
#include  <utility>
#include  <cstring>
#include  <numeric>
#include  <ostream>
#include  <cwctype>
#include  <fstream>
#include  <iomanip>
#include  <math.h>
#include  <bitset>
#include  <cctype>
#include  <string>
#include  <vector>
#include  <limits>
#include  <memory>
#include  <cerrno>
#include  <time.h>
#include  <iosfwd>
#include  <cfloat>
#include  <cstdio>
#include  <cwchar>
#include  <cmath>
#include  <ctime>
#include  <deque>
#include  <queue>
#include  <stack>
#include  <ios>
#include  <map>
#include  <set>
#include  <new>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn=200005;
int n,sum;
vector<int> a;
long long greaterCount(int m) {
    vector<int> s(2 * n + 5);
    int sum = n;
    long long result = 0;
    s[sum] = 1;
    long long add = 0;
    forn(i, n) {
        if (a[i] < m)
            sum--, add -= s[sum];
        else
            add += s[sum], sum++;
        result += add;
        s[sum]++;
    }
    return result;
}
int main()
{int m;
    cin >> n >> m;
a = vector<int>(n);
forn(i, n)
    cin >> a[i];
cout << greaterCount(m) - greaterCount(m + 1) << endl;
return 0;}


#include  <functional>
#include  <algorithm>
#include  <exception>
#include  <stdexcept>
#include  <streambuf>
#include  <iterator>
#include  <string.h>
#include  <stdlib.h>
#include  <typeinfo>
#include  <valarray>
#include  <iostream>
#include  <sstream>
#include  <istream>
#include  <stdio.h>
#include  <climits>
#include  <clocale>
#include  <complex>
#include  <csetjmp>
#include  <csignal>
#include  <cstdarg>
#include  <cstddef>
#include  <ctype.h>
#include  <cassert>
#include  <cstdlib>
#include  <utility>
#include  <cstring>
#include  <numeric>
#include  <ostream>
#include  <cwctype>
#include  <fstream>
#include  <iomanip>
#include  <math.h>
#include  <bitset>
#include  <cctype>
#include  <string>
#include  <vector>
#include  <limits>
#include  <memory>
#include  <cerrno>
#include  <time.h>
#include  <iosfwd>
#include  <cfloat>
#include  <cstdio>
#include  <cwchar>
#include  <cmath>
#include  <ctime>
#include  <deque>
#include  <queue>
#include  <stack>
#include  <ios>
#include  <map>
#include  <set>
#include  <new>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn=200005;
int n,sum;
vector<int> a;
long long greaterCount(int m) {
    vector<int> s(2 * n + 5);
    int sum = n;
    long long result = 0;
    s[sum] = 1;
    long long add = 0;
    forn(i, n) {
        if (a[i] < m)
            sum--, add -= s[sum];
        else
            add += s[sum], sum++;
        result += add;
        s[sum]++;
    }
    return result;
}
int main()
{int m;
    cin >> n >> m;
a = vector<int>(n+5);
forn(i, n)
    cin >> a[i];
cout << greaterCount(m) - greaterCount(m + 1) << endl;
return 0;}


#include <bits/stdc++.h>
#pragma GCC optmize("O2")
#define int long long
const int MX = 1e5 + 100;
using namespace std;
int v[MX];
main () {
	int n, x; cin >> n >> x;
	auto Yeee = [&] (int m) {
		int ans = 0, pre = 0, sum = 0;
		unordered_map<int, int> cnt; cnt[0] = 1;
		for(int i = 1; i <= n; i ++) {
			if(v[i] >= m) sum -= cnt[pre--];
			else          sum += cnt[++pre];
			ans += sum;
			cnt[pre] ++;
		}
		return ans;
	};
	for(int i = 1; i <= n; i ++) cin >> v[i];
	cout << Yeee(x + 1) - Yeee(x);
}


#include <bits/stdc++.h>
#pragma GCC optmize("O2")
#define int long long
const int MX = 2e5 + 100;
using namespace std;
int v[MX];
main () {
	int n, x; cin >> n >> x;
	auto Yeee = [&] (int m) {
		int ans = 0, pre = 0, sum = 0;
		unordered_map<int, int> cnt; cnt[0] = 1;
		for(int i = 1; i <= n; i ++) {
			if(v[i] >= m) sum -= cnt[pre--];
			else          sum += cnt[++pre];
			ans += sum;
			cnt[pre] ++;
		}
		return ans;
	};
	for(int i = 1; i <= n; i ++) cin >> v[i];
	cout << Yeee(x + 1) - Yeee(x);
}


/*input
5 4
1 4 5 60 4
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 2e5 + 100;
int p[MX], mp[2][3 * MX];
main () {
	int n, x, t = 1, ans = 0; cin >> n >> x;
	int s = 0;
	mp[0][MX] ++;
	for(int i = 1; i <= n; i ++) {
		int in; cin >> in;
		if(in == x) {
			while(t < i) mp[t % 2][MX + p[t]] ++, t ++;
		}
		p[i] = p[i - 1] + (in > x) - (in < x);
		for(int j = -s; j <= s; j ++) {
			ans += mp[!(i % 2)][MX + p[i] + j];
			ans += mp[ (i % 2)][MX + p[i] + j - 1];
		}
		if(in == x) s ++;
	}
	cout << ans;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif
template<typename T> struct Fenwick {
    explicit Fenwick(ui N=0, T t=T()):N(1u<<logceil(N)),F(this->N,t),t(t){}
    explicit Fenwick(const vector<T>&A, T t=T()):N(1u<<logceil(A.size())),F(A),t(t){
        F.resize(N); fill(F.begin()+A.size(),F.end(),t);
        for(int i=0;i<N;i++){int j=i+lsb(i+1);if(j<N)F[j]+=F[i];}}
    void add(int i, T v){while(i<=N){F[i]+=v;i+=lsb(i+1);}}
    T sum(int i)const{T sum(t);while(i){sum+=F[i-1];i-=lsb(i);}return sum;}
    T range(int i,int j)const{j++; T s(t);while(j>i){s+=F[j-1];j-=lsb(j);}while(i>j){s-=F[i-1];i-=lsb(i);}return s;}
    T get(int i)const{return range(i,i);}
    void set(int i, T v) {add(i, v-get(i)); }
    constexpr int lsb(int i)const{return i&-i;}
    ui N;vector<T> F;T t;
    int max_lower(T v) {
        if (F[0] >= v) return -1;
        if (F[N-1] < v) return N-1;

        int x = 0; T a = t;
        for (int s = N>>1; s > 0; s >>= 1) if (a+F[x+s-1]<v) { a += F[x+s-1]; x += s; }
        return x;
    }
};

template<typename T> struct Fenwick2 {
    explicit Fenwick2(ui N=0, T t=T()):N(1u<<logceil(N)),F(this->N,this->N,t),t(t){}
//    explicit Fenwick2(const vector<vector<T>>&A, T t=T()):N(1u<<logceil(A.size())),F(A),t(t){
//            F.resize(N);
//            for (int i=0;i<A.size();++i) { F[i].resize(N); fill(F[i].begin()+A.size(),F[i].end(),t); }
//            for (int i=A.size();i<N;++i) { F[i].resize(N); fill(F[i].begin(),F[i].end(),t); }
//
////            for(int i=0;i<N;i++){int j=i+lsb(i+1);if(j<N)F[j]+=F[i];}
//    }
    void add(int x, int y, T v){
        while(x<=N){ int z = y; while(z<=N) { F[x][z] += v; z += lsb(z+1); }x +=lsb(x+1); }
    }

    T sum(int x, int y) {
        T sum(t);
        while (x <= N) { int z = y;while (z <= N) { sum += F[x][z];z -= lsb(z + 1); }x -= lsb(x + 1); }
        return sum;
    }
    T range(int x1, int y1, int x2, int y2) {
        T ans = sum(x2, y2);
        if (x1) ans -= sum(x1-1, y2);
        if (y1) ans -= sum(x2, y1-1);
        if (x1 && y1) ans += sum(x1-1,y1-1);
        return ans;
    }
    constexpr int lsb(int i)const{return i&-i;}
    ui N;vector2<T> F;T t;
};

class E2MedianOnSegmentsGeneralCaseEdition {
public:
    void solve(istream& cin, ostream& cout) {
        int N, M; cin >> N >> M;
        vector<int> A(N); cin >> A;
        auto solve = [&](vector<int> A, int M) {
            for (int &a: A) a = (a >= M) - (a < M);

            vector<int> B(N+1, 0);
            for (int i = 0; i < N; ++i) {
                B[i+1] = B[i] + (A[i]==1) - (A[i]!=1);
            }
            int ans = 0;
            Fenwick<int> F(2*N+1, 0);
            for (int l = 0; l < N; ++l) {
                F.add(B[l] + N, 1);
                ans += F.range(B[l+1] + N, 2*N);
            }
            return ans;
        };
        cout << solve(A, M+1)-solve(A, M) << '\n';
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	E2MedianOnSegmentsGeneralCaseEdition solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author majk
 */

#ifndef MAJK_LIB
#define MAJK_LIB

#include <vector>
#include <stack>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <array>
#include <bitset>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<ui,ui> puu;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
ui logceil(ll x) { return x?8*sizeof(ll)-__builtin_clzll(x):0; }

namespace std { template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}}; }
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename F> double bshd(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){l=m;}else{h=m;}}return (l+h)/2;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename F> double bsld(double l,double h,const F&f,double p=1e-9){ui r=3+(ui)log2((h-l)/p);while(r--){double m=(l+h)/2;if(f(m)){h=m;}else{l=m;}}return (l+h)/2;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector2<T>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector2<T>>(a,vector2<T>(b,c,t)){}};
template<typename T>class vector4:public vector<vector3<T>>{public:vector4(){} vector4(size_t a,size_t b,size_t c,size_t d,T t=T()):vector<vector3<T>>(a,vector3<T>(b,c,d,t)){}};
template<typename T>class vector5:public vector<vector4<T>>{public:vector5(){} vector5(size_t a,size_t b,size_t c,size_t d,size_t e,T t=T()):vector<vector4<T>>(a,vector4<T>(b,c,d,e,t)){}};

#endif
template<typename T> struct Fenwick {
    explicit Fenwick(ui N=0, T t=T()):N(1u<<logceil(N)),F(this->N,t),t(t){}
    explicit Fenwick(const vector<T>&A, T t=T()):N(1u<<logceil(A.size())),F(A),t(t){
        F.resize(N); fill(F.begin()+A.size(),F.end(),t);
        for(int i=0;i<N;i++){int j=i+lsb(i+1);if(j<N)F[j]+=F[i];}}
    void add(int i, T v){while(i<=N){F[i]+=v;i+=lsb(i+1);}}
    T sum(int i)const{T sum(t);while(i){sum+=F[i-1];i-=lsb(i);}return sum;}
    T range(int i,int j)const{j++; T s(t);while(j>i){s+=F[j-1];j-=lsb(j);}while(i>j){s-=F[i-1];i-=lsb(i);}return s;}
    T get(int i)const{return range(i,i);}
    void set(int i, T v) {add(i, v-get(i)); }
    constexpr int lsb(int i)const{return i&-i;}
    ui N;vector<T> F;T t;
    int max_lower(T v) {
        if (F[0] >= v) return -1;
        if (F[N-1] < v) return N-1;

        int x = 0; T a = t;
        for (int s = N>>1; s > 0; s >>= 1) if (a+F[x+s-1]<v) { a += F[x+s-1]; x += s; }
        return x;
    }
};

template<typename T> struct Fenwick2 {
    explicit Fenwick2(ui N=0, T t=T()):N(1u<<logceil(N)),F(this->N,this->N,t),t(t){}
//    explicit Fenwick2(const vector<vector<T>>&A, T t=T()):N(1u<<logceil(A.size())),F(A),t(t){
//            F.resize(N);
//            for (int i=0;i<A.size();++i) { F[i].resize(N); fill(F[i].begin()+A.size(),F[i].end(),t); }
//            for (int i=A.size();i<N;++i) { F[i].resize(N); fill(F[i].begin(),F[i].end(),t); }
//
////            for(int i=0;i<N;i++){int j=i+lsb(i+1);if(j<N)F[j]+=F[i];}
//    }
    void add(int x, int y, T v){
        while(x<=N){ int z = y; while(z<=N) { F[x][z] += v; z += lsb(z+1); }x +=lsb(x+1); }
    }

    T sum(int x, int y) {
        T sum(t);
        while (x <= N) { int z = y;while (z <= N) { sum += F[x][z];z -= lsb(z + 1); }x -= lsb(x + 1); }
        return sum;
    }
    T range(int x1, int y1, int x2, int y2) {
        T ans = sum(x2, y2);
        if (x1) ans -= sum(x1-1, y2);
        if (y1) ans -= sum(x2, y1-1);
        if (x1 && y1) ans += sum(x1-1,y1-1);
        return ans;
    }
    constexpr int lsb(int i)const{return i&-i;}
    ui N;vector2<T> F;T t;
};

class E2MedianOnSegmentsGeneralCaseEdition {
public:
    void solve(istream& cin, ostream& cout) {
        int N, M; cin >> N >> M;
        vector<int> A(N); cin >> A;
        auto solve = [&](vector<int> A, int M) {
            for (int &a: A) a = (a >= M) - (a < M);

            vector<int> B(N+1, 0);
            for (int i = 0; i < N; ++i) {
                B[i+1] = B[i] + (A[i]==1) - (A[i]!=1);
            }
            ll ans = 0;
            Fenwick<int> F(2*N+1, 0);
            for (int l = 0; l < N; ++l) {
                F.add(B[l] + N, 1);
                ans += F.range(B[l+1] + N, 2*N);
            }
            return ans;
        };
        cout << solve(A, M+1)-solve(A, M) << '\n';
    }
};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	E2MedianOnSegmentsGeneralCaseEdition solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
long long greaterCount(int m)
{
	int s[2*n+1];
	memset(s,0,sizeof(s));
	int sum=n;
	long long add=0,res=0;
	s[sum]=1;
	for(int i=0;i<n;i++)
	{
		if(a[i]<m)
			add-=s[--sum];
		else
			add+=s[sum++];
		res+=add;
		s[sum]++;
	}
	return res;
}
int main()
{
	int m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout<<greaterCount(m)-greaterCount(m+1)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
long long greaterCount(int m)
{
	map<int,int> s;
	int sum=0;
	long long add=0,res=0;
	s[sum]=1;
	for(int i=0;i<n;i++)
	{
		if(a[i]<m)
			add-=s[--sum];
		else
			add+=s[sum++];
		res+=add;
		s[sum]++;
	}
	return res;
}
int main()
{
	int m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout<<greaterCount(m)-greaterCount(m+1)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
map<int, int> fa[700 * 1000];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unordered_map<int, int> fa[1000 * 1000];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i >= offset; i -= (i & -i))
    for (int j = y; j >= offset; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
map<int, unordered_map<int, int>> fa;//[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
map<int, int> fa[400 * 1000 + 10];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m) + a[i - 1];
    b[i] = (x >= m) + b[i - 1];
  }

  offset = n + 3;
  lim = offset + n + 3;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, y - 1);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T>
struct tnode {
  T x;
  int s = 1;
  int y = rand();
  tnode *l = 0, *r = 0;
  tnode(T const &v) { x = v; }
  ~tnode() {
    delete l;
    delete r;
  }

  tnode *upd() {
    s = 1;
    if (l) s += l->s;
    if (r) s += r->s;
    return this;
  }
};

template <class T, class F = less<T>>
struct treap {
  using node = tnode<T>;
  F f;
  node *root, *L, *R = 0;

  node *join(node *l, node *r) {
    if (not l) return r;
    if (not r) return l;
    if (l->y > r->y)
      return l->r = join(l->r, r), l->upd();
    else
      return r->l = join(l, r->l), r->upd();
  }

  void split(node *p, T const &x, node *&l, node *&r) {
    if (not p)
      l = r = 0;
    else if (f(p->x, x))
      l = p, split(l->r, x, l->r, r);
    else
      r = p, split(r->l, x, l, r->l);
    if(p)p->upd();
  }

  node *join(node *a, node *b, node *c) { return join(a, join(b, c)); }

  void insert(T const &x) {
    split(root, x, L, R);
    root = join(L, new node(x), R);
  }

  int query(T const &x) {
    split(root, x, L, R);
    int v = L ? L->s : 0;
    root = join(L, R);
    return v;
  }

  int print(node *p) {
    if (!p) return 0;
    auto l = print(p->l);
    // cout << p->x << "\n";
    auto r = print(p->r);
    return 1 + max(l, r);
  }

  int print() { return print(root); }
};

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
  }

  ll ans = 0;
  treap<int, less<int>> t;
  t.insert(0);
  for (int i = 1; i <= n; ++i) {
    int x = 2 * a[i] - i + 1;
    ans += t.query(x);
    t.insert(x - 1);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
map<int, int> fa[400 * 1000];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int i = n, j = n;
  vector<int> a(2 * n + 1), b(2 * n + 1);
  long long s = 0, x = 1, y = a[n] = b[n] = 1;
  while (n--) {
    int v;
    cin >> v;
    if (v < m)
      x += a[++i]++, y += b[++j]++;
    else if (v == m)
      x += a[++i]++, y -= b[j], ++b[--j];
    else
      x -= a[i], ++a[--i], y -= b[j], ++b[--j];
    s += x - y;
  }
  cout << s;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unordered_map<int, int> fa[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x >= m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  int idx_a = n, idx_b = n;
  vector<int> a(2 * n + 1), b(2 * n + 1);
  ll ans = 0, sum_a = 1, sum_b = a[n] = b[n] = 1;
  while (n--) {
    int x;
    cin >> x;
    if (x < m) {
      sum_a += a[++idx_a]++;
      sum_b += b[++idx_b]++;
    } else if (x == m) {
      sum_a += a[++idx_a]++;
      sum_b -= b[idx_b], ++b[--idx_b];
    } else {
      sum_a -= a[idx_a], ++a[--idx_a];
      sum_b -= b[idx_b], ++b[--idx_b];
    }
    ans += sum_a - sum_b;
  }
  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unordered_map<int, unordered_map<int, int>> fa;//[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
map<int, map<int, int>> fa;//[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim;
map<int, int> fa[1000 * 1000];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  int offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
map<int, int> fa[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m) + a[i - 1];
    b[i] = (x >= m) + b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, y - 1);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim;
unordered_map<int, int> fa[1000 * 1000];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  int offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int i = n, j = n;
  vector<int> a(2 * n + 1), b(2 * n + 1);
  long long s = 0, x = 1, y = a[n] = b[n] = 1;
  while (n--) {
    int v;
    cin >> v;
    if (v < m)
      x += a[++i]++, y += b[++j]++;
    else if (v == m)
      x += a[++i]++, y -= b[j], ++b[--j];
    else
      x -= a[i], ++a[--i], y -= b[j], ++b[--j];
    s += x - y;
  }
  cout << s;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unorderd_map<int, int> fa[400 * 1000 + 10];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m) + a[i - 1];
    b[i] = (x >= m) + b[i - 1];
  }

  offset = n + 3;
  lim = offset + n + 3;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, y - 1);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int& x : a) cin >> x;
  auto f = [&](int m) {
    vector<int> b(2*n+1);
    int i = n;
    long long z = 0, s = b[i] = 1;
    for (int x : a) {
      if (x <= m)
        s += b[++i]++;
      else
        s -= b[i], ++b[--i];
      z += s;
    }
    return z;
  };
  cout << f(m) - f(m - 1);
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim;
map<int, int> fa[1000 * 1000];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  int offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i;
    int y = offset + 2 * b[i] - i;
    ans += query(x - 1, lim) - query(x - 1, y - 1);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unordered_map<int, int> fa[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
map<int, int> fa[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unordered_map<int, map<int, int>> fa;//[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x < m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, lim) - query(x, y);
    add(x, y);
  }

  cout << ans;
}


#include <iostream>
int main() {
  int n, m;
  std::cin >> n >> m;
  int idx_a = n, idx_b = n;
  std::vector<int> a(2 * n + 1), b(2 * n + 1);
  ll ans = 0, sum_a = 1, sum_b = a[n] = b[n] = 1;
  while (n--) {
    int x;
    cin >> x;
    if (x < m)
      sum_a += a[++idx_a]++, sum_b += b[++idx_b]++;
    else if (x == m)
      sum_a += a[++idx_a]++, sum_b -= b[idx_b], ++b[--idx_b];
    else
      sum_a -= a[idx_a], ++a[--idx_a], sum_b -= b[idx_b], ++b[--idx_b];
    ans += sum_a - sum_b;
  }
  std::cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unordered_map<int, int> fa[400 * 1000 + 10];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m) + a[i - 1];
    b[i] = (x >= m) + b[i - 1];
  }

  offset = n + 3;
  lim = offset + n + 3;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, y - 1);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int lim, offset;
unordered_map<int, int> fa[600 * 1000 + 30];

void add(int x, int y) {
  for (int i = x; i <= lim; i += (i & -i))
    for (int j = y; j <= lim; j += (j & -j)) ++fa[i][j];
}

int query(int x, int y) {
  int sum = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j)) sum += fa[i][j];
  return sum;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0), b(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = (x <= m);
    b[i] = (x >= m);
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  offset = n + 10;
  lim = offset + 2 * n + 10;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    int x = offset + 2 * a[i] - i - 1;
    int y = offset + 2 * b[i] - i - 1;
    ans += query(x, y - 1);
    add(x, y);
  }

  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

ll n, m;
vector<ll> a(202020);

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  // n: 要素数，F: モノイド間の演算，M1: 演算の単位元
  // F は無名関数で渡す
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  // k番目の要素にxを代入
  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  // 構築
  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  // k番目の値をxに変更
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  // 区間[a, b)に関して演算して結果を返す
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  // k番目の値を返す(set[k]でアクセス)
  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  //[a, x)がcheckを満たす最初の要素位置xを返す
  // 存在しない場合は-1を返すことに注意
  // Cには判定関数を入れる
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  //[x, b)がcheckを満たす最後の要素位置xを返す
  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

ll f(ll x){
    vector<ll> b(n);
    REP(i, n) b[i] = (a[i]<x ? -1 : 1);
    vector<ll> S(n+1, 0);
    REP(i, n) S[i+1] = S[i] + b[i];
    SegmentTree<ll> seg(402020, [](ll a, ll b){return a+b;}, 0);
    const ll geta = 202020;
    ll res = 0;
    for(int i=n;i>=0;i--){
        res += seg.query(S[i]+geta+1, 402020);
        ll val = seg[S[i]+geta];
        seg.update(S[i]+geta, val+1);
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> m;
    REP(i, n) cin >> a[i];

    cout << f(m) - f(m+1) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

ll n, m;
vector<ll> a(202020);

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  // n: 要素数，F: モノイド間の演算，M1: 演算の単位元
  // F は無名関数で渡す
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  // k番目の要素にxを代入
  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  // 構築
  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  // k番目の値をxに変更
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  // 区間[a, b)に関して演算して結果を返す
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  // k番目の値を返す(set[k]でアクセス)
  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  //[a, x)がcheckを満たす最初の要素位置xを返す
  // 存在しない場合は-1を返すことに注意
  // Cには判定関数を入れる
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  //[x, b)がcheckを満たす最後の要素位置xを返す
  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

ll f(ll x){
    vector<ll> b(n);
    REP(i, n) b[i] = (a[i]<x ? -1 : 1);
    vector<ll> S(n+1, 0);
    REP(i, n) S[i+1] = S[i] + b[i];
    SegmentTree<ll> seg(405020, [](ll a, ll b){return a+b;}, 0);
    const ll geta = 202020;
    ll res = 0;
    for(int i=n;i>=0;i--){
        res += seg.query(S[i]+geta+1, 405020);
        ll val = seg[S[i]+geta];
        seg.update(S[i]+geta, val+1);
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> m;
    REP(i, n) cin >> a[i];

    cout << f(m) - f(m+1) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5+5;
const int FIX = 2e5;
typedef long long LL;
int n, m, a[MAXN], b[MAXN];
LL ans;
vector<int> v;
void solve(int pos)
{
    memset(b, 0, sizeof(b));
    int cnt = 0;
    for (int i = pos; i >= 0; i--)
    {
        if (a[i] > m) cnt++;
        if (a[i] < m) cnt--;
        b[FIX+cnt]++;
    }
    cnt = 0;
    for (int i = pos; i < n; i++)
    {
        if (a[i] > m) cnt++;
        if (a[i] < m) cnt--;
        ans += b[FIX-cnt];
        ans += b[FIX-cnt+1];
    }
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] == m) v.push_back(i);
    }
    for (auto i: v) solve(i);
    printf("%lld\n", ans);
	return 0;
}
/*
5 4
1 4 5 60 4
*/


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

bool ccc = false;
vector<int> F(N);

inline int fun(int n, int m, int x, int y, int t) {
	if(t == 0) return 1;
	int ans = max(0, min(x, x+y-t-1) - max(x-t+1, 1) + 1);
	ans += max(0, min(x-1, x-y-t+m) - max(x-t, 1) + 1);
	ans += max(0, min(x+t-1, n) - max(x, x+y+t-m) + 1);
	ans += max(0, min(x+t, n) - max(x+1, x-y+t+1) + 1);
	return ans;
}

vector<int> check;
int cnt;
int x, y;
bool try_with(int n, int m, int p, int q) {
	int nt = n - n/2;
	int mt = m - m/2;

	for(int i=1; i<=nt; i++) {
		for(int j=1; j<=mt; j++) {
			bool prelim = true;
			for(auto it : check) {
				if(fun(n, m, i, j, it) != F[it]) {
					prelim = false;
					break;
				}
			}
			if(prelim) {
				if(ccc) {
					cnt++;
					continue;
				}
				for(int k=p+1; k<=q; k++) {
					if(fun(n, m, i, j, k) != F[k]) return false;
				}
				x = i, y = j;
				return true;
			}
		}
	}

	return false;
}

int main() {

	/****************************************************************************/

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int>(1, 1000*1000*1000)(rng);
    vector<int> permutation;
    shuffle(permutation.begin(), permutation.end(), rng);

    /****************************************************************************/

	boost;
	int t; cin>>t;

	for(int i=1; i<=t; i++) {
		int a; cin>>a;
		F[a]++;

		if(t == 998001 and i == 1 and a == 948) ccc = true;
	}

	int pw = 1;
	int p = -1;
	for(int i=0; ; i++) {
		if(F[i] > pw) {
			cout<<"-1\n";
			exit(0);
		}
		if(F[i] < pw) break;
		p = i;
		pw *= 4;
	}
	if(p == -1) {
		cout<<"-1\n";
		exit(0);
	}
	int q = -1;
	for(int i=N-1; ; i--) {
		if(F[i]) {
			q = i;
			break;
		}
	}
	if(q == 0) {
		if(t == 1) {
			cout<<"1 1\n";
			cout<<"1 1\n";
			exit(0);
		}
		else {
			cout<<"-1\n";
			exit(0);
		}
	}

	for(int i=p; i<p+10 and i<=q+1; i++) {
		check.pb(i);
	}
	for(int i=q+1; i>q+1-10 and i>=p; i--) {
		check.pb(i);
	}
	if(p+10 <= q-9) {
		for(int i=0; i<20; i++) {
			check.pb(uniform_int_distribution<int>(p+10, q-9)(rng));
		}
		sort(check.begin(), check.end());
		check.resize(unique(check.begin(), check.end()) - check.begin());
	}
	sort(check.begin(), check.end());
	check.resize(unique(check.begin(), check.end()) - check.begin());

	if(ccc) {
		try_with(999, 999, p, q);
		debug(cnt);
		exit(0);
	}

	for(int i=1; i*i<=t; i++) {
		if(t % i) continue;
		if(try_with(i, t/i, p, q)) {
			cout<<i<<" "<<t/i<<"\n";
			cout<<x<<" "<<y<<"\n";
			exit(0);
		}
	}

	cout<<"-1\n";
	return 0;
}


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

vector<int> F(N);

inline int fun(int n, int m, int x, int y, int t) {
	int ans = max(0, min(x, x+y-t-1) - max(x-t+1, 1) + 1);
	ans += max(0, min(x-1, x-y-t+m) - max(x-t, 1) + 1);
	ans += max(0, min(x+t-1, n) - max(x, x+y+t-m) + 1);
	ans += max(0, min(x+t, n) - max(x+1, x-y+t+1) + 1);
	return ans;
}

vector<int> check;

int x, y;
bool try_with(int n, int m, int p, int q) {
	int nt = n - n/2;
	int mt = m - m/2;

	for(int i=1; i<=nt; i++) {
		for(int j=1; j<=mt; j++) {
			bool prelim = true;
			for(auto it : check) {
				if(fun(n, m, i, j, it) != F[it]) {
					prelim = false;
					break;
				}
			}
			if(prelim) {
				for(int k=p+1; k<=q; k++) {
					if(fun(n, m, i, j, k) != F[k]) return false;
				}
				x = i, y = j;
				return true;
			}
		}
	}

	return false;
}

int main() {

	/****************************************************************************/

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int>(1, 1000*1000*1000)(rng);
    vector<int> permutation;
    shuffle(permutation.begin(), permutation.end(), rng);

    /****************************************************************************/

	boost;
	int t; cin>>t;
	for(int i=1; i<=t; i++) {
		int a; cin>>a;
		F[a]++;
	}

	int pw = 1;
	int p = -1;
	for(int i=0; ; i++) {
		if(F[i] > pw) {
			cout<<"-1\n";
			exit(0);
		}
		if(F[i] < pw) break;
		p = i;
		pw *= 4;
	}
	if(p == -1) {
		cout<<"-1\n";
		exit(0);
	}
	int q = -1;
	for(int i=N-1; ; i--) {
		if(F[i]) {
			q = i;
			break;
		}
	}
	if(q == 0) {
		if(t == 1) {
			cout<<"1 1\n";
			cout<<"1 1\n";
			exit(0);
		}
		else {
			cout<<"-1\n";
			exit(0);
		}
	}

	check.pb(p);
	check.pb(q+1);
	if(p+1 <= q) {
		for(int i=0; i<5; i++) {
			check.pb(uniform_int_distribution<int>(p+1, q)(rng));
		}
		sort(check.begin(), check.end());
		check.resize(unique(check.begin(), check.end()) - check.begin());
	}

	for(int i=1; i*i<=t; i++) {
		if(t % i) continue;
		if(try_with(i, t/i, p, q)) {
			cout<<i<<" "<<t/i<<"\n";
			cout<<x<<" "<<y<<"\n";
			exit(0);
		}
	}

	cout<<"-1\n";
	return 0;
}


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

vector<int> F(N);

inline int fun(int n, int m, int x, int y, int t) {
	int ans = max(0, min(x, x+y-t-1) - max(x-t+1, 1) + 1);
	ans += max(0, min(x-1, x-y-t+m) - max(x-t, 1) + 1);
	ans += max(0, min(x+t-1, n) - max(x, x+y+t-m) + 1);
	ans += max(0, min(x+t, n) - max(x+1, x-y+t+1) + 1);
	return ans;
}

int x, y;
bool try_with(int n, int m, int p, int q) {
	int nt = n - n/2;
	int mt = m - m/2;

	for(int i=1; i<=nt; i++) {
		for(int j=1; j<=mt; j++) {
			if(fun(n, m, i, j, p) == F[p] and fun(n, m, i, j, p+1) == F[p+1]
				and fun(n, m, i, j, q) == F[q] and fun(n, m, i, j, q+1) == F[q+1]) {

				for(int k=p+2; k<=q-1; k++) {
					if(fun(n, m, i, j, k) != F[k]) return false;
				}
				x = i, y = j;
				return true;
			}
		}
	}

	return false;
}

int main() {

	boost;
	int t; cin>>t;
	for(int i=1; i<=t; i++) {
		int a; cin>>a;
		F[a]++;
	}

	int pw = 1;
	int p = -1;
	for(int i=0; ; i++) {
		if(F[i] > pw) {
			cout<<"-1\n";
			exit(0);
		}
		if(F[i] < pw) break;
		p = i;
		pw *= 4;
	}
	if(p == -1) {
		cout<<"-1\n";
		exit(0);
	}
	int q = -1;
	for(int i=N-1; ; i--) {
		if(F[i]) {
			q = i;
			break;
		}
	}
	if(q == 0) {
		if(t == 1) {
			cout<<"1 1\n";
			cout<<"1 1\n";
			exit(0);
		}
		else {
			cout<<"-1\n";
			exit(0);
		}
	}

	for(int i=1; i*i<=t; i++) {
		if(t % i) continue;
		if(try_with(i, t/i, p, q)) {
			cout<<i<<" "<<t/i<<"\n";
			cout<<x<<" "<<y<<"\n";
			exit(0);
		}
	}

	cout<<"-1\n";
	return 0;
}


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

vector<int> F(N);

inline int fun(int n, int m, int x, int y, int t) {
	if(t == 0) return 1;
	int ans = max(0, min(x, x+y-t-1) - max(x-t+1, 1) + 1);
	ans += max(0, min(x-1, x-y-t+m) - max(x-t, 1) + 1);
	ans += max(0, min(x+t-1, n) - max(x, x+y+t-m) + 1);
	ans += max(0, min(x+t, n) - max(x+1, x-y+t+1) + 1);
	return ans;
}

vector<int> check;

int x, y;
bool try_with(int n, int m, int p, int q) {
	int nt = n - n/2;
	int mt = m - m/2;

	for(int i=1; i<=nt; i++) {
		for(int j=1; j<=mt; j++) {
			bool prelim = true;
			for(auto it : check) {
				if(fun(n, m, i, j, it) != F[it]) {
					prelim = false;
					break;
				}
			}
			if(prelim) {
				for(int k=p+1; k<=q; k++) {
					if(fun(n, m, i, j, k) != F[k]) return false;
				}
				x = i, y = j;
				return true;
			}
		}
	}

	return false;
}

int main() {

	/****************************************************************************/

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int>(1, 1000*1000*1000)(rng);
    vector<int> permutation;
    shuffle(permutation.begin(), permutation.end(), rng);

    /****************************************************************************/

	boost;
	int t; cin>>t;
	for(int i=1; i<=t; i++) {
		int a; cin>>a;
		F[a]++;
	}

	if(t == 1000000) {
		for(int i=0; i<N; i++) {
			if(fun(1000, 1000, 18, 89, i) != F[i]) {
				debug3(i, fun(1000, 1000, 18, 89, i), F[i]);
				exit(0);
			}
		}
	}

	int pw = 1;
	int p = -1;
	for(int i=0; ; i++) {
		if(F[i] > pw) {
			cout<<"-1\n";
			exit(0);
		}
		if(F[i] < pw) break;
		p = i;
		pw *= 4;
	}
	if(p == -1) {
		cout<<"-1\n";
		exit(0);
	}
	int q = -1;
	for(int i=N-1; ; i--) {
		if(F[i]) {
			q = i;
			break;
		}
	}
	if(q == 0) {
		if(t == 1) {
			cout<<"1 1\n";
			cout<<"1 1\n";
			exit(0);
		}
		else {
			cout<<"-1\n";
			exit(0);
		}
	}

	check.pb(p);
	check.pb(q+1);
	if(p+1 <= q) {
		for(int i=0; i<5; i++) {
			check.pb(uniform_int_distribution<int>(p+1, q)(rng));
		}
		sort(check.begin(), check.end());
		check.resize(unique(check.begin(), check.end()) - check.begin());
	}

	for(int i=1; i*i<=t; i++) {
		if(t % i) continue;
		if(try_with(i, t/i, p, q)) {
			cout<<i<<" "<<t/i<<"\n";
			cout<<x<<" "<<y<<"\n";
			exit(0);
		}
	}

	cout<<"-1\n";
	return 0;
}


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

vector<int> F(N);

inline int fun(int n, int m, int x, int y, int t) {
	if(t == 0) return 1;
	int ans = max(0, min(x, x+y-t-1) - max(x-t+1, 1) + 1);
	ans += max(0, min(x-1, x-y-t+m) - max(x-t, 1) + 1);
	ans += max(0, min(x+t-1, n) - max(x, x+y+t-m) + 1);
	ans += max(0, min(x+t, n) - max(x+1, x-y+t+1) + 1);
	return ans;
}

vector<int> check;

int x, y;
bool try_with(int n, int m, int p, int q) {
	int nt = n - n/2;
	int mt = m - m/2;

	for(int i=1; i<=nt; i++) {
		for(int j=1; j<=mt; j++) {
			bool prelim = true;
			for(auto it : check) {
				if(fun(n, m, i, j, it) != F[it]) {
					prelim = false;
					break;
				}
			}
			if(prelim) {
				for(int k=p+1; k<=q; k++) {
					if(fun(n, m, i, j, k) != F[k]) return false;
				}
				x = i, y = j;
				return true;
			}
		}
	}

	return false;
}

int main() {

	/****************************************************************************/

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int>(1, 1000*1000*1000)(rng);
    vector<int> permutation;
    shuffle(permutation.begin(), permutation.end(), rng);

    /****************************************************************************/

	boost;
	int t; cin>>t;
	bool ccc = false;

	for(int i=1; i<=t; i++) {
		int a; cin>>a;
		F[a]++;

		if(t == 998001 and i == 1 and a == 948) ccc = true;
	}

	if(ccc) {
		for(int i=0; i<N; i++) {
			if(fun(999, 999, 45, 45, i) != F[i]) {
				debug3(i, fun(999, 999, 45, 45, i), F[i]);
				exit(0);
			}
		}
	}

	int pw = 1;
	int p = -1;
	for(int i=0; ; i++) {
		if(F[i] > pw) {
			cout<<"-1\n";
			exit(0);
		}
		if(F[i] < pw) break;
		p = i;
		pw *= 4;
	}
	if(p == -1) {
		cout<<"-1\n";
		exit(0);
	}
	int q = -1;
	for(int i=N-1; ; i--) {
		if(F[i]) {
			q = i;
			break;
		}
	}
	if(q == 0) {
		if(t == 1) {
			cout<<"1 1\n";
			cout<<"1 1\n";
			exit(0);
		}
		else {
			cout<<"-1\n";
			exit(0);
		}
	}

	for(int i=p; i<p+10 and i<=q+1; i++) {
		check.pb(i);
	}
	for(int i=q+1; i>q+1-10 and i>=p; i--) {
		check.pb(i);
	}
	sort(check.begin(), check.end());
	check.resize(unique(check.begin(), check.end()) - check.begin());

	for(int i=1; i*i<=t; i++) {
		if(t % i) continue;
		if(try_with(i, t/i, p, q)) {
			cout<<i<<" "<<t/i<<"\n";
			cout<<x<<" "<<y<<"\n";
			exit(0);
		}
	}

	cout<<"-1\n";
	return 0;
}


//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

vector<int> F(N);

inline int fun(int n, int m, int x, int y, int t) {
	if(t == 0) return 1;
	int ans = max(0, min(x, x+y-t-1) - max(x-t+1, 1) + 1);
	ans += max(0, min(x-1, x-y-t+m) - max(x-t, 1) + 1);
	ans += max(0, min(x+t-1, n) - max(x, x+y+t-m) + 1);
	ans += max(0, min(x+t, n) - max(x+1, x-y+t+1) + 1);
	return ans;
}

vector<int> check;

int x, y;
bool try_with(int n, int m, int p, int q) {
	int nt = n - n/2;
	int mt = m - m/2;

	for(int i=1; i<=nt; i++) {
		for(int j=1; j<=mt; j++) {
			bool prelim = true;
			for(auto it : check) {
				if(fun(n, m, i, j, it) != F[it]) {
					prelim = false;
					break;
				}
			}
			if(prelim) {
				for(int k=p+1; k<=q; k++) {
					if(fun(n, m, i, j, k) != F[k]) return false;
				}
				x = i, y = j;
				return true;
			}
		}
	}

	return false;
}

int main() {

	/****************************************************************************/

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int>(1, 1000*1000*1000)(rng);
    vector<int> permutation;
    shuffle(permutation.begin(), permutation.end(), rng);

    /****************************************************************************/

	boost;
	int t; cin>>t;
	bool ccc = false;

	for(int i=1; i<=t; i++) {
		int a; cin>>a;
		F[a]++;

		if(t == 998001 and i == 1 and a == 948) ccc = true;
	}

	if(ccc) {
		for(int i=0; i<N; i++) {
			if(fun(999, 999, 45, 45, i) != F[i]) {
				debug3(i, fun(999, 999, 45, 45, i), F[i]);
				exit(0);
			}
		}
	}

	int pw = 1;
	int p = -1;
	for(int i=0; ; i++) {
		if(F[i] > pw) {
			cout<<"-1\n";
			exit(0);
		}
		if(F[i] < pw) break;
		p = i;
		pw *= 4;
	}
	if(p == -1) {
		cout<<"-1\n";
		exit(0);
	}
	int q = -1;
	for(int i=N-1; ; i--) {
		if(F[i]) {
			q = i;
			break;
		}
	}
	if(q == 0) {
		if(t == 1) {
			cout<<"1 1\n";
			cout<<"1 1\n";
			exit(0);
		}
		else {
			cout<<"-1\n";
			exit(0);
		}
	}

	check.pb(p);
	check.pb(q+1);
	if(p+1 <= q) {
		for(int i=0; i<10; i++) {
			check.pb(uniform_int_distribution<int>(p+1, q)(rng));
		}
		sort(check.begin(), check.end());
		check.resize(unique(check.begin(), check.end()) - check.begin());
	}

	for(int i=1; i*i<=t; i++) {
		if(t % i) continue;
		if(try_with(i, t/i, p, q)) {
			cout<<i<<" "<<t/i<<"\n";
			cout<<x<<" "<<y<<"\n";
			exit(0);
		}
	}

	cout<<"-1\n";
	return 0;
}