#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <random>
#include <iomanip>
#include <assert.h>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef double long dl;
typedef unsigned long long ull;

int INF = 2e9;

vector <int> pref(string & s){
    int n = s.size();
    vector<int> g(n, 0);
    for(int i=1; i<n; i++){
        int j = g[i-1];
        while(j>0 and s[i]!=s[j]){
            j=g[j-1];
        }
        if(s[i]==s[j]) j++;
        g[i]=j;
    }
    return g;
}

int N = 3e5+10;
vector<ll> tree;

void build(vector<int> & g, int v, int tl, int tr){
    if(tl==tr) tree[v]=g[tl];
    else{
        int tm=(tl+tr)/2;
        build(g, 2*v, tl, tm);
        build(g, 2*v+1, tm+1, tr);
        tree[v]=max(tree[2*v], tree[2*v+1]);
    }
}

int find_max(int v, int tl, int tr, int l, int r){
    if(l>r) return 0;
    if(tl==l and tr==r) return tree[v];
    int tm = (tl+tr)/2;
    return max(find_max(2*v, tl, tm, l, min(tm, r)),
               find_max(2*v+1, tm+1, tr, max(tm+1, l), r));
}

/*void push(ll v, ll l, ll tm){
    if(tree[v]!=0){
        tree[2*v]=max(tree[v], tree[2*v]);
        tree[2*v+1]=max(tree[v]+tm-l+1, tree[2*v+1]);
        tree[v]=0;
    }
}*/

void update(ll v, ll tl, ll tr, ll pos, ll val){
    if(tl==tr) tree[v]=val;
    else{
        ll tm=(tl+tr)/2;
        if(pos<=tm) update(2*v, tl, tm, pos, val);
        else update(2*v+1, tm+1, tr, pos, val);
        tree[v]=max(tree[2*v], tree[2*v+1]);
    }
}

/*void print_arr(ll v, ll l, ll r){
    if(l==r){
        cout << tree[v] << " ";
    }
    else{
        ll m = (l+r)/2;
        push(v, l, m);
        print_arr(2*v, l, m);
        print_arr(2*v+1, m+1, r);
    }
}*/

ll bin_pow(ll a, ll b, ll m){
    if(b==0) return 1;
    a%=m;
    if(b%2==0){
        return bin_pow(a*a, b/2, m)%m;
    }
    else return (a*bin_pow(a, b-1, m))%m;
}

ull numbers(ull n){
    ull a=0;
    while(n!=0){
        n/=10;
        a++;
    }
    return a;
}

ull num(ull j, ull n1, ull k){
    ull t=0, a=0;
    while(a!=n1-k+1){
        t=j%10;
        j/=10;
        a++;
    }
    return t;
}

char f(string s){
    if(s[0]=='a' and s[1]=='b' or s[1]=='a' and s[0]=='b') return 'c';
    if(s[0]=='a' and s[1]=='c' or s[1]=='a' and s[0]=='c') return 'b';
    if(s[0]=='b' and s[1]=='c' or s[1]=='b' and s[0]=='c') return 'a';
}

vector<int> ssize;
vector<int> parent;
//vector<int> ma;

int find_set(int v){
    if(v==parent[v]){
        return v;
    }
    return parent[v] = find_set(parent[v]);
}

void union_set(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if(a!=b){
        if(ssize[a]<ssize[b]){
            parent[a] = b;
            ssize[b]+=ssize[a];
            //ma[b]=max(ma[a], ma[b]);
        }
        else{
            parent[b] = a;
            ssize[a]+=ssize[b];
            //ma[a]=max(ma[a], ma[b]);
        }
    }
}

void f(int v, int l, int r, int pos){
    if(l==r) tree[v]=1;
    else{
        int m = (l+r)/2;
        if(m>=pos){
            f(2*v+1, l, m, pos);
        }
        else{
            f(2*v+2, m+1, r, pos);
        }
        tree[v]=tree[2*v+1]+tree[2*v+2];
    }
}

int F(int v, int l, int r, int sum) {
    if (l == r) {
        return l;
    }
    int m = (l + r ) / 2;
    if (tree[2 * v + 1] < sum) {
        return F(2 * v + 2, m+1, r, sum - tree[2 * v + 1]);
    }
    else {
        return F(2 * v + 1, l, m, sum);
    }
}

struct wor{
    ll a, b, c, d, e;
};

bool cmp(wor w1, wor w2){
    return w1.a>w2.a;
}

bool cmp1(wor w1, wor w2){
    return w1.b<w2.b;
}

bool cmp2(wor w1, wor w2){
    return w1.c<w2.c;
}

double C_n_k(int n, int k){
    k=max(n-k, k);
    double ans=1;
    int pow_two = n+1;
    for(int i=k+1; i<=n; i++){
        ans*=i;
        while(ans>1e5 and pow_two!=0){
            ans/=2;
            pow_two--;
        }
    }
    for(int i=1; i<=n-k; i++){
        ans/=i;
    }
    while(pow_two!=0){
        ans/=2;
        pow_two--;
    }
    return ans;
}

vector<vector<int>> up;
int l, timer;
void dfs_lca(int v, int p, vector<vector<int>> & g, vector<int> & tinn, vector<int> & toutt){
    tinn[v]=timer;
    timer++;
    up[v][0]=p;
    for(int i=1; i<=l; i++){
        up[v][i]=up[up[v][i-1]][i-1];
    }
    for(int i=0; i<g[v].size(); i++){
        int to = g[v][i];
        if(to==p) continue;
        dfs_lca(to, v, g, tinn, toutt);
    }
    toutt[v]=timer;
}

bool upper(int a, int b, vector<int> & tinn, vector<int> & toutt){
    if(tinn[a]<=tinn[b] and toutt[a]>=toutt[b]){
        return true;
    }
    return false;
}

ll lca(int a, int b, vector<int> & tinn, vector<int> & toutt){
    ll ans=0;
    if(upper(a, b, tinn, toutt)) return 0;
    for(int i=l; i>=0; i--){
        if(!upper(up[a][i], b, tinn, toutt)){
            a=up[a][i];
            ans+=(1<<i);
        }
    }
    ans+=1;
    return ans;
}

ll phi(ll n){
    ll ans=n;
    for(ll i=2; i*i<=n; i++){
        if(n%i==0){
            while(n%i==0){
                n/=i;
            }
            ans-=ans/i;
        }
    }
    if(n!=1){
        ans-=ans/n;
    }
    return ans;
}

/*bool operator<(wor w1, wor w2){
    return w1.c>w2.c;
}*/

int main() {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie(0);
    cout.tie(0);
    //freopen("lazy.in", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    ll n, m, k;
    cin >> n >> m >> k;
    vector<bool> used(1e6+10, false);
    for(int i=0; i<n; i++){
        ll a;
        cin >> a;
        used[a]=true;
    }
    ll ans=0;
    ll sum=0;
    ll last=0;
    for(int i=1; i<=m; i++){
        if(used[i]){
            sum++;
            last=i;
        }
        if(sum==k){
            ans++;
            sum--;
            used[last]=false;
        }
    }
    for(int i=m+1; i<=1e6; i++){
        if(used[i-m]) sum--;
        if(used[i]){
            sum++;
            last=i;
        }
        if(sum==k){
            ans++;
            sum--;
            used[last]=false;
        }
    }
    cout << ans;
    return 0;
    //system( "pause" );
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <random>
#include <iomanip>
#include <assert.h>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef double long dl;
typedef unsigned long long ull;

int INF = 2e9;

vector <int> pref(string & s){
    int n = s.size();
    vector<int> g(n, 0);
    for(int i=1; i<n; i++){
        int j = g[i-1];
        while(j>0 and s[i]!=s[j]){
            j=g[j-1];
        }
        if(s[i]==s[j]) j++;
        g[i]=j;
    }
    return g;
}

int N = 3e5+10;
vector<ll> tree;

void build(vector<int> & g, int v, int tl, int tr){
    if(tl==tr) tree[v]=g[tl];
    else{
        int tm=(tl+tr)/2;
        build(g, 2*v, tl, tm);
        build(g, 2*v+1, tm+1, tr);
        tree[v]=max(tree[2*v], tree[2*v+1]);
    }
}

int find_max(int v, int tl, int tr, int l, int r){
    if(l>r) return 0;
    if(tl==l and tr==r) return tree[v];
    int tm = (tl+tr)/2;
    return max(find_max(2*v, tl, tm, l, min(tm, r)),
               find_max(2*v+1, tm+1, tr, max(tm+1, l), r));
}

/*void push(ll v, ll l, ll tm){
    if(tree[v]!=0){
        tree[2*v]=max(tree[v], tree[2*v]);
        tree[2*v+1]=max(tree[v]+tm-l+1, tree[2*v+1]);
        tree[v]=0;
    }
}*/

void update(ll v, ll tl, ll tr, ll pos, ll val){
    if(tl==tr) tree[v]=val;
    else{
        ll tm=(tl+tr)/2;
        if(pos<=tm) update(2*v, tl, tm, pos, val);
        else update(2*v+1, tm+1, tr, pos, val);
        tree[v]=max(tree[2*v], tree[2*v+1]);
    }
}

/*void print_arr(ll v, ll l, ll r){
    if(l==r){
        cout << tree[v] << " ";
    }
    else{
        ll m = (l+r)/2;
        push(v, l, m);
        print_arr(2*v, l, m);
        print_arr(2*v+1, m+1, r);
    }
}*/

ll bin_pow(ll a, ll b, ll m){
    if(b==0) return 1;
    a%=m;
    if(b%2==0){
        return bin_pow(a*a, b/2, m)%m;
    }
    else return (a*bin_pow(a, b-1, m))%m;
}

ull numbers(ull n){
    ull a=0;
    while(n!=0){
        n/=10;
        a++;
    }
    return a;
}

ull num(ull j, ull n1, ull k){
    ull t=0, a=0;
    while(a!=n1-k+1){
        t=j%10;
        j/=10;
        a++;
    }
    return t;
}

char f(string s){
    if(s[0]=='a' and s[1]=='b' or s[1]=='a' and s[0]=='b') return 'c';
    if(s[0]=='a' and s[1]=='c' or s[1]=='a' and s[0]=='c') return 'b';
    if(s[0]=='b' and s[1]=='c' or s[1]=='b' and s[0]=='c') return 'a';
}

vector<int> ssize;
vector<int> parent;
//vector<int> ma;

int find_set(int v){
    if(v==parent[v]){
        return v;
    }
    return parent[v] = find_set(parent[v]);
}

void union_set(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if(a!=b){
        if(ssize[a]<ssize[b]){
            parent[a] = b;
            ssize[b]+=ssize[a];
            //ma[b]=max(ma[a], ma[b]);
        }
        else{
            parent[b] = a;
            ssize[a]+=ssize[b];
            //ma[a]=max(ma[a], ma[b]);
        }
    }
}

void f(int v, int l, int r, int pos){
    if(l==r) tree[v]=1;
    else{
        int m = (l+r)/2;
        if(m>=pos){
            f(2*v+1, l, m, pos);
        }
        else{
            f(2*v+2, m+1, r, pos);
        }
        tree[v]=tree[2*v+1]+tree[2*v+2];
    }
}

int F(int v, int l, int r, int sum) {
    if (l == r) {
        return l;
    }
    int m = (l + r ) / 2;
    if (tree[2 * v + 1] < sum) {
        return F(2 * v + 2, m+1, r, sum - tree[2 * v + 1]);
    }
    else {
        return F(2 * v + 1, l, m, sum);
    }
}

struct wor{
    ll a, b, c, d, e;
};

bool cmp(wor w1, wor w2){
    return w1.a>w2.a;
}

bool cmp1(wor w1, wor w2){
    return w1.b<w2.b;
}

bool cmp2(wor w1, wor w2){
    return w1.c<w2.c;
}

double C_n_k(int n, int k){
    k=max(n-k, k);
    double ans=1;
    int pow_two = n+1;
    for(int i=k+1; i<=n; i++){
        ans*=i;
        while(ans>1e5 and pow_two!=0){
            ans/=2;
            pow_two--;
        }
    }
    for(int i=1; i<=n-k; i++){
        ans/=i;
    }
    while(pow_two!=0){
        ans/=2;
        pow_two--;
    }
    return ans;
}

vector<vector<int>> up;
int l, timer;
void dfs_lca(int v, int p, vector<vector<int>> & g, vector<int> & tinn, vector<int> & toutt){
    tinn[v]=timer;
    timer++;
    up[v][0]=p;
    for(int i=1; i<=l; i++){
        up[v][i]=up[up[v][i-1]][i-1];
    }
    for(int i=0; i<g[v].size(); i++){
        int to = g[v][i];
        if(to==p) continue;
        dfs_lca(to, v, g, tinn, toutt);
    }
    toutt[v]=timer;
}

bool upper(int a, int b, vector<int> & tinn, vector<int> & toutt){
    if(tinn[a]<=tinn[b] and toutt[a]>=toutt[b]){
        return true;
    }
    return false;
}

ll lca(int a, int b, vector<int> & tinn, vector<int> & toutt){
    ll ans=0;
    if(upper(a, b, tinn, toutt)) return 0;
    for(int i=l; i>=0; i--){
        if(!upper(up[a][i], b, tinn, toutt)){
            a=up[a][i];
            ans+=(1<<i);
        }
    }
    ans+=1;
    return ans;
}

ll phi(ll n){
    ll ans=n;
    for(ll i=2; i*i<=n; i++){
        if(n%i==0){
            while(n%i==0){
                n/=i;
            }
            ans-=ans/i;
        }
    }
    if(n!=1){
        ans-=ans/n;
    }
    return ans;
}

/*bool operator<(wor w1, wor w2){
    return w1.c>w2.c;
}*/

int main() {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie(0);
    cout.tie(0);
    //freopen("lazy.in", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    ll n, m, k;
    cin >> n >> m >> k;
    vector<int> g(n);
    for(int i=0; i<n; i++){
        cin >> g[i];
    }
    sort(g.begin(), g.end());
    set<int> s;
    ll ans=0;
    for(int i=0; i<n; i++){
        while(s.size()!=0 and *s.begin()+m-1<g[i]){
            s.erase(s.begin());
        }
        if(s.size()==k-1){
            ans++;
        }
        else {
            s.insert(g[i]);
        }
    }
    cout << ans;
    return 0;
    //system( "pause" );
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    go();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> cnt(1e6 + 5), a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]] = 1;
    }
    sort(all(a));
    int curr = 0, ans = 0;
    for (int i = 1; i <= m; i++)
        if (cnt[i])
            curr++;
    if (curr >= k) {
        int idx = lower_bound(all(a), m) - a.begin();
        if (idx == n)
            --idx;
        if (a[idx] > m)
            --idx;
        while (curr >= k) {
            cnt[a[idx]]--;
            idx--;
            ans++;
            curr--;
        }
    }
    for (int i = 2; i <= m; i++) {
        if (cnt[i - 1])
            --curr;
        if (cnt[i + m - 1])
            ++curr;
        if (curr >= k) {
            int idx = lower_bound(all(a), i + m - 1) - a.begin();
            if (idx == n)
                --idx;
            if (a[idx] > i + m - 1)
                --idx;
            while (curr >= k) {
                cnt[a[idx]]--;
                idx--;
                ans++;
                curr--;
            }
        }
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    go();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> cnt(1e6 + 5), a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]] = 1;
    }
    int curr = 0, ans = 0;
    for (int i = 1; i <= m; i++)
        if (cnt[i])
            curr++;
    if (curr >= k) {
        int idx = lower_bound(all(a), m) - a.begin();
        if (idx == n)
            --idx;
        if (a[idx] > m)
            --idx;
        while (curr >= k) {
            cnt[a[idx]]--;
            idx--;
            ans++;
            curr--;
        }
    }
    for (int i = 2; i <= m; i++) {
        if (cnt[i - 1])
            --curr;
        if (cnt[i + m - 1])
            ++curr;
        if (curr >= k) {
            int idx = lower_bound(all(a), a[i + m - 1]) - a.begin();
            if (idx == n)
                --idx;
            if (a[idx] > i + m - 1)
                --idx;
            while (curr >= k) {
                cnt[a[idx]]--;
                idx--;
                ans++;
                curr--;
            }
        }
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    go();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> cnt(1e6 + 5), a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]] = 1;
    }
    int curr = 0, ans = 0;
    for (int i = 1; i <= m; i++)
        if (cnt[i])
            curr++;
    if (curr >= k) {
        int idx = lower_bound(all(a), m) - a.begin();
        if (idx == n)
            --idx;
        if (a[idx] > m)
            --idx;
        while (curr >= k) {
            cnt[a[idx]]--;
            idx--;
            ans++;
            curr--;
        }
    }
    for (int i = 2; i <= m; i++) {
        if (cnt[i - 1])
            --curr;
        if (cnt[i + m - 1])
            ++curr;
        if (curr >= k) {
            int idx = lower_bound(all(a), i + m - 1) - a.begin();
            if (idx == n)
                --idx;
            if (a[idx] > i + m - 1)
                --idx;
            while (curr >= k) {
                cnt[a[idx]]--;
                idx--;
                ans++;
                curr--;
            }
        }
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    go();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> cnt(2e6 + 5), a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]] = 1;
    }
    sort(all(a));
    int curr = 0, ans = 0;
    for (int i = 1; i <= m; i++)
        if (cnt[i])
            curr++;

    if (curr >= k) {
        int idx = upper_bound(all(a), m) - a.begin();
        --idx;
        while (curr >= k) {
            if (cnt[a[idx]]) {
                cnt[a[idx]]--;
                assert(a[idx] >= 1 and a[idx] <= m);
                ans++;
                curr--;
            }
            idx--;
        }
    }
    for (int i = 2; i <= 1e6; i++) {
        if (cnt[i - 1])
            --curr;
        if (cnt[i + m - 1])
            ++curr;
        if (curr >= k) {
            int idx = upper_bound(all(a), i + m - 1) - a.begin();
            --idx;
            while (curr >= k) {
                if (cnt[a[idx]]) {
                    cnt[a[idx]]--;
                    assert(a[idx] >= i and a[idx] <= m + i - 1);
                    ans++;
                    curr--;
                }
                idx--;
            }
        }
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    go();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> cnt(2e6 + 5), a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]] = 1;
    }
    sort(all(a));
    deque<int> d;
    for (int i = 1; i <= m; i++) {
        if (cnt[i])
            d.push_back(i);
    }
    int ans = 0;
    if (d.size() >= k) {
        while (d.size() >= k) {
            int r = d.back();
            --cnt[r];
            ans++;
            d.pop_back();
        }
    }
    for (int i = 2; i <= 1e6; i++) {
        if (cnt[i - 1])
            d.pop_front();
        if (cnt[i + m - 1])
            d.push_back(i + m - 1);
        while (d.size() >= k) {
            int r = d.back();
            --cnt[r];
            ans++;
            d.pop_back();
        }
    }
    print(ans);
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    go();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> cnt(1e6 + 5), a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]] = 1;
    }
    sort(all(a));

    int curr = 0, ans = 0;
    for (int i = 1; i <= m; i++)
        if (cnt[i])
            curr++;

    if (curr >= k) {
        int idx = upper_bound(all(a), m) - a.begin();
        if (idx == n)
            --idx;
        if (a[idx] > m)
            --idx;
        while (curr >= k) {
            cnt[a[idx]]--;
            idx--;
            ans++;
            curr--;
        }
    }
    for (int i = 2; i <= m; i++) {
        if (i + m - 1 > 1e6)
            break;
        if (cnt[i - 1])
            --curr;
        if (cnt[i + m - 1])
            ++curr;
        if (curr >= k) {
            int idx = upper_bound(all(a), i + m - 1) - a.begin();
            if (idx == n)
                --idx;
            if (a[idx] > i + m - 1)
                --idx;
            while (curr >= k) {
                cnt[a[idx]]--;
                idx--;
                ans++;
                curr--;
            }
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000 //INF - 1e14
#define vi vector<ll>
#define PB push_back
#define mpl map<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) rin(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) printmat(mat,row,col);
#else
#define debug(x...)
#define matdeb(mat,row,col)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime
ll aN = 1e6;
vi a(aN + 1);
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif

	ll test_cases = 1;
	// inp(test_cases);
	fer(test_case, 1, test_cases) {
		// cout << "Case #" << test_case << ": ";
		rin(n, m, k);
		ll ans = 0;
		fer(i, 0, n - 1) {
			rin(p);
			a[p] = 1;
		}
		k--;
		// debug(n, m, k);;;
		fer(i, 0, 30) {
			debug(i, a[i]);
		}
		ll cnt = 0;
		fer(i, 0, m - 1) {
			cnt += a[i];
		}
		ll rmv = max(0LL, cnt - k);
		cnt -= rmv;
		ans += rmv;
		fer(i, 1, aN - m) {
			cnt -= a[i - 1];
			cnt += a[i + m - 1];
			ll rmv = max(0LL, cnt - k);
			cnt -= rmv;
			ans += rmv;
			debug(rmv, ans, cnt);
			if (i == 30)
				break;
		}
		debug(ans);
		cout << ans;
		// auto it = s.begin();
		// while (it != s.end()) {
		// 	auto itt = s.lower_bound(*it + m - 1);
		// 	if (itt != s.end() && *itt > *it) {
		// 		itt--;
		// 	}

		// 	while()
		// }
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	int n, m, k, ans = 0;
	cin >> n >> m >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	if (k == 1) {
		cout << n;
		return 0;
	}
	sort(v.begin(), v.end());
	int i = 0;
	while (i != n) {
		int val = v[i] + (m - 1);
		int ii = lower_bound(v.begin(), v.end(), val) - v.begin();
		if (ii != n) {
			if (v[ii] != val && ii) {
				ii--;
			}
		}
		else {
			ii--;
		}
		int rmv = max(0, ii - i + 1 - k + 1);
		ans += rmv;
		if (rmv) i = ii + 1;
		else i++;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	int n, m, k, ans = 0;
	cin >> n >> m >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	if (k == 1) {
		cout << n;
		return 0;
	}
	sort(v.begin(), v.end());
	int i = 0;
	while (i != n) {
		int val = v[i] + (m - 1);
		int ii = lower_bound(v.begin(), v.end(), val) - v.begin();
		if (ii != n) {
			if (v[ii] != val && ii) {
				ii--;
			}
		}
		else {
			ii--;
		}
		ans += max(0, ii - i + 1 - k + 1);
		i++;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	int n, m, k, ans = 0;
	cin >> n >> m >> k;;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	if (k == 1) {
		cout << n;
		return 0;
	}
	sort(v.begin(), v.end());
	int i = 0;
	while (i != n) {
		int val = v[i] + (m - 1);
		int ii = lower_bound(v.begin(), v.end(), val) - v.begin();
		if (ii != n) {
			if (v[ii] != val && ii) {
				ii--;
			}
		}
		else {
			ii--;
		}
		int rmv = max(0, ii - i + 1 - k + 1);
		ans += rmv;
		if (rmv) i = ii + 1;
		else i++;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define ll int
#define MOD 1000000007
#define INF 100000000000000
//INF - 1e14
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// 	freopen("intt.txt", "r", stdin);
// 	freopen("outt.txt", "w", stdout);
// #endif
	ll n, m, k, ans = 0;
	cin >> n >> m >> k;
	vi v(n);
	fer(i, 0, n - 1) cin >> v[i];
	if (k == 1) {
		cout << n;
		return 0;
	}
	sort(v.begin(), v.end());
	ll i = 0;
	while (i != n) {
		int val = v[i] + (m - 1);
		int ii = lower_bound(v.begin(), v.end(), val) - v.begin();
		debug(ii, val);
		if (ii != n) {
			if (v[ii] != val && ii) {
				ii--;
			}
		}
		else {
			ii--;
		}
		ans += max(0, ii - i + 1 - k + 1);
		debug(i, ii, ans);
		i = ii + 1;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000 //INF - 1e14
#define vi vector<ll>
#define PB push_back
#define mpl map<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) rin(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) printmat(mat,row,col);
#else
#define debug(x...)
#define matdeb(mat,row,col)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime
ll aN = 1e6;
vi a(aN + 1);
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	ll test_cases = 1;
	// inp(test_cases);
	fer(test_case, 1, test_cases) {
		// cout << "Case #" << test_case << ": ";
		rin(n, m, k);
		set<ll> s;
		ll ans = 0;
		fer(i, 0, n - 1) {
			rin(p);
			a[p] = 1;
			s.insert(p);
		}
		if (k == 1) {
			cout << n;
			return 0;
		}
		k--;
		ll cnt = 0;
		fer(i, 1, m) {
			cnt += a[i];
		}
		ll rmv = max(0LL, cnt - k);
		cnt -= rmv;
		ans += rmv;
		if (rmv) {
			auto it = s.lower_bound(m);
			if (it != s.end() && ((*it) != m))
				it--;
			if (it == s.end())
				it--;
			fer(i, 1, rmv) {
				auto itt = it;
				it--;
				s.erase(itt);
			}
		}
		if (m == 1e6) {
			cout << ans;
			return 0;
		}
		fer(i, 2, aN - m + 1) {
			if (s.find(i - 1) != s.end())
				cnt--;
			if (s.find(i + m - 1) != s.end())
				cnt++;
			ll rmv = max(0LL, cnt - k);
			cnt -= rmv;
			if (rmv) {
				auto it = s.lower_bound(i + m - 1);
				if (it != s.end() && (*it) != i + m - 1)
					it--;
				if (it == s.end())
					it--;
				fer(i, 1, rmv) {
					auto itt = it;
					it--;
					s.erase(itt);
				}
			}

			ans += rmv;
		}
		cout << ans;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	int n, m, k, ans = 0;
	cin >> n >> m >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	if (k == 1) {
		cout << n;
		return 0;
	}
	sort(v.begin(), v.end());
	int i = 0;
	while (i != n) {
		int val = v[i] + (m - 1);
		int ii = lower_bound(v.begin(), v.end(), val) - v.begin();
		if (ii != n) {
			if (v[ii] != val && ii) {
				ii--;
			}
		}
		else {
			ii--;
		}
		ans += max(0, ii - i + 1 - k + 1);
		i = ii + 1;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000 //INF - 1e14
#define vi vector<ll>
#define PB push_back
#define mpl map<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) rin(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) printmat(mat,row,col);
#else
#define debug(x...)
#define matdeb(mat,row,col)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime
ll aN = 1e6;
vi a(aN + 1);
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	ll test_cases = 1;
	// inp(test_cases);
	fer(test_case, 1, test_cases) {
		// cout << "Case #" << test_case << ": ";
		rin(n, m, k);
		set<ll> s;
		ll ans = 0;
		fer(i, 0, n - 1) {
			rin(p);
			a[p] = 1;
			s.insert(p);
		}
		if (k == 1) {
			cout << n;
			return 0;
		}
		debug(s);
		k--;
		// debug(n, m, k);;;
		// fer(i, 0, 30) {
		// 	debug(i, a[i]);
		// }
		ll cnt = 0;
		fer(i, 1, m) {
			cnt += a[i];
		}
		ll rmv = max(0LL, cnt - k);
		cnt -= rmv;
		ans += rmv;
		debug(rmv);
		if (rmv) {
			debug("called1");
			auto it = s.lower_bound(m);
			if (it != s.end() && *it != m)
				it--;
			fer(i, 1, rmv) {
				// debug(*it);
				auto itt = it;
				it--;
				s.erase(itt);
			}
		}
		debug(s);
		debug(cnt, rmv);
		fer(i, 2, aN - m + 1) {
			if (s.find(i - 1) != s.end())
				cnt--;
			if (s.find(i + m - 1) != s.end())
				cnt++;
			ll rmv = max(0LL, cnt - k);
			cnt -= rmv;
			if (rmv) {
				debug("called");
				auto it = s.lower_bound(i + m - 1);
				if (it != s.end() && *it != i + m - 1)
					it--;
				fer(i, 1, rmv) {
					auto itt = it;
					it--;
					s.erase(itt);
				}
			}
			if (rmv) {
				// debug(i, rmv, ans, cnt);
			}
			// debug(s);
			ans += rmv;
			// if (i == 40)
			// 	break;
		}
		debug(ans);
		cout << ans;
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000 //INF - 1e14
#define vi vector<ll>
#define PB push_back
#define mpl map<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) rin(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) printmat(mat,row,col);
#else
#define debug(x...)
#define matdeb(mat,row,col)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime
ll aN = 1e6;
vi a(aN + 1);
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	ll test_cases = 1;
	// inp(test_cases);
	fer(test_case, 1, test_cases) {
		// cout << "Case #" << test_case << ": ";
		rin(n, m, k);
		set<ll> s;
		ll ans = 0;
		fer(i, 0, n - 1) {
			rin(p);
			a[p] = 1;
			s.insert(p);
		}
		m = min(m, n);
		if (k == 1) {
			cout << n;
			return 0;
		}
		debug(s);
		k--;
		// debug(n, m, k);;;
		// fer(i, 0, 30) {
		// 	debug(i, a[i]);
		// }
		ll cnt = 0;
		fer(i, 1, m) {
			cnt += a[i];
		}
		ll rmv = max(0LL, cnt - k);
		cnt -= rmv;
		ans += rmv;
		debug(rmv);
		if (rmv) {
			debug("called1");
			auto it = s.lower_bound(m);
			if (it != s.end() && *it != m)
				it--;
			fer(i, 1, rmv) {
				// debug(*it);
				auto itt = it;
				it--;
				s.erase(itt);
			}
		}
		debug(s);
		debug(cnt, rmv);
		fer(i, 2, aN - m + 1) {
			if (s.find(i - 1) != s.end())
				cnt--;
			if (s.find(i + m - 1) != s.end())
				cnt++;
			ll rmv = max(0LL, cnt - k);
			cnt -= rmv;
			if (rmv) {
				debug("called");
				auto it = s.lower_bound(i + m - 1);
				if (it != s.end() && *it != i + m - 1)
					it--;
				fer(i, 1, rmv) {
					auto itt = it;
					it--;
					s.erase(itt);
				}
			}
			if (rmv) {
				// debug(i, rmv, ans, cnt);
			}
			// debug(s);
			ans += rmv;
			// if (i == 40)
			// 	break;
		}
		debug(ans);
		cout << ans;
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000 //INF - 1e14
#define vi vector<ll>
#define PB push_back
#define mpl map<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) rin(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) printmat(mat,row,col);
#else
#define debug(x...)
#define matdeb(mat,row,col)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime
ll aN = 1e6;
vi a(aN + 1);
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif

	ll test_cases = 1;
	// inp(test_cases);
	fer(test_case, 1, test_cases) {
		// cout << "Case #" << test_case << ": ";
		rin(n, m, k);
		ll ans = 0;
		fer(i, 0, n - 1) {
			rin(p);
			a[p] = 1;
		}
		k--;
		// debug(n, m, k);;;
		fer(i, 0, 30) {
			debug(i, a[i]);
		}
		ll cnt = 0;
		fer(i, 0, m - 1) {
			cnt += a[i];
		}
		ll rmv = max(0LL, cnt - k);
		cnt -= rmv;
		ans += rmv;
		fer(i, 1, aN - m) {
			cnt -= a[i - 1];
			cnt += a[i + m - 1];
			ll rmv = max(0LL, cnt - k);
			cnt -= rmv;
			ans += rmv;
			// debug(rmv, ans, cnt);
			// if (i == 30)
			// 	break;
		}
		debug(ans);
		cout << ans;
		// auto it = s.begin();
		// while (it != s.end()) {
		// 	auto itt = s.lower_bound(*it + m - 1);
		// 	if (itt != s.end() && *itt > *it) {
		// 		itt--;
		// 	}

		// 	while()
		// }
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000 //INF - 1e14
#define vi vector<ll>
#define PB push_back
#define mpl map<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) rin(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) printmat(mat,row,col);
#else
#define debug(x...)
#define matdeb(mat,row,col)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime
ll aN = 1e6;
vi a(aN + 1);
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	ll test_cases = 1;
	// inp(test_cases);
	fer(test_case, 1, test_cases) {
		// cout << "Case #" << test_case << ": ";
		rin(n, m, k);
		set<ll> s;
		ll ans = 0;
		fer(i, 0, n - 1) {
			rin(p);
			a[p] = 1;
			s.insert(p);
		}
		if (k == 1) {
			cout << n;
			return 0;
		}
		k--;
		if (m == 1e6) {
			cout << 0;
			return 0;
		}
		ll cnt = 0;
		fer(i, 1, m) {
			cnt += a[i];
		}
		ll rmv = max(0LL, cnt - k);
		cnt -= rmv;
		ans += rmv;
		if (rmv) {
			auto it = s.lower_bound(m);
			if (it != s.end() && *it != m)
				it--;
			fer(i, 1, rmv) {
				auto itt = it;
				it--;
				s.erase(itt);
			}
		}
		fer(i, 2, aN - m + 1) {
			if (s.find(i - 1) != s.end())
				cnt--;
			if (s.find(i + m - 1) != s.end())
				cnt++;
			ll rmv = max(0LL, cnt - k);
			cnt -= rmv;
			if (rmv) {
				auto it = s.lower_bound(i + m - 1);
				if (it != s.end() && *it != i + m - 1)
					it--;
				fer(i, 1, rmv) {
					auto itt = it;
					it--;
					s.erase(itt);
				}
			}

			ans += rmv;
		}
		cout << ans;
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000 //INF - 1e14
#define vi vector<ll>
#define PB push_back
#define mpl map<ll,ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) rin(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) printmat(mat,row,col);
#else
#define debug(x...)
#define matdeb(mat,row,col)
#endif
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result = 1; while (exp > 0) { if (exp % 2 == 1) result = (result * base) % M; base = (base * base) % M; exp = exp / 2; } return result; }
ll modInverse(ll A, ll M = MOD) { return fast_pow(A, M - 2, M); } // only when M is prime
ll aN = 1e6;
vi a(aN + 1);
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("intt.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
#endif
	ll test_cases = 1;
	// inp(test_cases);
	fer(test_case, 1, test_cases) {
		// cout << "Case #" << test_case << ": ";
		rin(n, m, k);
		set<ll> s;
		ll ans = 0;
		fer(i, 0, n - 1) {
			rin(p);
			a[p] = 1;
			s.insert(p);
		}
		if (k == 1) {
			cout << n;
			return 0;
		}
		debug(s);
		k--;
		// debug(n, m, k);;;
		// fer(i, 0, 30) {
		// 	debug(i, a[i]);
		// }
		ll cnt = 0;
		fer(i, 1, m) {
			cnt += a[i];
		}
		ll rmv = max(0LL, cnt - k);
		cnt -= rmv;
		ans += rmv;
		debug(rmv);
		if (rmv) {
			debug("called1");
			auto it = s.lower_bound(m);
			if (it != s.end() && *it != m)
				it--;
			fer(i, 1, rmv) {
				debug(*it);
				auto itt = it;
				it--;
				s.erase(itt);
			}
		}
		debug(s);
		debug(cnt, rmv);
		fer(i, 2, aN - m + 1) {
			if (s.find(i - 1) != s.end())
				cnt--;
			if (s.find(i + m - 1) != s.end())
				cnt++;
			ll rmv = max(0LL, cnt - k);
			cnt -= rmv;
			if (rmv) {
				debug("called");
				auto it = s.lower_bound(i + m - 1);
				if (it != s.end() && *it != i + m - 1)
					it--;
				fer(i, 1, rmv) {
					auto itt = it;
					it--;
					s.erase(itt);
				}
			}
			if (rmv) {
				debug(i, rmv, ans, cnt);
			}
			debug(s);
			ans += rmv;
			if (i == 40)
				break;
		}
		debug(ans);
		cout << ans;
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll ,ll >
#define vi          vector<ll int>
#define vii         vector<pii>
#define mi          map<ll int,ll int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        10000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        2000000

using namespace std;

void solve()
{
	ll n,m,k;
	cin>>n>>m>>k;
	vi v(n);
	take;
	sort(v.begin(),v.end());
	ll fka=v[n-1];
	ll z=0;
	ll c=0;
	mi mm;
	ll ans=0;
	for(ll i=0;i<n;i++) mm[v[i]]++;
	for(ll i=0;i<n;i++)
	{
		if(v[i]<=m)
		{
			z=i;
			c++;
			if(c==k)
			{
			//	v[i]=0;
				mm[v[i]]--;
				c--;
				ans++;
			}
		}
	}

	for(ll i=m+1;i<=fka;i++)
	{

		c=c+mm[i]-mm[i-m];
		if(c>=k)
		{
			ll t=c-(k-1);
			ans=ans+t;
			c=k-1;
			mm[i]=mm[i]-t;

		}

	}
	cout<<ans<<endl;
}
int main()
    {
       ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t;
        t=1;
       // sieve();
   //  cin>>t;
        while(t--)
        solve();
    }


#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll ,ll >
#define vi          vector<ll int>
#define vii         vector<pii>
#define mi          map<ll int,ll int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        10000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        2000000

using namespace std;

void solve()
{
	ll n,m,k;
	cin>>n>>m>>k;
	vi v(n);
	take;
	sort(v.begin(),v.end());
	ll fka=v[n-1];
	ll z=0;
	ll c=0;
	mi mm;
	ll ans=0;
	for(ll i=0;i<n;i++) mm[v[i]]++;
	for(ll i=0;i<n;i++)
	{
		if(v[i]<=m)
		{
			z=i;
			c++;
			if(c==k)
			{
				v[i]=0;
				mm[v[i]]--;
				c--;
				ans++;
			}
		}
	}

	for(ll i=m+1;i<=fka;i++)
	{

		c=c+mm[i]-mm[i-m];
		if(c>=k)
		{
			ll t=c-(k-1);
			ans=ans+t;
			mm[i]=mm[i]-t;

		}

	}
	cout<<ans<<endl;
}
int main()
    {
       ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t;
        t=1;
       // sieve();
   //  cin>>t;
        while(t--)
        solve();
    }


#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll ,ll >
#define vi          vector<ll int>
#define vii         vector<pii>
#define mi          map<ll int,ll int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        10000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        2000000

using namespace std;

void solve()
{
	ll n,m,k;
	cin>>n>>m>>k;
	vi v(n);
	take;
	sort(v.begin(),v.end());
	ll fka=v[n-1];
	ll z=0;
	ll c=0;
	mi mm;
	ll ans=0;
	for(ll i=0;i<n;i++) mm[v[i]]++;
	for(ll i=0;i<n;i++)
	{
		if(v[i]<=m)
		{
			z=i;
			c++;
			if(c==k)
			{
				v[i]=0;
				mm[v[i]]--;
				c--;
				ans++;
			}
		}
	}

	for(ll i=m+1;i<=fka;i++)
	{

		c=c+mm[i]-mm[i-m];
		if(c>=k)
		{
			ll t=c-(k-1);
			ans=ans+t;
			c=k-1;
			mm[i]=mm[i]-t;

		}

	}
	cout<<ans<<endl;
}
int main()
    {
       ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t;
        t=1;
       // sieve();
   //  cin>>t;
        while(t--)
        solve();
    }


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n);
    for(auto &i: a) cin>>i;
    if(k==1)
    {
        cout<<n<<"\n";
        return 0;
    }
    sort(a.begin(),a.end());
    vector<ll> ans;
    for(auto i: a)
    {
        if(ans.size()<k-1 or i-ans[ans.size()-1-(k-1)+1]>=m)
        ans.push_back(i);
    }
    cout<<n-ans.size()<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n);
    for(auto &i: a) cin>>i;
    sort(a.begin(),a.end());
    ll ans=0,x=a[0],c=1;
    for(ll i=1;i<n;i++)
    {
        if(a[i]-x<m) c++;
        else
        {
            ans+=max(0ll,c-k+1);
            c=1;
            x=a[i];
        }
    }
    ans+=max(0ll,c-k+1);
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;

//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;

/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
   // cin>>TESTS;
    while(TESTS--){
        int n,m,k;
        cin>>n>>m>>k;
        si s;
        for(int i=0;i<n;i++){
          int x;
          cin>>x;
          s.insert(x);
        }
       // sort(all(v));
        int ans=0;
        int time=1;
        int alarms=0;
        int i=0;
        set<int>t;
        while(time<=m&&s.size()){
           auto ip=s.begin();
           if(*ip==time){
            alarms++;
           if(alarms==k){
             alarms--;
             ans++;
             s.erase(ip);
           }else{
            t.insert(*ip);
            s.erase(ip);
           }
         }
           time++;
        }
        //cout<<ans<<endl;
       int first=1;
       int second=m+1;

       while(s.size()){
         if(t.size()){
           auto it1=t.begin();
           if(first==*it1){
            alarms--;
            t.erase(it1);
           }
          }
          auto it2=s.begin();
           if(second==*it2){
            alarms++;
           if(alarms==k){
            ans++;
            alarms--;
            s.erase(it2);
           }else{
            t.insert(*it2);
            s.erase(it2);
           }
         }
           first++;
           second++;
       }
       cout<<ans<<endl;
   }
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;

//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;

/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
   // cin>>TESTS;
    while(TESTS--){
        int n,m,k;
        cin>>n>>m>>k;
        si s;
        for(int i=0;i<n;i++){
          int x;
          cin>>x;
          s.insert(x);
        }
       // sort(all(v));
        int ans=0;
        int time=1;
        int alarms=0;
        int i=0;
        set<int>t;
        while(time<=m&&s.size()){
           auto ip=s.begin();
           if(*ip==time){
            alarms++;
           if(alarms==k){
             alarms--;
             ans++;
             s.erase(ip);
           }else{
            t.insert(*ip);
            s.erase(ip);
           }
         }
           time++;
        }
        //cout<<ans<<endl;
       int first=2;
       int second=m+2;
       if(*t.begin()==1){
        t.erase(t.begin());
        alarms--;
      }
       while(s.size()){
         if(t.size()){
           auto it1=t.begin();
           if(first==*it1){
            alarms--;
            t.erase(it1);
           }
          }
          auto it2=s.begin();
           if(second==*it2){
            alarms++;
           if(alarms==k){
            ans++;
            alarms--;
            s.erase(it2);
           }else{
            t.insert(*it2);
            s.erase(it2);
           }
         }
           first++;
           second++;
       }
       cout<<ans<<endl;
   }
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;

//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;

/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
   // cin>>TESTS;
    while(TESTS--){
        int n,m,k;
        cin>>n>>m>>k;
        si s;
        for(int i=0;i<n;i++){
          int x;
          cin>>x;
          s.insert(x);
        }
       // sort(all(v));
        int ans=0;
        int time=1;
        int alarms=0;
        int i=0;
        set<int>t;
        while(time<=m&&s.size()){
           auto ip=s.begin();
           if(*ip==time){
            alarms++;
           if(alarms==k){
             alarms--;
             ans++;
             s.erase(ip);
           }else{
            t.insert(*ip);
            s.erase(ip);
           }
         }
           time++;
        }
        //cout<<ans<<endl;
       int first=2;
       int second=m+1;
       if(*t.begin()==1){
        t.erase(t.begin());
        alarms--;
      }
       while(s.size()){
         if(t.size()){
           auto it1=t.begin();
           if(first==*it1){
            alarms--;
            t.erase(it1);
           }
          }
          auto it2=s.begin();
           if(second==*it2){
            alarms++;
           if(alarms==k){
            ans++;
            alarms--;
            s.erase(it2);
           }else{
            t.insert(*it2);
            s.erase(it2);
           }
         }
           first++;
           second++;
       }
       cout<<ans<<endl;
   }
}


// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroint-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 998244353
#define mp make_pair
#define ff first
#define ss second
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (int)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()
#define sp(a) setprecision(a)
#define rz resize
#define ld long double
#define inf 1e18
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define eb emplace_back
#define vvlli vector<vector<ll> >
#define vlli vector<ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vstr vector<string>
#define vvstr vector<vector<string> >
const double pi = acos(-1);
ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}

using namespace std;

ll MX=1e6+1;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int cnt=0,n,m,k,ans=0;
    cin>>n>>m>>k;
    vector<bool> a(MX);
    f(i,0,n)
    {
        int time;
        cin>>time;
        a[time]=1;
    }
    if(n<k)
        cout<<"0\n";
    else
    {
        f(i,1,m+1)
        {
            if(a[i])
            {
                if(cnt==k-1)
                    ans++,a[i]=0;
                else
                    cnt++;
            }
        }
        f(i,m+1,MX-m+1)
        {
            if(a[i-1]==1)
                cnt--;
            if(a[i+m-1]==1)
            {
                if(cnt==k-1)
                    ans++,a[i]=0;
                else
                    cnt++;
            }
        }
        cout<<ans<<"\n";
    }
}


// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroint-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 998244353
#define mp make_pair
#define ff first
#define ss second
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (int)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()
#define sp(a) setprecision(a)
#define rz resize
#define ld long double
#define inf 1e18
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define eb emplace_back
#define vvlli vector<vector<ll> >
#define vlli vector<ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vstr vector<string>
#define vvstr vector<vector<string> >
const double pi = acos(-1);
ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}

using namespace std;

ll MX=1e6+1;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int cnt=0,n,m,k,ans=0;
    cin>>n>>m>>k;
    // m--;
    vector<bool> a(MX);
    f(i,0,n)
    {
        int time;
        cin>>time;
        a[time]=1;
    }
    if(n<k)
        cout<<"0\n";
    else
    {
        f(i,1,m+1)
        {
            if(a[i])
            {
                if(cnt==k-1)
                {
                    // cout<<i<<"\n";
                    ans++,a[i]=0;
                }
                else
                    cnt++;
            }
        }
        // cout<<cnt<<"\n";
        f(i,2,MX-m+1)
        {
            if(a[i-1]==1)
                cnt--;
            if(a[i+m-1]==1)
            {
                if(cnt==k-1)
                {
                    // cout<<i<<"\n";
                    ans++,a[i+m-1]=0;
                }
                else
                    cnt++;
            }
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
#include<queue>
#include<stack>

using namespace std;

const int M = 1e6 + 5;
int a[M];

int main() {

	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	for(int i=0; i<n; i++) scanf("%d",&a[i]);

	if(k == 1) {
		printf("%d\n",n);
		return 0;
	}

	sort(a,a+n);

	queue<int> q;
	int ans = 0;

	for(int i=0; i<n; i++) {
		while(q.size() && a[i] - q.front() >= m )
			q.pop();

		if(q.size() >= k-1)
			ans++;
		else
			q.push(a[i]);

	}

	printf("%d\n",ans);
}


#include<bits/stdc++.h>
#include<queue>

using namespace std;

const int M = 1e6 + 5;
int a[M];

int main() {

	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);

	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	sort(a,a+n);

	queue<int>q;

	int i=0,ans = 0;
	while(n--) {
		if(q.size() + 1 < k)
			q.push(a[i]);
		else
		{
			while(!q.empty()) {
				int t = q.front();
				if(a[i] + 1 - t <= m) {
					ans++;
					break;
				} else {
					q.push(a[i]);
					break;
				}
			}
		}
//		printf("%d\n",q.front());
		i++;
	}

	printf("%d\n",ans);
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>

using namespace std;

#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   rush()        int T;scanf("%d",&T);while(T--)
#define   debug         puts("debug")

typedef   pair<int,int> P;

const int   M = 2e5+50;
const int mod = 1e9+7;
const int inf = 1e9;

int a[M];

int main() {

	int n,m,k,ans = 0;
	scanf("%d %d %d",&n,&m,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	sort(a,a+n);

	queue<int> q;
	for(int i=0;i<n;i++) {
		while(q.size() && a[i] - q.front() >= m) q.pop();

		if(q.size() >= k-1)
			ans++;
		else
			q.push(a[i]);
	}

	printf("%d\n",ans);

	return 0;
}

/*
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
*/


 #include<bits/stdc++.h>
#include<queue>

using namespace std;

const int M = 1e6 + 5;
int a[M];

int main() {

	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);

	for(int i=0;i<n;i++) scanf("%d",&a[i]);

	if(k == 1) {
		printf("%d\n",n);
		return 0;
	}

	sort(a,a+n);

	queue<int>q;

	int i=0,ans = 0;
	while(n--) {
		if(q.size() + 1 < k)
			q.push(a[i]);
		else
		{
			while(!q.empty()) {
				int t = q.front();
				if(a[i] + 1 - t <= m) {
					ans++;
					break;
				} else {
					q.push(a[i]);
					break;
				}
			}
		}
//		printf("%d\n",q.front());
		i++;
	}

	printf("%d\n",ans);
}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)

using namespace std;

int n, m, k;
vector<int> a;
bitset<200000> b;

int main() {
	cin >> n >> m >> k;
	a.resize(n, -1);
	rep(i, 0, n) cin >> a[i];
	sort(a.begin(), a.end());

	int L = 0, R = 0;
	int ans = 0;
	int cnt = 1;
	while(R < n) {
		while (a[R] - a[L] >= m) {
			if (!b[L]) cnt--;
			L++;
		}
		if (cnt == k) {
			cnt--, ans++;
			b[R] = true;
		}
		R++, cnt++;
	}

	cout << ans << '\n';
}


#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)

using namespace std;

int n, m, k;
vector<int> a;
bitset<200000> b;

int main() {
	cin >> n >> m >> k;
	a.resize(n, -1);
	rep(i, 0, n) cin >> a[i];
	sort(a.begin(), a.end());

	int L = 0, R = 0;
	int ans = 0;
	int cnt = 1;
	while(R < n) {
		if (a[R] - a[L] >= m) {
			if (!b[L]) cnt--;
			L++;
		}
		if (cnt == k) {
			cnt--, ans++;
			b[R] = true;
		}
		R++, cnt++;
	}

	cout << ans << '\n';
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <cmath>
#include <queue>
#define eps 1e-7
#define M 20005
#define N 1000005
#define SZ 200000002
using namespace std;
typedef long long ll;
const int inf = 1000000000;
ll mod = 1000000007LL;
ll mod2 = 998244353LL;
int n,m,k;
bool a[N];
int main() {
	cin>>n>>m>>k;
	memset(a, false, sizeof(a));
	for (int i = 1; i <= n; ++i) {
		int ai;
		scanf("%d", &ai);
		a[ai]=true;
	}
	int ans=0;
	deque<int> dq;
	for (int i = 1; i <= min(n,m); ++i) {
		if (a[i]) {
			dq.push_back(i);
		}
	}
//	cout<<dq.size()<<endl;
	for (int i = m; i <= n; ++i) {
		while(!dq.empty() && i-dq.front()>=m) {
			dq.pop_front();
		}
		int det=dq.size()-(k-1);
	//	cout<<"i="<<i<<" "<<dq.size()<<" "<<det<<endl;
		if (det>0) {
			for (int j = 1; j <= det; ++j) {
				dq.pop_back();
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <cmath>
#include <queue>
#define eps 1e-7
#define M 20005
#define N 1000005
#define SZ 200000002
using namespace std;
typedef long long ll;
const int inf = 1000000000;
ll mod = 1000000007LL;
ll mod2 = 998244353LL;
int n,m,k;
bool a[N];
int main() {
	cin>>n>>m>>k;
	memset(a, false, sizeof(a));
	for (int i = 1; i <= n; ++i) {
		int ai;
		scanf("%d", &ai);
		a[ai]=true;
	}
	int ans=0;
	deque<int> dq;
	for (int i = 1; i <= m; ++i) {
		if (a[i]) {
			dq.push_back(i);
		}
	}
//	cout<<dq.size()<<endl;
	for (int i = m; i <= 1000001; ++i) {
		while(!dq.empty() && i-dq.front()>=m) {
			dq.pop_front();
		}
		int det=dq.size()-(k-1);
	//	cout<<"i="<<i<<" "<<dq.size()<<" "<<det<<endl;
		if (det>0) {
			for (int j = 1; j <= det; ++j) {
				dq.pop_back();
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <cmath>
#include <queue>
#define eps 1e-7
#define M 20005
#define N 1000005
#define SZ 200000002
using namespace std;
typedef long long ll;
const int inf = 1000000000;
ll mod = 1000000007LL;
ll mod2 = 998244353LL;
int n,m,k;
bool a[N];
int main() {
	cin>>n>>m>>k;
	memset(a, false, sizeof(a));
	for (int i = 1; i <= n; ++i) {
		int ai;
		scanf("%d", &ai);
		a[ai]=true;
	}
	int ans=0;
	deque<int> dq;
//	cout<<dq.size()<<endl;
	for (int i = 1; i <= 1000001; ++i) {
		if (a[i]) {
			dq.push_back(i);
		}
		while(!dq.empty() && i-dq.front()>=m) {
			dq.pop_front();
		}
		if (i>=m) {
			int det=dq.size()-(k-1);
			if (det>0) {
				for (int j =1 ; j <= det; ++j) {
					dq.pop_back();
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int t,n,q;
long long ans;
const int MaxN=1e5*3+4;
int a[MaxN];
 void erase(int i)
{
    if (i==0 || i==n+1) return;
    if (a[i-1]<a[i] && a[i]>a[i+1]) ans-=a[i];
    if (a[i-1]>a[i] && a[i]<a[i+1]) ans+=a[i];
}
 void insert(int i)
{
    if (i==0 || i==n+1) return;
    if (a[i-1]<a[i] && a[i]>a[i+1]) ans+=a[i];
    if (a[i-1]>a[i] && a[i]<a[i+1]) ans-=a[i];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while (t--)
    {
        ans=0;
        cin>>n>>q;
        for (int i=1; i<=n; i++)
            cin>>a[i];
        a[0]=-1;
        a[n+1]=-1;
        for (int i=1; i<=n; i++)
        {
            insert(i);
        }
        cout<<ans<<endl;
        while (q--)
        {
            int l,r;
            cin>>l>>r;
            erase(l-1);
            erase(l);
            erase(l+1);
            if (l!=r)
            {
                if (r-1 != l+1 && r-1 != l) erase(r-1);
                if (r!=l+1) erase(r);
                erase(r+1);
            }
            swap(a[l],a[r]);
            insert(l-1);
            insert(l);
            insert(l+1);
            if (l!=r)
            {
                if (r-1!=l+1 && r-1!=l) insert(r-1);
                if (r!=l+1) insert(r);
                insert(r+1);
            }
            cout<<ans<<endl;
        }
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
int t,n,q;
long long ans;
const int MaxN=1e5*3+4;
long long a[MaxN];
void inline erase(int i)
{
    if (i==0 || i==n+1) return;
    if (a[i-1]<a[i] && a[i]>a[i+1]) ans-=a[i];
    if (a[i-1]>a[i] && a[i]<a[i+1]) ans+=a[i];
}
void inline insert(int i)
{
    if (i==0 || i==n+1) return;
    if (a[i-1]<a[i] && a[i]>a[i+1]) ans+=a[i];
    if (a[i-1]>a[i] && a[i]<a[i+1]) ans-=a[i];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while (t--)
    {
        ans=0;
        cin>>n>>q;
        for (int i=1; i<=n; i++)
            cin>>a[i];
        a[0]=a[1]-1;
        a[n+1]=a[n]-1;
        for (int i=1; i<=n; i++)
        {
            if (a[i-1]<a[i] && a[i]>a[i+1]) ans+=a[i];
            if (a[i-1]>a[i] && a[i]<a[i+1]) ans-=a[i];
        }
        cout<<ans<<endl;
        while (q--)
        {
            int l,r;
            cin>>l>>r;
            erase(l-1);
            erase(l);
            erase(l+1);
            if (l!=r)
            {
                if (r-1 != l+1 && r-1 != l) erase(r-1);
                if (r!=l+1) erase(r);
                erase(r+1);
            }
            swap(a[l],a[r]);
            insert(l-1);
            insert(l);
            insert(l+1);
            if (l!=r)
            {
                if (r-1!=l+1 && r-1!=l) insert(r-1);
                if (r!=l+1) insert(r);
                insert(r+1);
            }
            cout<<ans<<endl;
        }
    }
}


#include <bits/stdc++.h>
/*
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 10e9
#define MCOMP 998244353
#define int long long

int a[1000000+5];

int n;

int ans=0;

inline void insert(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans+=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans-=a[i];
}

inline void erase(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans-=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans+=a[i];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	ll t;
	cin>>t;
	while(t--){

	}

	return 0;
}*/

using namespace std;

#define int long long

int a[1000000+5];

int n;

int ans=0;

inline void insert(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans+=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans-=a[i];
}

inline void erase(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans-=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans+=a[i];
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while (t--)
    {
        int q;
        cin>>n>>q;
        for (int i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        a[0]=-1;
        a[n+1]=-1;
        ans=0;
        for (int i=1; i<=n; i++)
        {
            if (a[i-1]<a[i]&&a[i]>a[i+1]) ans+=a[i];
            if (a[i-1]>a[i]&&a[i]<a[i+1]) ans-=a[i];
        }
        cout<<ans<<'\n';
        while (q--)
        {
            int l,r;
            cin>>l>>r;
            erase(l-1);
            erase(l);
            erase(l+1);
            if (l!=r)
            {
                if (r-1!=l+1&&r-1!=l) erase(r-1);
                if (r!=l+1) erase(r);
                erase(r+1);
            }
            swap(a[l],a[r]);
            insert(l-1);
            insert(l);
            insert(l+1);
            if (l!=r)
            {
                if (r-1!=l+1&&r-1!=l) insert(r-1);
                if (r!=l+1) insert(r);
                insert(r+1);
            }
            cout<<ans<<'\n';
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 10e9
#define MCOMP 998244353

int a[1000000+5];

int n;

int ans=0;

inline void insert(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans+=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans-=a[i];
}

inline void erase(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans-=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans+=a[i];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	ll t;
	cin>>t;
	while(t--){
		int q;
        cin>>n>>q;
        for (int i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        a[0]=-1;
        a[n+1]=-1;
        ans=0;
        for (int i=1; i<=n; i++)
        {
            if (a[i-1]<a[i]&&a[i]>a[i+1]) ans+=a[i];
            if (a[i-1]>a[i]&&a[i]<a[i+1]) ans-=a[i];
        }
        cout<<ans<<'\n';
        while (q--)
        {
            int l,r;
            cin>>l>>r;
            erase(l-1);
            erase(l);
            erase(l+1);
            if (l!=r)
            {
                if (r-1!=l+1&&r-1!=l) erase(r-1);
                if (r!=l+1) erase(r);
                erase(r+1);
            }
            swap(a[l],a[r]);
            insert(l-1);
            insert(l);
            insert(l+1);
            if (l!=r)
            {
                if (r-1!=l+1&&r-1!=l) insert(r-1);
                if (r!=l+1) insert(r);
                insert(r+1);
            }
            cout<<ans<<'\n';
        }
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 10e9
#define MCOMP 998244353
#define int long long

int a[1000000+5];

int n;

int ans=0;

inline void insert(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans+=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans-=a[i];
}

inline void erase(int i)
{
    if (i==0||i==n+1) return;
    if (a[i-1]<a[i]&&a[i]>a[i+1]) ans-=a[i];
    if (a[i-1]>a[i]&&a[i]<a[i+1]) ans+=a[i];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	ll t;
	cin>>t;
	while(t--){
		int q;
        cin>>n>>q;
        for (int i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        a[0]=-1;
        a[n+1]=-1;
        ans=0;
        for (int i=1; i<=n; i++)
        {
            if (a[i-1]<a[i]&&a[i]>a[i+1]) ans+=a[i];
            if (a[i-1]>a[i]&&a[i]<a[i+1]) ans-=a[i];
        }
        cout<<ans<<'\n';
        while (q--)
        {
            int l,r;
            cin>>l>>r;
            erase(l-1);
            erase(l);
            erase(l+1);
            if (l!=r)
            {
                if (r-1!=l+1&&r-1!=l) erase(r-1);
                if (r!=l+1) erase(r);
                erase(r+1);
            }
            swap(a[l],a[r]);
            insert(l-1);
            insert(l);
            insert(l+1);
            if (l!=r)
            {
                if (r-1!=l+1&&r-1!=l) insert(r-1);
                if (r!=l+1) insert(r);
                insert(r+1);
            }
            cout<<ans<<'\n';
        }
	}

	return 0;
}


#include <bits/stdc++.h>
#include <cstdio>

typedef long long ll;
const int INF=1e9;

using namespace std;

void solve(vector<ll> &vals){
	ll val=0;
	bool flag=1;
	for(int i=0;i<(vals.size()-1);i++){
		if(flag==1){
			if(vals[i]>vals[i+1]) {val+=vals[i];flag=0;}
		}
		else{
			if(vals[i]<vals[i+1]) {val-=vals[i];flag=1;}
		}
	}
	if(vals.size()==1) val=vals[0];
	else if(flag==1 && vals[vals.size()-1]>vals[vals.size()-2])val+=vals[vals.size()-1];
	cout<<val<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin>>t;
	while(t--){
		ll n,q;
		cin>>n>>q;
		vector<ll> vals(n);
		for(auto &x:vals) cin>>x;
		vector<vector<ll>> swaps(q);
		for(int i=0;i<q;i++){
			ll x,y;
			cin>>x>>y;
			swaps[i]={x,y};
		}
		solve(vals);
		for(int i=0;i<q;i++){
			ll x=swaps[i][0];
			ll y=swaps[i][1];
			x--;y--;
			ll temp=vals[x];
			vals[x]=vals[y];
			vals[y]=temp;
			solve(vals);
		}
	}

	return 0;
}


//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli n,q,ans;
vector<lli> arr(300009);
int stat[300009];
void check(lli i){
   lli left,right;
   left=i-1;
   right=i+1;
   if(i==0){
    if(arr[right]<arr[i]){
        stat[i]=1;
        ans+=arr[i];
    }
    else if(arr[right]>arr[i]){
        stat[i]=-1;
    }
    else{
        stat[i]=0;
    }
   }
   else if(i==n-1){
    if(arr[left]<arr[i]){
        stat[i]=1;
        ans+=arr[i];
    }
    else if(arr[left]>arr[i]){
        stat[i]=-1;
    }
    else{
        stat[i]=0;
    }
   }
   else{
    if(arr[left]<arr[i]&&arr[right]<arr[i]){
        stat[i]=1;
        ans+=arr[i];
    }
    else if(arr[left]>arr[i]&&arr[right]>arr[i]){
        stat[i]=-1;
        ans-=arr[i];
    }
    else{
        stat[i]=0;
    }
   }
}
void decheck(lli i){
if(i==0&&stat[i]==1){
    ans-=arr[i];
}
else if(i==n-1&&stat[i]==1){
    ans-=arr[i];
}
else if(i>0&&i<n-1){
    if(stat[i]==-1){
        ans+=arr[i];
    }
    else if(stat[i]==1){
        ans-=arr[i];
    }
}
}
void makeit(lli l,lli r){
    map<lli,bool> usingit;
if(l-1>=0&&l-1<n){
    if(!usingit[l-1]){
        usingit[l-1]=1;
        decheck(l-1);
    }
}
if(l>=0&&l<n){
    if(!usingit[l]){
        usingit[l]=1;
        decheck(l);
    }
}
if(l+1>=0&&l+1<n){
    if(!usingit[l+1]){
        usingit[l+1]=1;
        decheck(l+1);
    }
}
if(r-1>=0&&r-1<n){
    if(!usingit[r-1]){
        usingit[r-1]=1;
        decheck(r-1);
    }
}
if(r>=0&&r<n){
    if(!usingit[r]){
        usingit[r]=1;
        decheck(r);
    }
}
if(r+1>=0&&r+1<n){
    if(!usingit[r+1]){
        usingit[r+1]=1;
        decheck(r+1);
    }
}
}
void fuckit(lli l,lli r){
    map<lli,bool> usingit;
if(l-1>=0&&l-1<n){
    if(!usingit[l-1]){
        usingit[l-1]=1;
        check(l-1);
    }
}
if(l>=0&&l<n){
    if(!usingit[l]){
        usingit[l]=1;
        check(l);
    }
}
if(l+1>=0&&l+1<n){
    if(!usingit[l+1]){
        usingit[l+1]=1;
        check(l+1);
    }
}
if(r-1>=0&&r-1<n){
    if(!usingit[r-1]){
        usingit[r-1]=1;
        check(r-1);
    }
}
if(r>=0&&r<n){
    if(!usingit[r]){
        usingit[r]=1;
        check(r);
    }
}
if(r+1>=0&&r+1<n){
    if(!usingit[r+1]){
        usingit[r+1]=1;
        check(r+1);
    }
}
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
lli t;
cin>>t;
while(t--){
    cin>>n>>q;
    memset(stat,0,sizeof(stat));
    ans=0;
    for(lli i=0;i<n;i++){
        cin>>arr[i];
    }
    for(lli i=0;i<=n-1;i++){
            check(i);
    }
    cout<<ans<<endl;
    while(q--){
        lli l,r;
        cin>>l>>r;
        l--;r--;
        makeit(l,r);
        lli temp=arr[l];
        arr[l]=arr[r];
        arr[r]=temp;
        fuckit(l,r);
        cout<<ans<<endl;
}
}
return 0;
}


//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli n,q,ans;
vector<lli> arr(300009);
int stat[300009];
void check(lli i){
   lli left,right;
   left=i-1;
   right=i+1;
   if(i==0){
    if(arr[right]<arr[i]){
        stat[i]=1;
        ans+=arr[i];
    }
    else if(arr[right]>arr[i]){
        stat[i]=-1;
    }
    else{
        stat[i]=0;
    }
   }
   else if(i==n-1){
    if(arr[left]<arr[i]){
        stat[i]=1;
        ans+=arr[i];
    }
    else if(arr[left]>arr[i]){
        stat[i]=-1;
    }
    else{
        stat[i]=0;
    }
   }
   else{
    if(arr[left]<arr[i]&&arr[right]<arr[i]){
        stat[i]=1;
        ans+=arr[i];
    }
    else if(arr[left]>arr[i]&&arr[right]>arr[i]){
        stat[i]=-1;
        ans-=arr[i];
    }
    else{
        stat[i]=0;
    }
   }
}
void decheck(lli i){
if(i==0&&stat[i]==1){
    ans-=arr[i];
   // cout<<"cutting : "<< -1*arr[i]<<endl;
}
else if(i==n-1&&stat[i]==1){
    ans-=arr[i];
   // cout<<"cutting : "<< -1*arr[i]<<endl;
}
else if(i>0&&i<n-1){
    if(stat[i]==-1){
        ans+=arr[i];
       // cout<<"cutting : "<< -1*arr[i]<<endl;
    }
    else if(stat[i]==1){
        ans-=arr[i];
       // cout<<"cutting : "<<arr[i]<<endl;
    }
}
}
void makeit(lli l,lli r){
    vector<bool> usingit(300009,0);
if(l-1>=0&&l-1<n){
    if(!usingit[l-1]){
        usingit[l-1]=1;
        decheck(l-1);
    }
}
if(l>=0&&l<n){
    if(!usingit[l]){
        usingit[l]=1;
        decheck(l);
    }
}
if(l+1>=0&&l+1<n){
    if(!usingit[l+1]){
        usingit[l+1]=1;
        decheck(l+1);
    }
}
if(r-1>=0&&r-1<n){
    if(!usingit[r-1]){
        usingit[r-1]=1;
        decheck(r-1);
    }
}
if(r>=0&&r<n){
    if(!usingit[r]){
        usingit[r]=1;
        decheck(r);
    }
}
if(r+1>=0&&r+1<n){
    if(!usingit[r+1]){
        usingit[r+1]=1;
        decheck(r+1);
    }
}
}
void fuckit(lli l,lli r){
vector<bool> usingit(300009,0);
if(l-1>=0&&l-1<n){
    if(!usingit[l-1]){
        usingit[l-1]=1;
        check(l-1);
    }
}
if(l>=0&&l<n){
    if(!usingit[l]){
        usingit[l]=1;
        check(l);
    }
}
if(l+1>=0&&l+1<n){
    if(!usingit[l+1]){
        usingit[l+1]=1;
        check(l+1);
    }
}
if(r-1>=0&&r-1<n){
    if(!usingit[r-1]){
        usingit[r-1]=1;
        check(r-1);
    }
}
if(r>=0&&r<n){
    if(!usingit[r]){
        usingit[r]=1;
        check(r);
    }
}
if(r+1>=0&&r+1<n){
    if(!usingit[r+1]){
        usingit[r+1]=1;
        check(r+1);
    }
}
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
lli t;
cin>>t;
while(t--){
    cin>>n>>q;
    memset(stat,0,sizeof(stat));
    ans=0;
    for(lli i=0;i<n;i++){
        cin>>arr[i];
    }
    for(lli i=0;i<=n-1;i++){
            check(i);
           //cout<<stat[i]<<" ";
            //cout<<"added : "<<(stat[i])*arr[i]<<endl;
    }
   // cout<<endl;
    cout<<ans<<endl;
    while(q--){
        lli l,r;
        cin>>l>>r;
        l--;r--;
        makeit(l,r);
       // for(lli i=0;i<=n-1;i++){
           // cout<<stat[i]<<" ";
           // cout<<"arr[i] : "<<(stat[i])*arr[i]<<endl;
   // }
    //cout<<"answer after decheck : "<<ans<<endl;
   // cout<<endl<<endl;
        lli temp=arr[l];
        arr[l]=arr[r];
        arr[r]=temp;
        fuckit(l,r);
        //for(lli i=0;i<=n-1;i++){
          //  cout<<stat[i]<<" ";
          //  cout<<"arr[i] : "<<(stat[i])*arr[i]<<endl;
    //}
        cout<<ans<<endl;
}
}
return 0;
}