Link to this code: https://cses.fi/paste/74d273db0c74039e225cdc/
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvs = vector<vs>;
using vvb = vector<vb>;
using vvpi = vector<vpi>;

#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second
#define endl "\n"

#ifndef LOCAL
#define cerr if (false) cerr
#endif


void solve() {
    int N, M, K;
    cin >> N >> M >> K;
    vi applicants(N), apartments(M);
    for (auto& x : applicants)
        cin >> x;
    for (auto& x : apartments)
        cin >> x;
    sort(all(apartments));
    sort(all(applicants));
    int ans = 0, i = 0, j = 0;
    while (i < sz(applicants) && j < sz(apartments)) {
        if (abs(applicants[i] - apartments[j]) <= K) {
            ans++;
            i++;
            j++;
        } else if (apartments[j] < applicants[i])
            j++;
        else
            i++;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    solve();
}