#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define FOR(i,n) for (i = 0; i < n; ++i)
#define FORK(i,k,n) for (i = k; i <= n; ++i)
#define FORR(i,k,n) for (i = k; i >= n; --i)
#define re(a,b) memset(a,b,sizeof(a))
#define sz(a) (int)(a.size())
#define MIN(a,b) (a) = min((a),(b))
#define MAX(a,b) (a) = max((a),(b))
#define input(in) freopen(in,"r",stdin)
#define output(out) freopen(out,"w",stdout)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define LEN(a) (int)(a.length())
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define FCLOSE {fclose(stdin); fclose(stdout);}
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define M 1000010
#define INF 1001001001
ll visit[M];// for counting the elements
void update(ll i,ll v,ll b[],ll n)
{
for(; i <=n; i += i&-i)
b[i] += v;
}
ll query(ll x,ll b[])
{
ll sum = 0;
for(; x > 0; x -= x&-x)
sum += b[x];
return sum;
}
template<class T> //fast I/O operations
inline void inp(T &p) {
p=0; register char ch=0;
while(ch<'0' or ch>'9') {ch=getchar();}
while(ch>='0' and ch<='9') {p=(p<<1)+(p<<3)+ch-'0'; ch=getchar();}
}
int main()
{
// ios_base::sync_with_stdio(false);cin.tie(0);
ll i,j,n,x,y,k;
inp(n);
inp(k);
ll pi[n]={0},t[n];
ll ans=0;
vector<ll> a;
FOR(i,n)
{
inp(t[i]);
a.pb(t[i]);
}
FOR(i,M)
visit[i]=0;
sort(t,t+n);
FOR(i,n)
{
a[i]=lower_bound(t,t+n,a[i])-t+1;
}
for(i=n-1;i>=0;i--)
{
// cout << a[i] << " ";
pi[i]=query(M-1,visit)-query(a[i],visit);
update(a[i],1,visit,M);
}
sort(pi,pi+n);
for(i=n-1;i>=0;i--)
{
// cout << i << " " << pi[i] << " " << k-pi[i] << "\n";
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wogICAgRk9SKGksbikKICAgIHsKICAgICAgICBpbnAodFtpXSk7CiAgICAgICAgYS5wYih0W2ldKTsKICAgIH0KICAgIEZPUihpLE0pCiAgICB2aXNpdFtpXT0wOwogICAgIHNvcnQodCx0K24pOwogICAgICAgIEZPUihpLG4pCiAgICAgICAgewogICAgICAgICAgICBhW2ldPWxvd2VyX2JvdW5kKHQsdCtuLGFbaV0pLXQrMTsKICAgICAgICB9CiAgICBmb3IoaT1uLTE7aT49MDtpLS0pCiAgICB7CiAgICAgIC8vICAgY291dCA8PCBhW2ldIDw8ICIgIjsKICAgICAgICAgcGlbaV09cXVlcnkoTS0xLHZpc2l0KS1xdWVyeShhW2ldLHZpc2l0KTsKICAgICAgICAgdXBkYXRlKGFbaV0sMSx2aXNpdCxNKTsKICAgICB9CiAgICBzb3J0KHBpLHBpK24pOwogICAgZm9yKGk9bi0xO2k+PTA7aS0tKQogICAgewogICAgIC8vICAgY291dCA8PCBpIDw8ICIgIiA8PCBwaVtpXSA8PCAiICIgPDwgay1waVtpXSAgPDwgIlxuIjsKICAgICAgICBqPWxvd2VyX2JvdW5kKHBpLHBpK24say1waVtpXSktcGk7CiAgICAgIC8vICBjb3V0IDw8IGogPDwgIlxuIjsKICAgICAgICBpZihqIT1uICYmIGo8aSkKICAgICAgICBhbnMrPWktajsKICAgIH0KICAgIHByaW50ZigiJWQiLGFucyk7CiAgICByZXR1cm4gMDsKfQo=