#include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int a[110000]; __int64 num; void calculate(int *p,int l,int mid,int r) { int *b = new int[r + 1]; int i,j,k; for (i = l;i <= r;++i) { b[i] = p[i]; } i = l,j = mid + 1,k = l; while (i <= mid && j <= r) { if (b[i] <= b[j]) p[k++] = b[i++]; else { p[k++] = b[j++]; num += mid - i + 1; } } while (i <= mid) p[k++] = b[i++]; while (j <= r) p[k++] = b[j++]; delete []b; } void dg(int *p,int l,int r) { int mid; if(l<r) { mid = (l + r) / 2; dg(p,l,mid); dg(p,mid + 1,r); calculate(p,l,mid,r); } } int main() { // freopen("b.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF) { for(int i = 0; i < n; i ++) scanf("%d",&a[i]); num = 0; dg(a,0,n-1); printf("%I64d\n",num); } return 0; }