eolymp
bolt
Try our new interface for solving problems
Problems

Trains and rabbits

Trains and rabbits

Rabbit king is string and fair ruler. Year by year he sustains the country at high level of developmet, protects from attacks of kangaroids and hamstars. Citizens of the kingdom love their King. Spring came and King has returned from his another campaign. King iconizes spring, so he asked to open as many windows in main corridor of his castle as possible. The task is not simple, since there are very many windows in the castle. And rabbits-servants do not want King to get cold. They should open windows avoiding draft in the corridor. The corridor could be imagined as \textbf{2} parallel walls with windows. Each window has 2 coordinates: start and finish. Walls start at coordinate \textbf{0} and have length \textbf{L}. The first was contains \textbf{N_1} windows (windows do not overlap, but can touch), the second has \textbf{N_2}. windows. Draft starts if there is a trough path for a wind through the corridor (wind blows at right angles to the wall). In other words, if two windows are open: (\textbf{4}; \textbf{8}) at the first wall and (\textbf{6}; \textbf{10}) at the second, we will get a draft at the interval (\textbf{6}; \textbf{8}). For windows (\textbf{5}; \textbf{7}) and (\textbf{8}; \textbf{10}) and even for (\textbf{5}; \textbf{7}) and (\textbf{7}; \textbf{8}) draft will not start. How many windows could be opened at most? \InputFile The first line contains three integers, separated by spaces: \textbf{L}, \textbf{N_1}, \textbf{N_2} (\textbf{1} ≤ \textbf{L} ≤ \textbf{100000}, \textbf{0} ≤ \textbf{N_1}, \textbf{N_2} ≤ \textbf{L}). Following \textbf{N_1} lines contain coordinates of start and finish for windows at the first wall, separated by spaces: \textbf{b} \textbf{e} (\textbf{0} ≤ \textbf{b} < \textbf{e} ≤ \textbf{L}). In same way following \textbf{N_2} lined describe windows at the second wall. \OutputFile You need to output maximum number of windows that could be opened, to avoid cold for King.
Time limit 1 second
Memory limit 64 MiB
Input example #1
10 2 3
0 2
4 7
1 4
5 8
8 9
Output example #1
3
Source ACM-ICPC Ukraine 2012, 1st Stage Ukraine, April 21, 2012