Enemies and Sabers#10451

Enemies and Sabers

5 seconds
256 megabytes
Easy

Cossack Vus has arrived at the Sich to visit a friend who has begun forging sabers in his workshop. This friend has already crafted sabers, where the -th saber is characterized by two parameters: length and sharpness, denoted as a_i and b_i respectively. The cost of the -th saber is cost_i karbovantsiv.

Recently, enemies have appeared at the Sich. The ataman has offered a reward for capturing each enemy — capturing the -th enemy provides a reward of profit_j karbovantsiv. Each enemy has armor with specific parameters: thickness and strength, denoted as c_j and d_j respectively.

To capture an enemy, their armor must be pierced. This requires a saber whose length is at least as great as the armor's thickness, and whose sharpness is at least as great as the armor's strength. Formally, the -th saber can capture the -th enemy if both conditions are satisfied: a_i \geq c_j and b_i \geq d_j.

Cossack Vus wants to determine the maximum number of karbovantsiv he can earn to decide if engaging in this risky venture is worthwhile, and he seeks your assistance.

Note that at the Sich, it is possible to take karbovantsiv on credit, meaning Cossack Vus can have a negative balance at some point. Additionally, Cossack Vus can use a single saber to capture multiple enemies.

Input

The first line contains two integers and (1 \leq n,m \leq 10^6) — the number of sabers and enemies, respectively.

The next lines each contain three integers a_i, b_i, and cost_i (0 \leq a_i, b_i, cost_i \leq 10^9) — the length, sharpness, and cost of the -th saber.

The following lines each contain three integers c_j, d_j, and profit_j (0 \leq c_j, d_j, profit_j \leq 10^9) — the thickness and strength of the -th enemy's armor and the reward for capturing them.

Output

Output a single integer — the maximum number of karbovantsiv Cossack Vus can earn.

Examples

Example 1

Loading
Loading

Scoring

  1. ( points): For any two enemies , where i \ne j, either c_i > c_j, or d_i > d_j, meaning there is no enemy whose both armor parameters are not worse than another; n, m \leq 5\,000;

  2. ( points): For any two enemies , where i \ne j, either c_i > c_j, or d_i > d_j, meaning there is no enemy whose both armor parameters are not worse than another; n, m \leq 10^5;

  3. ( points): For any two sabers , where i \ne j, either a_i > a_j, or b_i > b_j, meaning there is no saber whose both attack parameters are not worse than another; n, m \leq 5\,000;

  4. ( points): For any two sabers , where i \ne j, either a_i > a_j, or b_i > b_j, meaning there is no saber whose both attack parameters are not worse than another; n, m \leq 10^5;

  5. ( points): n,m \leq 5\,000;

  6. ( points): n, m \leq 10^5;

  7. ( points): Without additional constraints.