New Game AI

Given N characters with hp and dp values and a threshold C, count the characters that the order-dependent target scan can return over all reorderings.

Medium7SortingGraphGreedyNo attempts yetTime limit2sMemory limit256 MB

Problem

Aoba is a beginner programmer at a game company. She was asked to write the battle strategy of the enemy AI (artificial intelligence) for a new game. Every character in this game has a hit point value hp and a defence point value dp, and no two characters share the same hp and the same dp at once. The player builds a party by picking one or more characters and sends it into battle.

Aoba first made the AI attack the weakest character of the party: the character with the smallest hp, and among those the character with the smallest dp. Her function selectTarget(v) takes an array that represents a party and returns the character the AI attacks.

Her project manager Yagami was not satisfied with that AI and called it boring. After a long struggle Aoba found that the AI becomes interesting once one of the constant zeros in her program is replaced by a constant C. The rewritten program is below. Character is the type of a character, and its fields hp and dp are the hit point and the defence point of that character.

int C = <constant integer>;

Character selectTarget(Character v[]) {
    int n = length(v);
    int r = 0;
    for (int i = 1; i < n; i++) {
        if (abs(v[r].hp - v[i].hp) > C) {
            if (v[r].hp > v[i].hp) r = i;
        } else {
            if (v[r].dp > v[i].dp) r = i;
        }
    }
    return v[r];
}

Even when v holds the same set of characters, this function can return different characters depending on the order they sit in. Yagami wants to know how many characters of a party can become the target of the new AI. Given the party v and the constant C, count the characters that can be the return value of selectTarget(v) when v is reordered arbitrarily.

Input

The input consists of a single test case. The first line has two integers N and C (1N500001 \le N \le 50000, 0C1090 \le C \le 10^9). N is the size of v, and C is the constant C in the program. The i-th of the following N lines has two integers hpihp_i and dpidp_i (0hpi,dpi1090 \le hp_i, dp_i \le 10^9). hpihp_i is the hit point of the i-th character of v, and dpidp_i is its defence point. If iji \ne j, then hpihpjhp_i \ne hp_j or dpidpjdp_i \ne dp_j.

Output

Print the number of characters that can be the return value of selectTarget(v) when v is shuffled into an arbitrary order.