#include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #define mod 1000000007 #define INF 1000000000 #define LLINF 2000000000000000000LL #define PI 3.1415926536 #define SIZE 1000002 struct SEG{ int segn2,seg[2<<20]; void init(int n){ segn2=1; while(segn20){ k=(k-1)/2; seg[k]=seg[k*2+1]+seg[k*2+2]; } return; } void add(int k,int x){ k+=segn2-1; seg[k]+=x; while(k>0){ k=(k-1)/2; seg[k]=seg[k*2+1]+seg[k*2+2]; } return; } }; SEG seg1,seg2,seg3; int n,a[SIZE],s_a[SIZE],dic_size,d; int s1[SIZE],s2[SIZE],s3[SIZE]; ll ans=0; map dic; int main(){ scanf("%d",&n); for(int i=0;i