#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
vector<int> t;
void update(int idx, int v, int val, int vl, int vr) {
    if (vl == vr)
        t[v] = max(t[v], val);
    else {
        int vm = (vl + vr) / 2;
        if (idx <= vm)
            update(idx, 2 * v + 1, val, vl, vm);
        else
            update(idx, 2 * v + 2, val, vm + 1, vr);
        t[v] = max(t[2 * v + 1], t[2 * v + 2]);
    }
}
int getmax(int v, int l, int r, int vl, int vr) {
    if (l <= vl && vr <= r)
        return t[v];
    if (l > vr || vl > r)
        return -1;
    int vm = (vl + vr) / 2;
    return max(getmax(2 * v + 1, l, r, vl, vm), getmax(2 * v + 2, l, r, vm + 1, vr));
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    t.resize(4 * n + 20);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        int x, y, z;
        for (int j = i; j < n; ++j) {
            tie(x, y, z) = q[j];
            if (x != get<0>(q[i]))
                break;
            int cur_max = -1;
            cur_max = getmax(0, y + 1, n + 4, 0, n);
            if (cur_max > z)
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            tie(x, y, z) = q[j];
            if (x != get<0>(q[i])) {
                i = j;
                break;
            }
            update(y, 0, z, 0, n);
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int get(int idx, vector<int> &f) {
    int res = 0;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            for (int z = get<1>(q[j]) + 1; z < n + 5; ++z)
            for (int z = 1; z <= n + 4 - get<1>(q[j]); ++z)
                cur_max = max(cur_max, maxes[z]);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            maxes[n + 5 - get<1>(q[j])] = max(maxes[get<1>(q[j])], get<2>(q[j]));
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int getmax(int idx, vector<int> &f) {
    int res = -1;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i)
        cin >> vc[i];
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], z);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            cur_max = getmax(n + 5 - (get<1>(q[j]) + 1), maxes);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            upd(n + 5 - get<1>(q[j]), get<2>(q[j]), maxes);
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int getmax(int idx, int val, vector<int> &f) {
    int res = -1;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            //for (int z = get<1>(q[j]) + 1; z < n + 5; ++z)
            for (int z = 1; z <= n + 5 - (get<1>(q[j]) + 1); ++z)
                cur_max = max(cur_max, maxes[z]);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            maxes[n + 5 - get<1>(q[j])] = max(maxes[n + 5 - get<1>(q[j])], get<2>(q[j]));
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int get(int idx, vector<int> &f) {
    int res = 0;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            for (int z = get<1>(q[j]) + 1; z < n + 5; ++z)
            for (int z = 1; z <= n + 4 - get<1>(q[j]); ++z)
                cur_max = max(cur_max, maxes[z]);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            maxes[n + 4 - get<1>(q[j])] = max(maxes[get<1>(q[j])], get<2>(q[j]));
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
vector<int> t;
void update(int idx, int v, int val, int vl, int vr) {
    if (vl == vr)
        t[v] = max(t[v], val);
    else {
        int vm = (vl + vr) / 2;
        if (idx <= vm)
            update(idx, 2 * v + 1, val, vl, vm);
        else
            update(idx, 2 * v + 2, val, vm + 1, vr);
        t[v] = max(t[2 * v + 1], t[2 * v + 2]);
    }
}
int getmax(int v, int l, int r, int vl, int vr) {
    if (l <= vl && vr <= r)
        return t[v];
    if (l > vr || vl > r)
        return -1;
    int vm = (vl + vr) / 2;
    return max(getmax(2 * v + 1, l, r, vl, vm), getmax(2 * v + 2, l, r, vm + 1, vr));
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    t.resize(4 * n + 20);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        int x, y, z;
        for (int j = i; j < n; ++j) {
            tie(x, y, z) = q[j];
            if (x != get<0>(q[i]))
                break;
            int cur_max = -1;
            cur_max = getmax(0, y + 1, n + 4, 0, n);
            if (cur_max > z)
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            tie(x, y, z) = q[j];
            if (x != get<0>(q[i])) {
                i = j;
                break;
            }
            update(y, 0, z, 0, n);
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int getmax(int idx, vector<int> &f) {
    int res = -1;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    vector<int> B;
    map<int, int> tob;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i)
        cin >> va[i];
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        B.push_back(vb[i]);
    }
    sort(B.begin(), B.end());
    B.erase(unique(B.begin(), B.end()), B.end());
    for (int i = 0; i < n; ++i)
        cin >> vc[i];
    for (auto &d : B)
        tob[d] = nb++;
    for (int i = 0; i < n; ++i)
        q[i] = make_tuple(va[i], tob[vb[i]], vc[i]);
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            cur_max = getmax(n + 5 - (get<1>(q[j]) + 1), maxes);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            upd(n + 5 - get<1>(q[j]), get<2>(q[j]), maxes);
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int getmax(int idx, vector<int> &f) {
    int res = -1;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    vector<int> B;
    map<int, int> tob;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i)
        cin >> va[i];
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        B.push_back(vb[i]);
    }
    sort(B.begin(), B.end());
    B.erase(unique(B.begin(), B.end()), B.end());
    for (int i = 0; i < n; ++i)
        cin >> vc[i];
    for (auto &d : B)
        tob[d] = nb++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(x, tob[y], z);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            cur_max = getmax(n + 5 - (get<1>(q[j]) + 1), maxes);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            upd(n + 5 - get<1>(q[j]), get<2>(q[j]), maxes);
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<tuple<int, int, int>> q;
    for (int i = 0; i < n; ++i) {
        int A, B, C;
        cin >> A >> B >> C;
        q.emplace_back(A, B, C);
        a.insert(A);
        b.insert(B);
        c.insert(C);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x, y, z;
        tie(x, y, z) = q[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            for (int z = get<1>(q[j]) + 1; z < n + 5; ++z)
                cur_max = max(cur_max, maxes[z]);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            maxes[get<1>(q[j])] = max(maxes[get<1>(q[j])], get<2>(q[j]));
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int get(int idx, vector<int> &f) {
    int res = 0;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            for (int z = get<1>(q[j]) + 1; z < n + 5; ++z)
            for (int z = 1; z <= n + 5 - get<1>(q[j]); ++z)
                cur_max = max(cur_max, maxes[z]);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            maxes[n + 5 - get<1>(q[j])] = max(maxes[get<1>(q[j])], get<2>(q[j]));
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int getmax(int idx, vector<int> &f) {
    int res = -1;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    vector<int> B;
    map<int, int> tob;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i)
        cin >> va[i];
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        B.push_back(vb[i]);
    }
    sort(B.begin(), B.end());
    B.erase(unique(B.begin(), B.end()), B.end());
    for (int i = 0; i < n; ++i)
        cin >> vc[i];
    for (auto &d : B)
        tob[d] = nb++;
    for (int i = 0; i < n; ++i)
        q[i] = make_tuple(va[i], tob[vb[i]], vc[i]);
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            cur_max = getmax(n + 5 - (get<1>(q[j]) + 1), maxes);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            upd(n + 5 - get<1>(q[j]), get<2>(q[j]), maxes);
        }
        if (i == pi)
            break;
    }
    cout << cnt << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void upd(int idx, int val, vector<int> &f) {
    for (; idx < f.size(); idx += (idx & (-idx)))
        f[idx] = max(f[idx], val);
}
int getmax(int idx, vector<int> &f) {
    int res = -1;
    for (; idx > 0; idx -= (idx & (-idx)))
        res = max(res, f[idx]);
    return res;
}
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> tob;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i)
        cin >> va[i];
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i)
        cin >> vc[i];
    for (auto &d : b)
        tob[d] = nb++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(x, tob[y], z);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            cur_max = getmax(n + 5 - (get<1>(q[j]) + 1), maxes);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            upd(n + 5 - get<1>(q[j]), get<2>(q[j]), maxes);
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            //for (int z = get<1>(q[j]) + 1; z < n + 5; ++z)
            for (int z = 0; z <= n + 4 - (get<1>(q[j]) + 1); ++z)
                cur_max = max(cur_max, maxes[z]);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            maxes[n + 4 - get<1>(q[j])] = max(maxes[n + 4 - get<1>(q[j])], get<2>(q[j]));
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡      КАК ЖЕ МНЕ НАДОЕЛА ЭТА ПРОГА ТУПАЯ ГОСПОДИ
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ﾉ
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
mt19937 gen(time(0));
bool IS_ONE_TEST = 1;
void solve() {
    int n;
    cin >> n;
    set<int> a, b, c;
    map<int, int> toa, tob, toc;
    int na = 1, nb = 1, nc = 1;
    vector<int> va(n), vb(n), vc(n);
    vector<tuple<int, int, int>> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> va[i];
        a.insert(va[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vb[i];
        b.insert(vb[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> vc[i];
        c.insert(vc[i]);
    }
    for (auto &d : a)
        toa[d] = na++;
    for (auto &d : b)
        tob[d] = nb++;
    for (auto &d : c)
        toc[d] = nc++;
    for (int i = 0; i < n; ++i) {
        int x = va[i], y = vb[i], z = vc[i];
        q[i] = make_tuple(toa[x], tob[y], toc[z]);
    }
    sort(q.rbegin(), q.rend());
    vector<int> maxes(n + 5);
    int cnt = 0;
    for (int i = 0; i < q.size();) {
        int pi = i;
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i]))
                break;
            int cur_max = -1;
            for (int z = get<1>(q[j]) + 1; z < n + 5; ++z)
                cur_max = max(cur_max, maxes[z]);
            if (cur_max > get<2>(q[j]))
                ++cnt;
        }
        for (int j = i; j < n; ++j) {
            if (get<0>(q[j]) != get<0>(q[i])) {
                i = j;
                break;
            }
            maxes[get<1>(q[j])] = max(maxes[get<1>(q[j])], get<2>(q[j]));
        }
        if (i == pi)
            break;
    }
    cout << cnt << endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    cout << fixed << setprecision(15);
    int t;
    if (IS_ONE_TEST)
        t = 1;
    else
        cin >> t;
    while (t-->0) {
        solve();
    }
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000
#define mod         1000000007
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s];
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2, 2, -2, -2, 1, -1, 1, -1};
int dc[]={1,-1,  1, -1, 2,  2,-2, -2};
int dr1[]={0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[]={-1,0, 1,-1, 0, 1, -1, 0,   1};
int dr2[]={0, 0, 1, -1};
int dc2[]={1,-1, 0,  0};
////////////////////////////
using namespace std;
#define ma 2000000

ll tree[ma*3];
vector<pair<ll,ll> >adj[ma];

void update(ll n,ll b,ll e,ll x,ll val)
{
    if(b==e)
    {
        tree[n]=max(val,tree[n]);
        return;
    }

    ll mid=(b+e)>>1,l=n*2,r=l+1;
    if(x<=mid)update(l,b,mid,x,val);
    else update(r,mid+1,e,x,val);
    tree[n]=max(tree[r],tree[l]);
}

ll query(ll n,ll b,ll e,ll x,ll y)
{
    if(b>y||e<x)return 0;

    if(b>=x&&e<=y)return tree[n];
    ll mid=(b+e)>>1,l=n*2,r=l+1;
    ll p=query(l,b,mid,x,y);
    ll p1=query(r,mid+1,e,x,y);
    return max(p,p1);
}

ll a[ma],b[ma],c[ma];

int main()
{
    ll n,i,j,x,y,z;
    while(cin>>n)
    {
        map<ll,ll>mp;
        vector<ll>v;
        for(i=1;i<=n;i++)
        {
            cin>>x>>y>>z;
            a[i]=x,b[i]=y,c[i]=z;
            v.pb(x);v.pb(y);
        }
        sort(v.begin(),v.end());
        ll cn=0;

        for(i=0;i<v.sz;i++)
        {
            if(mp[v[i]]==0)mp[v[i]]=++cn;
        }

        for(i=1;i<=n;i++)
        {
            a[i]=mp[a[i]],b[i]=mp[b[i]];
            adj[a[i]].pb(mk(b[i],c[i]));
        }

        ll ans=0;

        for(i=cn;i>=1;i--)
        {
            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll q=adj[i][j].ss;
                ll r=query(1,1,cn,p+1,cn);
                if(r>q)ans++;
            }

            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll p1=adj[i][j].ss;
                update(1,1,cn,p,p1);
            }
        }

        cout<<ans<<endl;

    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000
#define mod         1000000007
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s];
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2, 2, -2, -2, 1, -1, 1, -1};
int dc[]={1,-1,  1, -1, 2,  2,-2, -2};
int dr1[]={0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[]={-1,0, 1,-1, 0, 1, -1, 0,   1};
int dr2[]={0, 0, 1, -1};
int dc2[]={1,-1, 0,  0};
////////////////////////////
using namespace std;
#define ma 2000000

ll tree[ma*3];
vector<pair<ll,ll> >adj[ma];

void update(ll n,ll b,ll e,ll x,ll val)
{
    if(b==e)
    {
        tree[n]=max(val,tree[n]);
        return;
    }

    ll mid=(b+e)>>1,l=n*2,r=l+1;
    if(x<=mid)update(l,b,mid,x,val);
    else update(r,mid+1,e,x,val);
    tree[n]=max(tree[r],tree[l]);
}

ll query(ll n,ll b,ll e,ll x,ll y)
{
    if(b>y||e<x)return 0;

    if(b>=x&&e<=y)return tree[n];
    ll mid=(b+e)>>1,l=n*2,r=l+1;
    ll p=query(l,b,mid,x,y);
    ll p1=query(r,mid+1,e,x,y);
    return max(p,p1);
}

ll a[ma],b[ma],c[ma];

int main()
{
    ll n,i,j,x,y,z;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    while(cin>>n)
    {
        map<ll,ll>mp;
        vector<ll>v;
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
            v.pb(a[i]);
        }

        for(i=1;i<=n;i++)
        {
            cin>>b[i];
            v.pb(b[i]);
        }

        for(i=1;i<=n;i++)cin>>c[i];
        sort(v.begin(),v.end());
        ll cn=0;

        for(i=0;i<v.sz;i++)
        {
            if(mp[v[i]]==0)mp[v[i]]=++cn;
        }

        for(i=1;i<=n;i++)
        {
            a[i]=mp[a[i]],b[i]=mp[b[i]];
            adj[a[i]].pb(mk(b[i],c[i]));
        }

        ll ans=0;

        for(i=cn;i>=1;i--)
        {
            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll q=adj[i][j].ss;
                ll r=query(1,1,cn,p+1,cn);
                if(r>q)ans++;
            }

            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll p1=adj[i][j].ss;
                update(1,1,cn,p,p1);
            }
        }

        cout<<ans<<endl;

    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000
#define mod         1000000007
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s];
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2, 2, -2, -2, 1, -1, 1, -1};
int dc[]={1,-1,  1, -1, 2,  2,-2, -2};
int dr1[]={0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[]={-1,0, 1,-1, 0, 1, -1, 0,   1};
int dr2[]={0, 0, 1, -1};
int dc2[]={1,-1, 0,  0};
////////////////////////////
using namespace std;
#define ma 2000000

ll tree[ma*3];
vector<pair<ll,ll> >adj[ma];

void update(ll n,ll b,ll e,ll x,ll val)
{
    if(b==e)
    {
        tree[n]=max(val,tree[n]);
        return;
    }

    ll mid=(b+e)>>1,l=n*2,r=l+1;
    if(x<=mid)update(l,b,mid,x,val);
    else update(r,mid+1,e,x,val);
    tree[n]=max(tree[r],tree[l]);
}

ll query(ll n,ll b,ll e,ll x,ll y)
{
    if(b>y||e<x)return 0;

    if(b>=x&&e<=y)return tree[n];
    ll mid=(b+e)>>1,l=n*2,r=l+1;
    ll p=query(l,b,mid,x,y);
    ll p1=query(r,mid+1,e,x,y);
    return max(p,p1);
}

ll a[ma],b[ma],c[ma];

int main()
{
    ll n,i,j,x,y,z;
    while(cin>>n)
    {
        map<ll,ll>mp;
        vector<ll>v;
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
            v.pb(a[i]);
        }

        for(i=1;i<=n;i++)
        {
            cin>>b[i];
            v.pb(b[i]);
        }

        for(i=1;i<=n;i++)cin>>c[i];
        sort(v.begin(),v.end());
        ll cn=0;

        for(i=0;i<v.sz;i++)
        {
            if(mp[v[i]]==0)mp[v[i]]=++cn;
        }

        for(i=1;i<=n;i++)
        {
            a[i]=mp[a[i]],b[i]=mp[b[i]];
            adj[a[i]].pb(mk(b[i],c[i]));
        }

        ll ans=0;

        for(i=cn;i>=1;i--)
        {
            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll q=adj[i][j].ss;
                ll r=query(1,1,cn,p+1,cn);
                if(r>q)ans++;
            }

            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll p1=adj[i][j].ss;
                update(1,1,cn,p,p1);
            }
        }

        cout<<ans<<endl;

    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         1000000000000
#define mod         1000000007
#define ull         unsigned long long int
#define f(i,k,n)    for(ll i=k;i<n;i++)
#define fr(i,n,k)   for(i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s];
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2, 2, -2, -2, 1, -1, 1, -1};
int dc[]={1,-1,  1, -1, 2,  2,-2, -2};
int dr1[]={0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[]={-1,0, 1,-1, 0, 1, -1, 0,   1};
int dr2[]={0, 0, 1, -1};
int dc2[]={1,-1, 0,  0};
////////////////////////////
using namespace std;
#define ma 2000000

ll tree[ma*3];
vector<pair<ll,ll> >adj[ma];

void update(ll n,ll b,ll e,ll x,ll val)
{
    if(b==e)
    {
        tree[n]=min(val,tree[n]);
        return;
    }

    ll mid=(b+e)>>1,l=n*2,r=l+1;
    if(x<=mid)update(l,b,mid,x,val);
    else update(r,mid+1,e,x,val);
    tree[n]=min(tree[r],tree[l]);
}

ll query(ll n,ll b,ll e,ll x,ll y)
{
    if(b>y||e<x)return inf;

    if(b>=x&&e<=y)return tree[n];
    ll mid=(b+e)>>1,l=n*2,r=l+1;
    ll p=query(l,b,mid,x,y);
    ll p1=query(r,mid+1,e,x,y);
    return min(p,p1);
}

ll a[ma],b[ma],c[ma];

int main()
{
    ll n,i,j,x,y,z;
    while(cin>>n)
    {
        map<ll,ll>mp;
        vector<ll>v;
        for(i=1;i<=n;i++)
        {
            cin>>x>>y>>z;
            a[i]=x,b[i]=y,c[i]=z;
            v.pb(x);v.pb(y);
        }
        sort(v.begin(),v.end());
        ll cn=0;

        for(i=0;i<ma*3;i++)tree[i]=inf;
        for(i=0;i<v.sz;i++)
        {
            if(mp[v[i]]==0)mp[v[i]]=++cn;
        }

        for(i=1;i<=n;i++)
        {
            a[i]=mp[a[i]],b[i]=mp[b[i]];
            adj[a[i]].pb(mk(b[i],c[i]));
        }

        ll ans=0;

        for(i=1;i<=cn;i++)
        {
            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll q=adj[i][j].ss;
                ll r=query(1,1,cn,1,p-1);
                if(r<q)ans++;
            }

            for(j=0;j<adj[i].sz;j++)
            {
                ll p=adj[i][j].ff;
                ll p1=adj[i][j].ss;
                update(1,1,cn,p,p1);
            }
        }

        cout<<ans<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include<chrono>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define sqr(x) ((x) * (x))
#define all(x)  x.begin(),x.end()
#define MP make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vp vector<pll>
//#define IO(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
#define vvp vector<vp>
#define fs first
#define sc second
#define forn(i,n) for(int i=0; i<n; i++)
#define rrep(i,s,e) for(int i=s; i>=e; i--)
#define rep(i,s,e) for(int i=s; i<=e; i++)
#define print(x) for(auto i:x) cout<<i<<endl;
#define printp(x) for(auto i:x)cout<<i.first<<" "<<i.second<<endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define precision   cout << setprecision(20) << fixed;
#define inf (int)2e9+100
#define infl (ll)2e18
#define rall(x) (x).rbegin(), (x).rend()
#define _ inline
#define rs resize
#define sz(a) int((a).size())
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
const int M = 1e9 + 7;
const int N = (int)5e5+10;
////////

struct l {
	int B;
	int I;
	int R;
};
vi f(N, -1);
void upd(int i, int x) {
	for (; i < N; i += i & -i)
		f[i] = max(f[i], x);
}
int mx(int i) {
	int r = -1;
	for (; i > 0; i -= i & -i)
		r = max(f[i], r);
	return r;
}
int main() {
	fastio; precision;
	int n; cin >> n;
	vector<l> a(n);
	forn(i, n)cin >> a[i].B;
	forn(i, n)cin >> a[i].I;
	forn(i, n)cin >> a[i].R;
	sort(all(a), [](l a, l b) {
		return a.B < b.B;
	});

	map<int, int> mp;
	forn(i, n)mp[a[i].I];
	int count = 0;
	for (auto &i : mp)i.sc = count++;
	forn(i, n) a[i].I = mp[a[i].I];
	//for(auto i:a)cout<<i.B<<
	int ans = 0;
	rrep(i, n - 1, 0) {
		int s = i;
		while (s >= 0 and a[s].I == a[i].I)s--;
		rep(j, s + 1, i) {
			int pos = N - a[j].I;
			int MX = mx(pos - 1);//?
			if (a[j].R < MX) ans++;
		}
		rep(j, s + 1, i) {
			int pos = N - a[j].I;
			upd(pos, a[j].R);
		}
		i = s;
	}
	cout << ans;
 }


#include<bits/stdc++.h>
#include<chrono>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define sqr(x) ((x) * (x))
#define all(x)  x.begin(),x.end()
#define MP make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vp vector<pll>
//#define IO(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
#define vvp vector<vp>
#define fs first
#define sc second
#define forn(i,n) for(int i=0; i<n; i++)
#define rrep(i,s,e) for(int i=s; i>=e; i--)
#define rep(i,s,e) for(int i=s; i<=e; i++)
#define print(x) for(auto i:x) cout<<i<<endl;
#define printp(x) for(auto i:x)cout<<i.first<<" "<<i.second<<endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define precision   cout << setprecision(20) << fixed;
#define inf (int)2e9+100
#define infl (ll)2e18
#define rall(x) (x).rbegin(), (x).rend()
#define _ inline
#define rs resize
#define sz(a) int((a).size())
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
const int M = 1e9 + 7;
const int N = (int)5e5+10;
////////

struct l {
	int B;
	int I;
	int R;
};
vi f(N, -1);
void upd(int i, int x) {
	for (; i < N; i += i & -i)
		f[i] = max(f[i], x);
}
int mx(int i) {
	int r = -1;
	for (; i > 0; i -= i & -i)
		r = max(f[i], r);
	return r;
}
int main() {
	fastio; precision;
	int n; cin >> n;
	vector<l> a(n);
	forn(i, n)cin >> a[i].B;
	forn(i, n)cin >> a[i].I;
	forn(i, n)cin >> a[i].R;
	sort(all(a), [](l a, l b) {
		return a.B < b.B;
	});

	map<int, int> mp;
	forn(i, n)mp[a[i].I];
	int count = 0;
	for (auto &i : mp)i.sc = count++;
	forn(i, n) a[i].I = mp[a[i].I];
	int ans = 0;
	rrep(i, n - 1, 0) {
		int s = i;
		while (s >= 0 and a[s].B == a[i].B)s--;
		rep(j, s + 1, i) {
			int pos = N - a[j].I;
			int MX = mx(pos-1);//?
			if (a[j].R < MX) ans++;
		}
		rep(j, s + 1, i) {
			int pos = N - a[j].I;
			upd(pos, a[j].R);
		}
		i = s+1;
	}
	cout << ans;
 }


#include<bits/stdc++.h>
#include<chrono>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define sqr(x) ((x) * (x))
#define all(x)  x.begin(),x.end()
#define MP make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vp vector<pll>
//#define IO(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
#define vvp vector<vp>
#define fs first
#define sc second
#define forn(i,n) for(int i=0; i<n; i++)
#define rrep(i,s,e) for(int i=s; i>=e; i--)
#define rep(i,s,e) for(int i=s; i<=e; i++)
#define print(x) for(auto i:x) cout<<i<<endl;
#define printp(x) for(auto i:x)cout<<i.first<<" "<<i.second<<endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define precision   cout << setprecision(20) << fixed;
#define inf (int)2e9+100
#define infl (ll)2e18
#define rall(x) (x).rbegin(), (x).rend()
#define _ inline
#define rs resize
#define sz(a) int((a).size())
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
const int M = 1e9 + 7;
const int N = (int)5e5+10;
////////

struct l {
	int B;
	int I;
	int R;
};
vi f(N, -1);
void upd(int i, int x) {
	for (; i < N; i += i & -i)
		f[i] = max(f[i], x);
}
int mx(int i) {
	int r = -1;
	for (; i > 0; i -= i & -i)
		r = max(f[i], r);
	return r;
}
int main() {
	fastio; precision;
	int n; cin >> n;
	vector<l> a(n);
	forn(i, n)cin >> a[i].B;
	forn(i, n)cin >> a[i].I;
	forn(i, n)cin >> a[i].R;
	sort(all(a), [](l a, l b) {
		return a.B < b.B;
	});

	map<int, int> mp;
	forn(i, n)mp[a[i].I];
	int count = 0;
	for (auto &i : mp)i.sc = count++;
	forn(i, n) a[i].I = mp[a[i].I];

	int ans = 0;
	rrep(i, n - 1, 0) {
		int s = i;
		while (s >= 0 and a[s].B == a[i].B)s--;
		rep(j, s + 1, i) {
			int pos = N - a[j].B;
			int MX = mx(pos - 1);//?
			if (a[j].R < MX) ans++;
		}
		rep(j, s + 1, i) {
			int pos = N - a[j].B;
			upd(pos, a[j].R);
		}
		i = s;
	}
	cout << ans;
 }


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*2] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2+1,l,mid,ind,val);
        else
            update(node*2+2,mid+1,r,ind,val);
        sege[node]= max(sege[node*2+1],sege[node*2+2]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r)return sege[node];
    int mid = (l+r)>>1;
    int s1=query(node*2+1,l,mid,b,e);
    int s2=query(node*2+2,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].B);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].I);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].R);
    sort(all.B(),all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B(),INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j=i;
        for(;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(0,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(0,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*3] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2+1,l,mid,ind,val);
        else
            update(node*2+2,mid+1,r,ind,val);
        sege[node]= max(sege[node*2+1],sege[node*2+2]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r)return sege[node];
    int mid = (l+r)>>1;
    int s1=query(node*2+1,l,mid,b,e);
    int s2=query(node*2+2,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].B);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].I);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].R);
    sort(all.B(),all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B(),INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j=i;
        for(;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(0,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(0,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*3] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2+1,l,mid,ind,val);
        else
            update(node*2+2,mid+1,r,ind,val);
        sege[node]= max(sege[node*2+1],sege[node*2+2]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r || (b<=l && e>=r) )return sege[node];
    int mid = (l+r)>>1;
    int s1=query(node*2+1,l,mid,b,e);
    int s2=query(node*2+2,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].B);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].I);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].R);
    sort(all.B(),all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B(),INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j=i;
        for(;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(0,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(0,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


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

#define all(v) (v).begin() + 1, (v).end()
#define LEFT(n) (2*n)
#define RIGHT(n) (2*n + 1)

using namespace std;

const int MAX_N = 5e5 + 15;
int max_tree[3*MAX_N];

struct info
{
    int beauty, richness, intellect;
};

int sort_by_beauty(info &A, info &B)
{
    return (A.beauty < B.beauty);
}

void insert_richness(int n, int left, int right, int index, int value)
{
    if(index < left || right < index)
        return;

    if(left == right)
    {
        max_tree[n] = max(max_tree[n], value);
        return ;
    }

    int mid = (left + right) >> 1;
    insert_richness(LEFT(n), left, mid, index, value);
    insert_richness(RIGHT(n), mid + 1, right, index, value);

    max_tree[n] = max(max_tree[LEFT(n)], max_tree[RIGHT(n)]);
}

int get_max_richness(int n, int left, int right, int query_left, int query_right)
{
    if(right < query_left || query_right < left || right < left)
        return 0;

    if(query_left <= left && right <= query_right)
        return max_tree[n];

    int mid = (left + right) >> 1;
    int left_max = get_max_richness(LEFT(n), left, mid, query_left, query_right);
    int right_max = get_max_richness(RIGHT(n), mid + 1, right, query_left, query_right);

    return max(left_max, right_max);
}

int main()
{
    int no_of_ladies;
    scanf("%d", &no_of_ladies);

    vector <info> lady(no_of_ladies + 1);
    for(int i = 1; i <= no_of_ladies; i++) scanf("%d", &lady[i].beauty);
    for(int i = 1; i <= no_of_ladies; i++) scanf("%d", &lady[i].richness);
    for(int i = 1; i <= no_of_ladies; i++) scanf("%d", &lady[i].intellect);

    sort(all(lady), sort_by_beauty);

    vector <int> intelligence(no_of_ladies + 1, 0);
    for(int i = 1; i <= no_of_ladies; i++) intelligence[i] = lady[i].intellect;

    sort(all(intelligence));
    map <int, int> iq_rank;

    for(int i = 1; i <= no_of_ladies; i++)
    {
        iq_rank[intelligence[i]] = (intelligence[i] == intelligence[i - 1] ? iq_rank[intelligence[i - 1]] : i);
    }

    memset(max_tree, 0, sizeof(max_tree));

    int suicides = 0;

    for(int i = no_of_ladies; i >= 1; )
    {
        int j;

        for(j = i; j >= 1 && lady[j].beauty == lady[i].beauty; j--)
        {
            int max_richness_with_other_2_greater = get_max_richness(1, 1, no_of_ladies, iq_rank[lady[j].intellect] + 1, no_of_ladies);

            if(max_richness_with_other_2_greater > lady[j].richness)
                suicides++;
        }

        for(j = i; j >= 1 && lady[j].beauty == lady[i].beauty; j--)
        {
            insert_richness(1, 1, no_of_ladies, iq_rank[lady[j].intellect], lady[j].richness);
        }

        i = j;
    }

    printf("%d", suicides);
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*3] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2+1,l,mid,ind,val);
        else
            update(node*2+2,mid+1,r,ind,val);
        sege[node]= max(sege[node*2+1],sege[node*2+2]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r || (l<=b && r>=e) )return sege[node];
    int mid = (l+r)>>1;
    int s1=query(node*2+1,l,mid,b,e);
    int s2=query(node*2+2,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].B);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].I);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].R);
    sort(all.B(),all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B(),INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j=i;
        for(;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(0,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(0,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*3] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2+1,l,mid,ind,val);
        else
            update(node*2+2,mid+1,r,ind,val);
        sege[node]= max(sege[node*2+1],sege[node*2+2]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r || (b<=l && e>=r) )return sege[node];
    int mid = (l+r)>>1;
    int s1=query(node*2+1,l,mid,b,e);
    int s2=query(node*2+2,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].B);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].I);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].R);
    sort(all.B()+1,all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B()+1,INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j=i;
        for(;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(0,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(0,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*3] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2,l,mid,ind,val);
        else
            update(node*2+1,mid+1,r,ind,val);
        sege[node]= max(sege[node*2],sege[node*2+1]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r || (b<=l && e>=r) )return sege[node];
    int mid = (l+r)/2;
    int s1=query(node*2,l,mid,b,e);
    int s2=query(node*2+1,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].B);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].I);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].R);
    sort(all.B()+1,all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B()+1,INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j;
        for(j=i;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(1,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(1,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*2] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2+1,l,mid,ind,val);
        else
            update(node*2+2,mid+1,r,ind,val);
        sege[node]= max(sege[node*2+1],sege[node*2+2]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r)return sege[node];
    int mid = (l+r)>>1;
    int s1=query(node*2+1,l,mid,b,e);
    int s2=query(node*2+2,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)
        scanf("%d %d %d",&all[i].B,&all[i].I,&all[i].R);
    sort(all.B(),all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B(),INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j=i;
        for(;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(0,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(0,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


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

//Hello World

typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define B begin
#define E end
#define PB push_back
#define lasB(b) (b&(-b))
#define PI acos(-1.0)
#define EPS (1e-8)
#define N 500005

int n , sege[N*3] , sol;

void update(int node , int l  , int r , int ind , int val)
{
    if(l==r)
        sege[node]=max(val,sege[node]);
    else
    {
        int mid = (l+r)/2;
        if(ind<=mid)
            update(node*2,l,mid,ind,val);
        else
            update(node*2+1,mid+1,r,ind,val);
        sege[node]= max(sege[node*2],sege[node*2+1]);
    }
}

int query(int node , int l , int r, int b , int e)
{
    if(l>r || b>e || b>r || e<l)return 0;
    if(l==r || (b<=l && e>=r) )return sege[node];
    int mid = (l+r)/2;
    int s1=query(node*2,l,mid,b,e);
    int s2=query(node*2+1,mid+1,r,b,e);
    return max(s1,s2);
}

struct wom{int B , I , R;};

bool cmp(wom &a , wom &b)
{
    return a.B<b.B;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie();
    scanf("%d" , &n);
    vector<wom> all(n+1);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].B);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].I);
    for(int i=1;i<=n;i++)scanf("%d",&all[i].R);
    sort(all.B(),all.E(),cmp);
    vector<int> INTEL(n+1,0);
    for(int i=1;i<=n;i++)
        INTEL[i]=all[i].I;
    sort(INTEL.B(),INTEL.E());
    map<int,int> iq;
    for(int i=1;i<=n;i++)
        iq[ INTEL[i] ]=(INTEL[i]==INTEL[i-1]?iq[INTEL[i-1]]:i);
    for(int i=n;i>=1;)
    {
        int j;
        for(j=i;j>=1&&all[i].B==all[j].B;j--)
            sol+=(query(1,1,n,iq[all[j].I]+1,n)>all[j].R);
        for(j=i;j>=1&&all[j].B==all[i].B;j--)
            update(1,1,n,iq[all[j].I],all[j].R);
        i=j;
    }
    printf("%d",sol);
    return 0;
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

/*
                     Keep trying ..!!!!
                     The journey is more important
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define FOR(i,a,b) for(int i = a;i <= b; i++)

// debug templates
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int inf = 1e9 + 7;
template < typename T >
class fenwick{
    public:
     vector < T > BIT;
     int N;
     void init(int size){
         BIT.resize(size + 1);
         fill(BIT.begin() , BIT.end() , 0);
         N = size + 1;
     }
     void update(int x , T val){ // update index i by val
           while(x <= N){
               BIT[x] = max(BIT[x] , val);
               x += (x & (-x));
           }
     }
     T query(T x){
          T val = 0;
          while(x > 0){
              val = max(val , BIT[x]);
              x -= (x & (-x));
          }
          return val;
     }
};
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
     int n;
     cin >> n;
     vpi B(n);
     vi I(n) , R(n);
     for(int i = 0; i < n; i++) {
        cin >> B[i].fi;
        B[i].se = i;
     }
    for(int i = 0; i < n; i++) cin >> I[i];
    for(int i = 0; i < n; i++) cin >> R[i];
    vector < int > newI = I;
    sort(newI.begin() , newI.end());
    newI.resize(unique(newI.begin() , newI.end()) - newI.begin());
    int t = newI.size();
    for(int i = 0; i < n; i++) {
        I[i] = lower_bound(newI.begin() , newI.end() , I[i]) - newI.begin();
        I[i] = t - I[i];
    }
    sort(B.begin() , B.end());
    fenwick < int > fenw;
    fenw.init(n + 1);
    int ans = 0;
    for(int i = n - 2; i >= 0; i--){
        if(B[i].fi == B[i + 1].fi){
            int mx = fenw.query(I[B[i].se] - 1);
            if(mx > R[B[i].se]) ans++;

        } else{
             // update tables
             for(int j = i + 1; j < n; j++){
                 if(j == i + 1) fenw.update(I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi == B[j - 1].fi) fenw.update(I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi != B[j - 1].fi) break;
             }
            int mx = fenw.query(I[B[i].se] - 1);
            if(mx > R[B[i].se]) ans++;
        }
    }
    cout << ans << '\n';
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

/*
                     Keep trying ..!!!!
                     The journey is more important
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define FOR(i,a,b) for(int i = a;i <= b; i++)

// debug templates
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int inf = 1e9 + 7;

template <typename T>
class segTree{
    public:
     vector < T > tree;
     vector < T > v;
     void build(vector < T > &vec){ // O(N)
            v = vec;
            tree.resize(4 * v.size());
            buildUtil(0 , 0 , v.size() - 1);
     }
     void update(int x , int start , int end, int idx , T val){ // O(logN)
            if(idx > end || idx < start) return;
            if(start == end){
                v[idx] = max(v[idx] , val);
                tree[x] = max(tree[x] , val); // update elements in interval
                return;
            }
            int mid = ((end + start) >> 1);
            update(x + x + 1,   start, mid, idx, val);
            update(x + x + 2, mid + 1, end, idx, val);
            tree[x] = max(tree[x + x + 1] , tree[x + x + 2]); // combine intervals
     }
     T query(int x, int start , int end, int qs , int qe){ // O(logN)
            if(qs > qe) return -inf;
            if(qs > end || qe < start) return -inf; // interval will not contribute
            if(start >= qs && end <= qe) return tree[x];
            int mid = ((start + end) >> 1);
            T lef = query(x + x + 1, start, mid , qs , qe);
            T rig = query(x + x + 2, mid + 1 , end , qs , qe);
            return max(lef , rig); // combine intervals
     }
     void buildUtil(int x , int start , int end){ // O(N)
         if(start == end){
             tree[x] = v[start];
             return;
         }
         int mid = ((start + end) >> 1);
         buildUtil(x + x + 1, start , mid);
         buildUtil(x + x + 2, mid + 1, end);
         tree[x] = max(tree[x + x + 1] , tree[x + x + 2]); // combine intervals
     }

};
const int N = 5e5 + 3;
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vpi B(n);
    vi I(n) , R(n);
    for(int i = 0; i < n; i++) {
        cin >> B[i].fi;
        B[i].se = i;
    }
    for(int i = 0; i < n; i++) cin >> I[i];
    for(int i = 0; i < n; i++) cin >> R[i];
    vector < int > newI = I;
    vector < int > newR = R;
    sort(newI.begin() , newI.end());
    sort(newR.begin() , newR.end());
    newI.resize(unique(newI.begin() , newI.end()) - newI.begin());
    newR.resize(unique(newR.begin() , newR.end()) - newR.begin());
    int r = newR.size(); int t = newI.size();
    for(int i = 0; i < n; i++) {
        I[i] = lower_bound(newI.begin() , newI.end() , I[i]) - newI.begin();
        R[i] = lower_bound(newR.begin() , newR.end() , R[i]) - newR.begin();
        I[i] = t - I[i];
    }
    sort(B.begin() , B.end());
    vector < int > val(n , 0);
    segTree < int > sg;
    sg.build(val);
    int ans = 0;
    // for(int i = 0; i < n; i++) cout << "("<<B[i].fi <<","<<B[i].se<<") ";
    // cout << '\n';
    // debugv(I); debugv(R);
    for(int i = n - 2; i >= 0; i--){
        if(B[i].fi == B[i + 1].fi){
            int mx = sg.query(0 , 0 , n - 1 , 0 ,  I[B[i].se] - 1);
            if(mx > R[B[i].se]) ans++;

        } else{
             // update tables
             for(int j = i + 1; j < n; j++){
                 if(j == i + 1) sg.update(0 , 0 , n - 1 , I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi == B[j - 1].fi) sg.update(0 , 0 , n - 1, I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi != B[j - 1].fi) break;
             }
            int mx = sg.query(0 , 0 , n - 1 , 0 , I[B[i].se] - 1);
            if(mx > R[B[i].se]) ans++;
        }
    }
    cout << ans << '\n';
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

/*
                     Keep trying ..!!!!
                     The journey is more important
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define FOR(i,a,b) for(int i = a;i <= b; i++)

// debug templates
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int inf = 1e9 + 7;
template < typename T >
class fenwick{
    public:
     vector < T > BIT;
     int N;
     void init(int size){
         BIT.resize(size + 1);
         fill(BIT.begin() , BIT.end() , 0);
         N = size + 1;
     }
     void update(int x , T val){ // update index i by val
           while(x <= N){
               BIT[x] = max(BIT[x] , val);
               x += (x & (-x));
           }
     }
     T query(T x){
          T val = 0;
          while(x > 0){
              val = max(val , BIT[x]);
              x -= (x & (-x));
          }
          return val;
     }
};
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
     int n;
     cin >> n;
     vpi B(n);
     vi I(n) , R(n);
     for(int i = 0; i < n; i++) {
        cin >> B[i].fi;
        B[i].se = i;
     }
    for(int i = 0; i < n; i++) cin >> I[i];
    for(int i = 0; i < n; i++) cin >> R[i];
    vector < int > newI = I;
    vector < int > newR = R;
    sort(newI.begin() , newI.end());
    sort(newR.begin() , newR.end());
    newI.resize(unique(newI.begin() , newI.end()) - newI.begin());
    newR.resize(unique(newR.begin() , newR.end()) - newR.begin());
    int r = newR.size(); int t = newI.size();
    for(int i = 0; i < n; i++) {
        I[i] = lower_bound(newI.begin() , newI.end() , I[i]) - newI.begin();
        R[i] = lower_bound(newR.begin() , newR.end() , R[i]) - newR.begin();
        I[i] = t - I[i];
    }
    sort(B.begin() , B.end());
    fenwick < int > fenw;
    fenw.init(n + 1);
    int ans = 0;
    for(int i = n - 2; i >= 0; i--){
        if(B[i].fi == B[i + 1].fi){
            int mx = fenw.query(I[B[i].se] - 1);
            if(mx > R[B[i].se]) ans++;

        } else{
             // update tables
             for(int j = i + 1; j < n; j++){
                 if(j == i + 1) fenw.update(I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi == B[j - 1].fi) fenw.update(I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi != B[j - 1].fi) break;
             }
            int mx = fenw.query(I[B[i].se] - 1);
            if(mx > R[B[i].se]) ans++;
        }
    }
    cout << ans << '\n';
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

/*
                     Keep trying ..!!!!
                     The journey is more important
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define FOR(i,a,b) for(int i = a;i <= b; i++)

// debug templates
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int N = 5e5 + 7;
vector < pi > B;
int I[N] , R[N];
const int inf = 1e9 + 7;
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    B.resize(n);
    for(int i = 0; i < n; i++){
        cin >> B[i].fi; B[i].se = i;
    }
    for(int i = 0; i < n; i++) cin >> I[i];
    for(int i = 0; i < n; i++) cin >> R[i];
    sort(B.begin() , B.end());
    multiset < pair < int , int > > mp;
    vector < bool > mur(n , 0);
    for(int i = n - 1; i >= 0; i--){
        if(i == n - 1 || B[i].fi == B[i + 1].fi) mp.insert(make_pair(I[B[i].se] , R[B[i].se]));
        else{
             auto ub = mp.upper_bound(make_pair(I[B[i].se] , R[B[i].se]));
             mur[i] = (ub != mp.end());
        }
    }
    for(int i = n - 2; i >= 0; i--){
        if(B[i].fi == B[i + 1].fi) mur[i] = mur[i + 1];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += (mur[i]);
    }
    cout << ans << '\n';
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

/*
                     Keep trying ..!!!!
                     The journey is more important
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define FOR(i,a,b) for(int i = a;i <= b; i++)

// debug templates
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int inf = 1e9 + 7;

template <typename T>
class segTree{
    public:
     vector < T > tree;
     vector < T > v;
     void build(vector < T > &vec){ // O(N)
            v = vec;
            tree.resize(4 * v.size());
            buildUtil(0 , 0 , v.size() - 1);
     }
     void update(int x , int start , int end, int idx , T val){ // O(logN)
            if(idx > end || idx < start) return;
            if(start == end){
                v[idx] = max(v[idx] , val);
                tree[x] = max(tree[x] , val); // update elements in interval
                return;
            }
            int mid = ((end + start) >> 1);
            update(x + x + 1,   start, mid, idx, val);
            update(x + x + 2, mid + 1, end, idx, val);
            tree[x] = max(tree[x + x + 1] , tree[x + x + 2]); // combine intervals
     }
     T query(int x, int start , int end, int qs , int qe){ // O(logN)
            if(qs > qe) return -inf;
            if(qs > end || qe < start) return -inf; // interval will not contribute
            if(start >= qs && end <= qe) return tree[x];
            int mid = ((start + end) >> 1);
            T lef = query(x + x + 1, start, mid , qs , qe);
            T rig = query(x + x + 2, mid + 1 , end , qs , qe);
            return max(lef , rig); // combine intervals
     }
     void buildUtil(int x , int start , int end){ // O(N)
         if(start == end){
             tree[x] = v[start];
             return;
         }
         int mid = ((start + end) >> 1);
         buildUtil(x + x + 1, start , mid);
         buildUtil(x + x + 2, mid + 1, end);
         tree[x] = max(tree[x + x + 1] , tree[x + x + 2]); // combine intervals
     }

};
const int N = 5e5 + 3;
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vpi B(n);
    vi I(n) , R(n);
    for(int i = 0; i < n; i++) {
        cin >> B[i].fi;
        B[i].se = i;
    }
    for(int i = 0; i < n; i++) cin >> I[i];
    for(int i = 0; i < n; i++) cin >> R[i];
    vector < int > newI = I;
    vector < int > newR = R;
    sort(newI.begin() , newI.end());
    sort(newR.begin() , newR.end());
    newI.resize(unique(newI.begin() , newI.end()) - newI.begin());
    newR.resize(unique(newR.begin() , newR.end()) - newR.begin());
    for(int i = 0; i < n; i++) {
        I[i] = lower_bound(newI.begin() , newI.end() , I[i]) - newI.begin();
        R[i] = lower_bound(newR.begin() , newR.end() , R[i]) - newR.begin();
    }
    sort(B.begin() , B.end());
    vector < int > val(n , 0);
    segTree < int > sg;
    sg.build(val);
    int ans = 0;
    // for(int i = 0; i < n; i++) cout << "("<<B[i].fi <<","<<B[i].se<<") ";
    // cout << '\n';
    // debugv(I); debugv(R);
    for(int i = n - 2; i >= 0; i--){
        if(B[i].fi == B[i + 1].fi){
            int mx = sg.query(0 , 0 , n - 1, I[B[i].se] + 1 , n - 1);
            if(mx > R[B[i].se]) ans++;

        } else{
             // update tables
             for(int j = i + 1; j < n; j++){
                 if(j == i + 1) sg.update(0 , 0 , n - 1 , I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi == B[j - 1].fi) sg.update(0 , 0 , n - 1, I[B[j].se] , R[B[j].se]);
                 else if(B[j].fi != B[j - 1].fi) break;
             }
            int mx = sg.query(0 , 0 , n - 1, I[B[i].se] + 1 , n - 1);
            if(mx > R[B[i].se]) ans++;
        }
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
#define A first
#define B second.first
#define C second.second
#define pii pair<int,pair<int,int> >
using namespace std;
const int N = 5e5+1;
pii a[N];
int n,i,b[N],BIT[N],ans;
int get(int pos){
	int x;
	for(;pos <= n; pos += pos & -pos)
	   x = max(x,BIT[pos]);
	return x;
}
void upd(int pos,int val){
	for(;pos; pos -= pos & - pos)
	BIT[pos] = max (BIT[pos], val);
}
main(){
	cin >> n;
	for ( i = 1; i <= n; i++) cin >> a[i].A;
	for ( i = 1; i <= n; i++) cin >> a[i].B, b[i] = a[i].B;
	for ( i = 1; i <= n; i++) cin >> a[i].C;
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	sort(b+1,b+n+1);
	for ( i = 1; i <= n; i++){
		int x = a[i].B;
		int pos = lower_bound(b+1,b+n+1,x) - b;
		int y = get(pos+1);
		if ( y > a[i].C) ans ++;
		upd(pos,a[i].C);
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define A first
#define B second.first
#define C second.second
#define pii pair<int,pair<int,int> >
using namespace std;
const int N = 5e5+1;
pii a[N];
int n,i,b[N],BIT[N],ans;
int get(int pos){
	int x= 0;
	for(;pos <= n; pos += pos & -pos)
	   x = max(x,BIT[pos]);
	return x;
}
void upd(int pos,int val){
	for(;pos; pos -= pos & - pos)
	BIT[pos] = max (BIT[pos], val);
}
main(){
	cin >> n;
	for ( i = 1; i <= n; i++) cin >> a[i].A;
	for ( i = 1; i <= n; i++) cin >> a[i].B, b[i] = a[i].B;
	for ( i = 1; i <= n; i++) cin >> a[i].C;
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	sort(b+1,b+n+1);
	for ( i = 1; i <= n; i++){
		int x = a[i].B;
		int pos = lower_bound(b+1,b+n+1,x) - b;
		int y = get(pos+1);
		if ( y > a[i].C) ans ++;
		upd(pos,a[i].C);
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define int long long
#define B first
#define I second.first
#define R second.second
using namespace std;
const int N = 5e5+1,M = (1<<30)+1;
map< pair<int,pair<int,int> >,int> BIN;
pair<int,pair<int,int> > a[N];
void add(pair<int,pair<int,int> > pos,int val){
	int x = pos.B,y = pos.I, z = pos.R;
	for (;x < M; x += x&-x)
	for (int y1 = y;y1 < M; y1+=y1&-y1)
	for (int z1 = z;z1 < M; z1+=z1&-z1)
	BIN[make_pair(x,make_pair(y1,z1))] += val;
}
int ans = 0;
int sum(pair<int,pair<int,int> > pos){
	int x = pos.B,y = pos.I, z = pos.R,sum = 0;
	for (;x > 0; x -= x&-x){
	for (int y1 = y;y1 > 0; y1-=y1&-y1)
	for (int z1 = z;z1 > 0; z1-=z1&-z1)
	sum += BIN[make_pair(x,make_pair(y1,z1))];
	return sum;
}}
main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i].B >> a[i].I >> a[i].R;
		a[i].B++,a[i].I++,a[i].R++;
		add({a[i].B,{a[i].I,a[i].R}},1);
	}
	int H = sum({M-1,{M-1,M-1}});
//	cout << H;
	for (int i = 1; i <= n; i++){
		 if(H - sum({a[i].B,{M-1,M-1}}) - sum({M-1,{M-1,a[i].R}})
		 - sum({M-1,{a[i].I,M-1}}) + 2*sum(a[i]) > 0) ans++;
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define B first
#define I second.first
#define R second.second
using namespace std;
const int N = 5e5+1,M = 5e5;
map< pair<int,pair<int,int> >,int> BIN,m1,m2,m3;
pair<int,pair<int,int> > a[N];
int f1[N],f2[N],f3[N];
void add(pair<int,pair<int,int> > pos){
	int x = pos.B,y = pos.I, z = pos.R;
	int y1,z1;
	for (;x <=M; x += x&-x)
	for (y1 = y;y1 <=M; y1+=(y1&-y1))
	for (z1 = z;z1 <=M; z1+=(z1&-z1))
	BIN[{x,{y1,z1}}] ++;
}
int ans = 0,i,n;
int sum(pair<int,pair<int,int> > pos){
	int x = pos.B,y = pos.I, z = pos.R,sum = 0,y1,z1;
	for (;x > 0; x -= (x&-x))
	for (y1 = y;y1 > 0; y1-=(y1&-y1))
	for (z1 = z;z1 > 0; z1-=(z1&-z1))
	sum += BIN[{x,{y1,z1}}];
	return sum;
}
main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for (i = 1; i <= n; i++)
	{	cin >> a[i].B;a[i].B++;
	f1[i] = a[i].B;
	}
	for (i = 1; i <= n; i++)
		{cin >> a[i].I;a[i].I++;f2[i] = a[i].I;	}
	for (i = 1; i <= n; i++){
		cin >> a[i].R;a[i].R++;
		f3[i] = a[i].R;
	}
	sort(f1+1,f1+n+1);
	sort(f2+1,f2+n+1);
	sort(f3+1,f3+n+1);
	for (i = 1; i <= n; i++){
		a[i].B = lower_bound(f1+1,f1+n+1,a[i].B) - f1;
		a[i].I = lower_bound(f2+1,f2+n+1,a[i].I) - f2;
		a[i].R = lower_bound(f3+1,f3+n+1,a[i].R) - f3;
	}
	for(i = 1; i<=n; i++) add(a[i]);
	int H = sum({M,{M,M}});
	for (i = 1; i <= n; i++){
		 if((H - sum({a[i].B,{M,M}}) - sum({M,{M,a[i].R}})
		 - sum({M,{a[i].I,M}}) - sum(a[i]) + sum({a[i].B,{a[i].I,M}}) +
		  sum({a[i].B,{M,a[i].R}}) + sum({M,{a[i].I,a[i].R}})) > 0) ans++;
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define int long long
#define B first
#define I second.first
#define R second.second
using namespace std;
const int N = 5e5+1,M = (1<<30)+1;
map< pair<int,pair<int,int> >,int> BIN;
pair<int,pair<int,int> > a[N];
void add(pair<int,pair<int,int> > pos,int val){
	int x = pos.B,y = pos.I, z = pos.R;
	for (;x < M; x += x&-x)
	for (int y1 = y;y1 < M; y1+=y1&-y1)
	for (int z1 = z;z1 < M; z1+=z1&-z1)
	BIN[make_pair(x,make_pair(y1,z1))] += val;
}
int ans = 0;
int sum(pair<int,pair<int,int> > pos){
	int x = pos.B,y = pos.I, z = pos.R,sum = 0;
	for (;x > 0; x -= x&-x){
	for (int y1 = y;y1 > 0; y1-=y1&-y1)
	for (int z1 = z;z1 > 0; z1-=z1&-z1)
	sum += BIN[make_pair(x,make_pair(y1,z1))];
	return sum;
}}
main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i].B,a[i].B++;
	for (int i = 1; i <= n; i++)
		cin >> a[i].I,a[i].I++;
	for (int i = 1; i <= n; i++){
		cin >> a[i].R,a[i].R++;
		add({a[i].B,{a[i].I,a[i].R}},1);
	}
	int H = sum({M-1,{M-1,M-1}});
	for (int i = 1; i <= n; i++){
		 if(H - sum({a[i].B,{M-1,M-1}}) - sum({M-1,{M-1,a[i].R}})
		 - sum({M-1,{a[i].I,M-1}}) + 5*sum(a[i]) - sum({a[i].B,{a[i].I,M-1}}) -
		  sum({a[i].B,{M-1,a[i].R}}) - sum({M-1,{a[i].I,a[i].R}})> 0) ans++;
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define A first
#define B second.first
#define C second.second
#define pii pair<int,pair<int,int> >
using namespace std;
const int N = 5e5+1;
pii a[N];
int n,i,b[N],BIT[N],ans;
int get(int pos){
	int x = 0;
	for(;pos; pos -= pos & -pos)
	   x = max(x,BIT[pos]);
	return x;
}
void upd(int pos,int val){
	for(;pos <= n; pos += pos & - pos)
	BIT[pos] = max (BIT[pos], val);
}
main(){
	cin >> n;
	for ( i = 1; i <= n; i++) cin >> a[i].A;
	for ( i = 1; i <= n; i++) cin >> a[i].B, b[i] = a[i].B;
	for ( i = 1; i <= n; i++) cin >> a[i].C;
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	sort(b+1,b+n+1);
	for ( i = 1; i <= n; i++){
		int x = a[i].B;
		int pos = n + 1 - (lower_bound(b+1,b+n+1,x) - b);
		int y = get(pos-1);
		if ( y > a[i].C) ans ++;
		upd(pos,a[i].C);
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define B first
#define I second.first
#define R second.second
using namespace std;
const int N = 5e5+1,M = 5e5;
map< pair<int,pair<int,int> >,int> BIN,m1,m2,m3;
pair<int,pair<int,int> > a[N];
pair<int,int> f1[N],f2[N],f3[N];
void add(pair<int,pair<int,int> > pos){
	int x = pos.B,y = pos.I, z = pos.R;
	int y1,z1;
	for (;x <=M; x += x&-x)
	for (y1 = y;y1 <=M; y1+=(y1&-y1))
	for (z1 = z;z1 <=M; z1+=(z1&-z1))
	BIN[{x,{y1,z1}}] ++;
}
int ans = 0,i,n;
int sum(pair<int,pair<int,int> > pos){
	int x = pos.B,y = pos.I, z = pos.R,sum = 0,y1,z1;
	for (;x > 0; x -= (x&-x))
	for (y1 = y;y1 > 0; y1-=(y1&-y1))
	for (z1 = z;z1 > 0; z1-=(z1&-z1))
	sum += BIN[{x,{y1,z1}}];
	return sum;
}
main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for (i = 1; i <= n; i++)
	{	cin >> a[i].B;a[i].B++;
	f1[i] = {a[i].B,i};
	}
	for (i = 1; i <= n; i++)
		{cin >> a[i].I;a[i].I++;f2[i] = {a[i].I,i};	}
	for (i = 1; i <= n; i++){
		cin >> a[i].R;a[i].R++;
		f3[i] = {a[i].R,i};
	}
	sort(f1+1,f1+n+1);
	sort(f2+1,f2+n+1);
	sort(f3+1,f3+n+1);
	for (i = 1; i <= n; i++){
		a[f1[i].second].B = i;
		a[f2[i].second].B = i;
		a[f2[i].second].B = i;
	}
	for(i = 1; i<=n; i++) add(a[i]);
	int H = sum({M-1,{M-1,M-1}});
	for (i = 1; i <= n; i++){
		 if((H - sum({a[i].B,{M-1,M-1}}) - sum({M,{M,a[i].R}})
		 - sum({M,{a[i].I,M}}) - sum(a[i]) + sum({a[i].B,{a[i].I,M}}) +
		  sum({a[i].B,{M,a[i].R}}) + sum({M,{a[i].I,a[i].R}})) > 0) ans++;
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define int long long
#define B first
#define I second.first
#define R second.second
using namespace std;
const int N = 5e5+1,M = 1e9+1;
map< pair<int,pair<int,int> >,int> BIN;
pair<int,pair<int,int> > a[N];
void add(pair<int,pair<int,int> > pos,int val){
	int x = pos.B,y = pos.I, z = pos.R;
	int y1,z1;
	for (;x < M; x += x&-x)
	for (y1 = y;y1 < M; y1+=(y1&-y1))
	for (z1 = z;z1 < M; z1+=(z1&-z1))
	BIN[make_pair(x,make_pair(y1,z1))] ++;
}
int ans = 0;
int sum(pair<int,pair<int,int> > pos){
	int x = pos.B,y = pos.I, z = pos.R,sum = 0,y1,z1;
	for (;x > 0; x -= (x&-x))
	for (y1 = y;y1 > 0; y1-=(y1&-y1))
	for (z1 = z;z1 > 0; z1-=(z1&-z1))
	sum += BIN[make_pair(x,make_pair(y1,z1))];
	return sum;
}
main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{	cin >> a[i].B;a[i].B++;}
	for (int i = 1; i <= n; i++)
		{cin >> a[i].I;a[i].I++;	}
	for (int i = 1; i <= n; i++){
		cin >> a[i].R;a[i].R++;
		add(a[i],1);
	}
	int H = sum({M-1,{M-1,M-1}});
	for (int i = 1; i <= n; i++){
		 if((H - sum({a[i].B,{M-1,M-1}}) - sum({M-1,{M-1,a[i].R}})
		 - sum({M-1,{a[i].I,M-1}}) - sum(a[i]) + sum({a[i].B,{a[i].I,M-1}}) +
		  sum({a[i].B,{M-1,a[i].R}}) + sum({M-1,{a[i].I,a[i].R}})) > 0) ans++;
	}
	cout << ans;
}