#include #include #include #include #include #include using namespace std; using ll = long long; template< typename T > struct BIT2D{ int H,W; vector> data; BIT2D(int h,int w):H(h),W(w),data(h+1,vector(w+1,0)){} void add(int h,int w,T x){ h++;w++; for(int i = h;i<=H;i+=i&(-i)){ for(int j = w;j<=W;j+=j&(-j)){ data[i][j] += x; } } } //sum of [l,r) T sum(int h1,int w1,int h2,int w2){ return sum(h2,w2)-sum(h2,w1-1)-sum(h1-1,w2)+sum(h1-1,w1-1); } T sum(int h,int w){ h++;w++; T now = 0; for(int i = h;i>0;i-=i&(-i)){ for(int j = w;j>0;j-=j&(-j)){ now += data[i][j]; } } return now; } }; int main(){ int n; cin>>n; vector a(n); for(int i = 0;i>a[i]; ll ans = 0; vector> s1(n+1,vector(n+1,0)),s2(n+1,vector(n+1,0)); for(int i = 0;i