Prochur Chhuti Lagbe (প্রচুর ছুটি লাগবে)

Limits 1s, 512 MB

Nibir is currently working as a software engineer. He has been continuously working for the past few weeks because of work pressure. He is feeling a little bit tired. So, he is thinking about taking leaves for a few days. He wants to request leave for one or more days. He will not make more than one leave request on a single day. But all of his leaves may not be accepted by the authorities.

Why would they reject those leave requests?

Well, if the current requested leave days overlap with previously accepted leave days, the authorities will reject the current request. Otherwise, they will accept the current request, and these currently accepted leave days will be used to make decisions on future requests.

Now, how would the currently requested days overlap?
If the current requested day contains at least one day that exists in previously requested days.

Nibir wants to know the number of total accepted leave days.

Input

Input will consist of N (N<=1000). N represents the number of previously accepted leaves that are valid.
Next, N line will contain X & Y in each line, (1 <= X <= Y<=10000).
X is the leave start day, end Y is the leave end day.

The next line will consist of Q (Q<=1000). Q represents the number of the latest requested leave.
Next Q line will contain A & B in each line (1 <= A <= B <=10000).
A is the leave start day, end B is the leave end day.

Output

You have to print the total accepted leave days Nibir can have with the current Q request.

Sample

InputOutput
3 
1 3
4 7
15 20
3
8 10
9 10
7 10
3

Here the only accepted leave day is 8-10. Hence total accepted leave days is 3.


Submit

Login to submit.

Statistics

73% Solution Ratio
akash01Earliest, Oct '22
mumith_fahim99Fastest, 0.0s
nusuBotLightest, 4.9 MB
seyamalamShortest, 408B
Toph uses cookies. By continuing you agree to our Cookie Policy.