#include <stdio.h>
#include <stdlib.h>
#define MAXN 10000
typedef struct Node {
    int val;
    struct Node *left, *right;
} Node;
Node* newNode(int val) {
    Node* node = (Node*)malloc(sizeof(Node));
    node->val = val;
    node->left = node->right = NULL;
    return node;
}
Node* insert(Node* root, int val) {
    if (!root) return newNode(val);
    if (val < root->val) root->left = insert(root->left, val);
    else if (val > root->val) root->right = insert(root->right, val);
    return root;
}
int countInRange(Node* root, int L, int R) {
    if (!root) return 0;
    if (root->val < L) return countInRange(root->right, L, R);
    if (root->val > R) return countInRange(root->left, L, R);
    return 1 + countInRange(root->left, L, R) + countInRange(root->right, L, R);
}

int main() {
    int N;
    if (scanf("%d", &N) != 1 || N < 1 || N > MAXN) {
        printf("Invalid input\n");
        return 0;
    }

    Node* root = NULL;
    int item, small, large;
    for (int i = 0; i < N; i++) {
        if (scanf("%d %d %d", &item, &small, &large) != 3) {
            printf("Invalid input\n");
            return 0;
        }
        if (item < 1 || item > 100000) {
            printf("Invalid input\n");
            return 0;
        }
        root = insert(root, item);
    }

    int L, R;
    if (scanf("%d %d", &L, &R) != 2 || L > R || L < 1 || R > 100000) {
        printf("Invalid input\n");
        return 0;
    }

    int result = countInRange(root, L, R);
    printf("%d\n", result);

    return 0;
}