PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000072. Xe về tháp (The Tower is Going Home)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xe về tháp (The Tower is Going Home)

The Tower is Going Home

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A rook starts at (1,1)(1,1) in a 10910^9-by-10910^9 grid and aims to reach any cell on the top row. Vertical and horizontal blocking spells are given. Minimize the number removed to allow the rook to reach the destination.

Input

Line 1: n,mn,m. Next nn lines: vertical wall positions xx. Final mm lines: x1,x2,yx_1,x_2,y for each horizontal spell.

Output

Print the minimum number of spells removed.

Subtasks

  • Subtask 1 (20 points): Exactly one dataset; 0≤n,m≤1000000\le n,m\le100000; n+m≤12n+m\le12; 1≤x<1091\le x<10^9; 1≤x1≤x2≤1091\le x_1\le x_2\le10^9; 1≤y<1091\le y<10^9; vertical walls distinct, all horizontal segments pairwise disjoint.
  • Subtask 2 (30 points): Exactly one dataset; 0≤n,m≤1000000\le n,m\le100000; n+m≤2000n+m\le2000; 1≤x<1091\le x<10^9; 1≤x1≤x2≤1091\le x_1\le x_2\le10^9; 1≤y<1091\le y<10^9; vertical walls distinct, all horizontal segments pairwise disjoint.
  • Subtask 3 (50 points): Exactly one dataset; 0≤n,m≤1000000\le n,m\le100000; n+m≤200000n+m\le200000; 1≤x<1091\le x<10^9; 1≤x1≤x2≤1091\le x_1\le x_2\le10^9; 1≤y<1091\le y<10^9; vertical walls distinct, all horizontal segments pairwise disjoint.

Example

Input

1 2
2
1 1 1
1 3 2

Output

1

Explanation

Removing one of the walls suffices; keeping both prevents reaching the top.