//#define _GLIBCXX_DEBUG #include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair; template bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} template bool chmax(T1 &a,T2 b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,-1,0,0,1,1,-1,-1}; vectordy={0,0,1,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } template ostream &operator<<(ostream &os, const pair&p){ return os << p.first << " " << p.second; } //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); ll ret=0; void solve(ll l,ll r,ll k,vector&a){ if(r-l==1){ if(a[l]*2==k)ret++; return; } ll m=(l+r)/2; map>mp; map>cum; map>cum2; P mi=MP(INF,INF); rrep(i,l,m){ if(mi.fi>a[i])mi=MP(a[i],1); else if(mi.fi==a[i])mi.se++; mp[a[i]].EB(mi.fi); if(!cum.count(a[i]))cum[a[i]].EB(0,0); if(!cum2.count(a[i]))cum2[a[i]].EB(0,0); auto k=cum[a[i]].back(); cum[a[i]].EB(k.fi+m-i,k.se+1); k=cum2[a[i]].back(); cum2[a[i]].EB(k.fi+(m-i)*(mi.se==1),k.se+(mi.se==1)); } /*for(auto z:cum2){ cout<a[i])mi=MP(a[i],1); else if(mi.fi==a[i])mi.se++; //cout<())-mp[k-a[i]].begin(); //cout<())-mp[k-a[i]].begin(); auto p1=cum2[k-a[i]][(ll)mp[k-a[i]].size()]; auto p2=cum2[k-a[i]][idx]; //cout<>n>>k; vectora(n); rep(i,0,n)cin>>a[i]; solve(0,n,k,a); cout<