CF469B.Chat Online

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little X and Little Z are good friends. They always chat online. But both of them have schedules.

Little Z has fixed schedule. He always online at any moment of time between a1a_{1} and b1b_{1} , between a2a_{2} and b2b_{2} , ..., between apa_{p} and bpb_{p} (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 00 , he will be online at any moment of time between c1c_{1} and d1d_{1} , between c2c_{2} and d2d_{2} , ..., between cqc_{q} and dqd_{q} (all borders inclusive). But if he gets up at time tt , these segments will be shifted by tt . They become [ci+t,di+t][c_{i}+t,d_{i}+t] (for all ii ).

If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between ll and rr (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [l,r][l,r] suit for that?

输入格式

The first line contains four space-separated integers p,q,l,rp,q,l,r ( 1<=p,q<=50; 0<=l<=r<=10001<=p,q<=50; 0<=l<=r<=1000 ).

Each of the next pp lines contains two space-separated integers ai,bia_{i},b_{i} ( 0<=a_{i}<b_{i}<=1000 ). Each of the next qq lines contains two space-separated integers cj,djc_{j},d_{j} ( 0<=c_{j}<d_{j}<=1000 ).

It's guaranteed that b_{i}<a_{i+1} and d_{j}<c_{j+1} for all valid ii and jj .

输出格式

Output a single integer — the number of moments of time from the segment [l,r][l,r] which suit for online conversation.

输入输出样例

  • 输入#1

    1 1 0 4
    2 3
    0 1
    

    输出#1

    3
    
  • 输入#2

    2 3 0 20
    15 17
    23 26
    1 4
    7 11
    15 17
    

    输出#2

    20
    
首页