#include #include #include #include #include #define REP(i,a,b) for(i=a;i=2; m/=2){ mh = m / 2; rep(i,mh){ w = pntPolar(1, i*theta); for(j=i; j (i ^= k); k/=2); if(j < i) w=a[i], a[i]=a[j], a[j]=w; } } #define ll long long #define N2 65536 #define M 30000 #define BLOCK_SIZE 30 int in[120000]; int bef[M], aft[M], inside[M]; pnt p1[N2], p2[N2]; int main(){ int N; int i, j, k, block; int st, ed, per; ll res; double invN2 = 1.0 / N2; assert( scanf("%d",&N)==1 ); assert( 1<=N && N<=100000 ); rep(i,N) assert( scanf("%d",in+i)==1 ), assert( 1 <= in[i] && in[i] <= M ), in[i]--; /* bef[i] = the number of i in the previous blocks */ /* aft[i] = the number of i in the next blocks */ res = 0; rep(i,M) bef[i] = aft[i] = 0; rep(i,N) aft[in[i]]++; per = (N+BLOCK_SIZE-1) / BLOCK_SIZE; /* the number of elements for each blocks */ rep(block, BLOCK_SIZE){ st = block * per; /* the index of the first element in this block */ ed = (block+1) * per; /* the index of the first element in the next block */ if(ed > N) ed = N; REP(i,st,ed) aft[in[i]]--; rep(i,M) inside[i] = 0; /* BEGIN: counting arithmetic progressions whose at least 2 terms are in this block */ REP(i,st,ed){ /* inside[i] denotes the number of i in indexes [st, i) (in this block) */ REP(j,i+1,ed) if(in[i] != in[j]){ /* in this loop, count only arithmetic progressions with three distinct terms */ k = in[i] - (in[j] - in[i]); if(0<=k && k