#include <map> #include <set> #include <cmath> #include <ctime> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <bitset> #include <string> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> #define fuck(x) cout<<"["<<x<<"]"; #define FIN freopen("input.txt","r",stdin); #define FOUT freopen("output.txt","w+",stdout); #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; typedef pair<int, int> PII; const int maxn = 1e5+5; int a[maxn]; //原始数组 int c[maxn]; //维护 long long cnt=0; //答案 void Msort(int l,int r){ int mid=(l+r)/2; int i,j,tmp; if(r>l){ Msort(l,mid); Msort(mid+1,r); tmp=l; for(i=l,j=mid+1;i<=mid&&j<=r; ){ if(a[i]>a[j]){ c[tmp++]=a[j++]; cnt+=mid-i+1; }else{ c[tmp++]=a[i++]; } } if(i<=mid) for(;i<=mid;) c[tmp++]=a[i++]; if(j<=r) for(;j<=r;) c[tmp++]=a[j++]; for(i=l;i<=r;i++) a[i]=c[i]; } } int main(){ int n,t; while(scanf("%d",&n) !=EOF){ cnt=0; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } Msort(0,n-1); cout<<cnt<<endl; } return 0; }