#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

class BITree {
public:
    static const int SIZE = 100010, BIAS = 5;
    long long u[SIZE];
    void clear(){
        memset(u,0,sizeof(u));
    }
    void modify(int x, long long v){
        for(x+=BIAS;x<SIZE;x+=x&-x) u[x]+=v;
    }
    long long getsum(int x){
        long long s=0;
        for(x+=BIAS;x;x-=x&-x) s+=u[x];
        return s;
    }
}BIT;

int a[100010];

int main()
{
	ios::sync_with_stdio(false);
	int n, k;
	while (cin >> n >> k) {
		vector<int> Q;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			Q.push_back(a[i]);
		}
		sort(Q.begin(), Q.end());
		Q.resize(unique(Q.begin(), Q.end()) - Q.begin());
		BIT.clear();
		long long sum = 0;
		for (int i = n - 1; i >= 0; i--) {
			int idx = (lower_bound(Q.begin(), Q.end(), a[i]) - Q.begin()) + 1;
			sum += BIT.getsum(idx - 1);
			BIT.modify(idx, 1);
		}
		long long ans = max(0ll, sum - k);
		cout << ans << '\n';
	}
	return 0;
}

