#include "bits/stdc++.h" #include using namespace std; using ll =long long; using dd =double; using pll =pair; using tll =tuple; using vll =vector; using vdd =vector
; using vpll =vector; using vtll =vector; using vvll =vector; using vvdd =vector; using vvpll =vector; using vvtll =vector; using vvvll =vector; using vvvdd=vector; using vvvpll =vector; using vvvtll =vector; using vvvvll=vector;using vvvvdd=vector;using vvvvpll=vector;using vvvvtll=vector; constexpr ll INF = 1LL << 60; constexpr dd EPS = 1e-11; constexpr dd PI = 3.1415926535897932; //cin,cout高速化のおまじない+桁数指定 struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(std::numeric_limits::max_digits10); } } fast; #define REPS(i, S, E) for (ll i = (S); i <= (E); i++) #define rep(i, S, E) for (ll i = (S); i <= (E); i++) #define REP(i, N) REPS(i, 0, (N)-1) #define DEPS(i, S, E) for (ll i = (E); i >= (S); i--) #define dep(i, E, S) for (ll i = (E); i >= (S); i--) #define DEP(i, N) DEPS(i, 0, (N)-1) #define EACH(e, v) for (auto&& e : v) #define each(e, v) for (auto&& e : v) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; } template inline T MaxE(vector&v,ll S,ll E){T m=v[S]; REPS(i,S,E)chmax(m,v[i]); return m;}//v[S]~v[E]の最大値 template inline T MinE(vector&v,ll S,ll E){T m=v[S]; REPS(i,S,E)chmin(m,v[i]); return m;}//v[S]~v[E]の最小値 template inline T MaxE(vector &v, ll N) { return MaxE(v, 0, N - 1); } //先頭N個中の最大値 template inline T MinE(vector &v, ll N) { return MinE(v, 0, N - 1); } template inline T MaxE(vector &v) { return MaxE(v, (ll)v.size()); } template inline T MinE(vector &v) { return MinE(v, (ll)v.size()); } template inline ll MaxI(vector&v,ll S,ll E){ll m=S; REPS(i,S,E){if(v[i]>v[m])m=i;} return m;} template inline ll MinI(vector&v,ll S,ll E){ll m=S; REPS(i,S,E){if(v[i] inline ll MaxI(vector &v, ll N) { return MaxI(v, 0, N - 1); } template inline ll MinI(vector &v, ll N) { return MinI(v, 0, N - 1); } template inline ll MaxI(vector &v) { return MaxI(v, (ll)v.size()); } template inline ll MinI(vector &v) { return MinI(v, (ll)v.size()); } template inline T Sum(vector &v, ll S,ll E){ T s=v[S]; REPS(i,S+1,E)s+=v[i]; return s; } template inline T Sum(vector &v, ll N) { return Sum(v, 0, N - 1); } template inline T Sum(vector &v) { return Sum(v, v.size()); } template inline ll sz(T &v){ return (ll)v.size(); } template inline T POW(T a, ll n){ T r=1; for (; n>0; n>>=1, a*=a){ if (n&1)r*=a; } return r; } inline ll POW(int a, ll n){ return POW((ll)a, n); } inline ll CEIL(ll a, ll b){ return (a+b-1)/b; } ll Gcd(ll a, ll b){ return (b==0) ? a : Gcd(b, a%b); } ll Lcm(ll a, ll b){ return a * b / Gcd(a, b); } inline ll MSB(ll a){for(ll o=63,x=-1;;){ll m=(o+x)/2; if(a<(1LL<>=1,i++) if(m&1)v.push_back(i); return move(v);} inline ll BitNum(ll m){ for (ll c=0;; m>>=1){ c+=m&1; if (!m)return c; } } inline ll Bit(ll s, ll i){ return (s>>i)&1; } //sの第ibit i=0-63 [[nodiscard]] inline ll BitOn(ll s, ll i){ return s|(1LL< inline ll FloorIdx(vector &v, T x){ return upper_bound(ALL(v), x)-v.begin()-1; } template inline ll CeilIdx(vector &v, T x){ return lower_bound(ALL(v), x)-v.begin(); } template inline ll UnderNumOf(vector &v, T x){ //sort済vのx以下の個数を得る return upper_bound(v.begin(), v.end(), x) - v.begin(); } template inline ll UnderNumOf(vector &v, T x, Pr pred){ //x以下個数 return upper_bound(v.begin(), v.end(), x, pred) - v.begin(); } template inline ll OverNumOf(vector &v, T x){ //sort済vのx以上の個数を得る return (ll)v.size() - (lower_bound(v.begin(), v.end(), x) - v.begin()); } template inline ll OverNumOf(vector &v, T x, Pr pred){ //x以上の個数 return (ll)v.size() - (lower_bound(v.begin(), v.end(), x, pred) - v.begin()); } template inline vector cinv(ll N){ vector v(N); REP(i, N)cin>>v[i]; return move(v);} template inline vector> cinv2(ll N){ vector> v(N); REP(i,N){cin>>v[i].first>>v[i].second;} return move(v); } template inline vector> cinv3(ll N){ vector> v(N); REP(i,N){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);} return move(v);} template inline vector> cinv4(ll N){ vector> v(N); REP(i,N){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i])>>get<3>(v[i]);} return move(v);} template inline vector> cinvv(ll N, ll M){ vector> vv(N); REP(i, N) vv[i] = cinv(M); return move(vv);} template inline void coutv(vector &v, string d=" "){ ll N=(ll)v.size(); REP(i,N){cout << v[i] << ((i==N-1)?"":d);} cout<<'\n';} template inline void coutv(deque &v, string d=" "){ ll N=(ll)v.size(); REP(i,N){cout << v[i] << ((i==N-1)?"":d);} cout<<'\n';} template void bye(T a){cout << a << '\n'; exit(0);} #if defined(_DEBUG) ll dumpW = 5; template void Dump(vector &v){ REP(i, (ll)v.size()) { cerr << ((i==0)?"[":" ") << setw(dumpW) << v[i]; } cerr << "]"; } void Dump(vll &v){ REP(i, (ll)v.size()) { cerr << ((i==0)?"[":" ") << setw(dumpW); if (v[i] == INF) cerr << "INF"; else if (v[i] == -INF) cerr << "-INF"; else cerr << v[i]; } cerr << "]"; } template void Dump(vector> &v){ ll N=(ll)v.size(); string d[2][2]={{" ", "["}, {"\n", "]\n"}}; REP(i, N) { cerr << d[0][i==0]; Dump(v[i]); cerr << d[1][i==N-1]; } } template void Dump(vector>> &v){ ll N=(ll)v.size(); string d[2]={" <", "[ <"}; REP(i, N) { cerr << d[i==0] << i << ">\n"; Dump(v[i]); } cerr << "]\n"; } template void Dump(vector>>> &v){ ll N=(ll)v.size(); string d[2]={" ---<", "[ ---<"}; REP(i, N) { cerr << d[i==0] << i << ">---\n"; Dump(v[i]); } cerr << "]\n"; } template void Dump(vector>>>> &v){ ll N=(ll)v.size(); string d[2]={" ======<", "[ ======<"}; REP(i, N) { cerr << d[i==0] << i << ">======\n"; Dump(v[i]); } cerr << "]\n"; } #else template void Dump(vector &v){} template void Dump(vector> &v){} template void Dump(vector>> &v){} template void Dump(vector>>> &v){} template void Dump(vector>>>> &v){} #endif template struct mll_{ ll val; mll_(ll v = 0): val(v % MOD){ if (val < 0) val += MOD; } mll_ operator - () const { return -val; } mll_ operator + (const mll_ &b) const { return val + b.val; } mll_ operator - (const mll_ &b) const { return val - b.val; } mll_ operator * (const mll_ &b) const { return val * b.val; } mll_ operator / (const mll_ &b) const { return mll_(*this) /= b; } mll_ operator + (ll b) const { return *this + mll_(b); } mll_ operator - (ll b) const { return *this - mll_(b); } mll_ operator * (ll b) const { return *this * mll_(b); } friend mll_ operator + (ll a, const mll_ &b) { return b + a; } friend mll_ operator - (ll a, const mll_ &b) { return -b + a; } friend mll_ operator * (ll a, const mll_ &b) { return b * a; } friend mll_ operator / (ll a, const mll_ &b) { return mll_(a)/b; } mll_ &operator += (const mll_ &b) { val=(val+b.val)%MOD; return *this; } mll_ &operator -= (const mll_ &b) { val=(val+MOD-b.val)%MOD; return *this; } mll_ &operator *= (const mll_ &b) { val=(val*b.val)%MOD; return *this; } mll_ &operator /= (const mll_ &b) { ll c=b.val, d=MOD, u=1, v=0; while (d){ ll t = c / d; c -= t * d; swap(c, d); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } mll_ &operator += (ll b) { return *this += mll_(b); } mll_ &operator -= (ll b) { return *this -= mll_(b); } mll_ &operator *= (ll b) { return *this *= mll_(b); } mll_ &operator /= (ll b) { return *this /= mll_(b); } bool operator == (const mll_ &b) { return val == b.val; } bool operator != (const mll_ &b) { return val != b.val; } bool operator == (ll b) { return *this == mll_(b); } bool operator != (ll b) { return *this != mll_(b); } friend bool operator == (ll a, const mll_ &b) { return mll_(a) == b.val; } friend bool operator != (ll a, const mll_ &b) { return mll_(a) != b.val; } friend ostream &operator << (ostream &os, const mll_ &a) { return os << a.val; } friend istream &operator >> (istream &is, mll_ &a) { return is >> a.val; } static mll_ Combination(ll a, ll b){ chmin(b, a-b); if (b<0) return mll_(0); mll_ c = 1; REP(i, b) c *= a-i; REP(i, b) c /= i+1; return c; } }; using mll = mll_<998244353LL>; //1000000007LL;// 998244353LL; using vmll = std::vector; using vvmll = std::vector; using vvvmll = std::vector; using vvvvmll = std::vector; using vvvvvmll = std::vector; template struct SegmentTree{ using F = function; vector dat; //第i要素 dat[i+n-1] ll n; //要素数以上の最小の 2のべき乗 F f; T ti; SegmentTree(){} SegmentTree(vector &v, F f, T ti){ Init(v, f, ti); } void Init(vector &v, F f, T ti){ this->f=f; this->ti=ti; for (n = 1; n < (ll)v.size(); n *= 2); dat.resize(2*n-1, ti); REP(i, (ll)v.size()) { dat[i+n-1] = v[i]; }//初期化 DEP(i, n-1) { dat[i] = f(dat[2*i+1], dat[2*i+2]); }//構築 } void Set(ll i, T x){ //第i要素にxをセット i += n-1; dat[i] = x; while (i>0) { i=(i-1)/2; dat[i]=f(dat[2*i+1], dat[2*i+2]); } } T Range(ll a, ll b) { return range(a, b+1, 0, 0, n); } T operator [] (ll i) { return dat[i+n-1]; } void Dump(ll w=5){ REP(i, n) for (ll k=i+n-1, m=1, p=1; k>=0; p=m, m*=k%2, k=(k==0)?-1:(k-1)/2){ if (m) cerr << ((k= n-1) return k-(n-1); //葉なら見つかった→位置return ll i = findL(a, b, x, 2*k+1, l, (l+r)/2); //左部分木探す if (i==b) i = findL(a, b, x, 2*k+2, (l+r)/2, r); //左になければ右 return i; } ll FindR(ll a, ll b, T x) { return findR(a, b+1, x, 0, 0, n); } ll findR(ll a, ll b, T x, ll k, ll l, ll r){ //[l,r)内最右 なければa-1 if (r<=a || b<=l || f(dat[k], x)!=dat[k]) return a-1; //範囲外or満たさない if (k >= n-1) return k-(n-1); //葉なら見つかった→位置return ll i = findR(a, b, x, 2*k+2, (l+r)/2, r); //右部分木探す if (i==a-1) i = findR(a, b, x, 2*k+1, l, (l+r)/2); //右になければ左 return i; } }; ll K; vector A; SegmentTree sgt; ll dfs(ll a, ll b){ if (a>b)return 0; ll mnval=sgt.Range(a, b); vll mnidxs; mnidxs.push_back(a-1); ll aa=a; while (true){ ll idx = sgt.FindL(aa, b, mnval); if (idx==b+1)break; mnidxs.push_back(idx); aa=idx+1; } mnidxs.push_back(b+1); ll s=sz(mnidxs); ll ans=0; rep(i, 1, s-2){ ll x=mnidxs[i-1]+1; ll y=mnidxs[i]; ll z=mnidxs[i+1]-1; unordered_map cnt; unordered_map sum; cnt.reserve(y-x+2); sum.reserve(y-x+2); rep(j, x, y){ cnt[A[j]]++; sum[A[j]]+=(y-j+1); } rep(j, y, z){ ll val=K-A[j]; if (cnt.count(val)==1){ ans+=sum[val]+cnt[val]*(j-y); } } } rep(i, 0, s-2){ ll aaa=mnidxs[i]+1; ll bbb=mnidxs[i+1]-1; ll v=dfs(aaa, bbb); ans+=v; } return ans; } void solve() { ll n; cin >> n >> K; A = cinv(n); sgt.Init( A, //全初期値の入ったvector [](ll x, ll y){return min(x, y); }, //データ同士の合成関数 INF //単位元 ); ll ans=dfs(0, n-1); cout << ans << '\n'; } int main(){ #if 1 solve(); #else ll t; cin >> t; rep(i, 0, t-1){ solve(); } #endif return 0; }