Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

This round has an unusual addition to the rules. For each problem you must use distinct language. Thus, if you have a submission that has passed at least one test or is being tested at the moment, then for this task you can use only this language and can not use it for other tasks. More details can be read by the link. Different implementations of the same language are considered to be the same language (for example, in C++ you can only solve one problem, regardless of the exact chosen compiler).

No tag edit access

B. Significant Cups

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputStepan is a very experienced olympiad participant. He has *n* cups for Physics olympiads and *m* cups for Informatics olympiads. Each cup is characterized by two parameters — its significance *c*_{i} and width *w*_{i}.

Stepan decided to expose some of his cups on a shelf with width *d* in such a way, that:

- there is at least one Physics cup and at least one Informatics cup on the shelf,
- the total width of the exposed cups does not exceed
*d*, - from each subjects (Physics and Informatics) some of the most significant cups are exposed (i. e. if a cup for some subject with significance
*x*is exposed, then all the cups for this subject with significance greater than*x*must be exposed too).

Your task is to determine the maximum possible total significance, which Stepan can get when he exposes cups on the shelf with width *d*, considering all the rules described above. The total significance is the sum of significances of all the exposed cups.

Input

The first line contains three integers *n*, *m* and *d* (1 ≤ *n*, *m* ≤ 100 000, 1 ≤ *d* ≤ 10^{9}) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf.

Each of the following *n* lines contains two integers *c*_{i} and *w*_{i} (1 ≤ *c*_{i}, *w*_{i} ≤ 10^{9}) — significance and width of the *i*-th cup for Physics olympiads.

Each of the following *m* lines contains two integers *c*_{j} and *w*_{j} (1 ≤ *c*_{j}, *w*_{j} ≤ 10^{9}) — significance and width of the *j*-th cup for Informatics olympiads.

Output

Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width *d*, considering all the rules described in the statement.

If there is no way to expose cups on the shelf, then print 0.

Examples

Input

3 1 8

4 2

5 5

4 2

3 2

Output

8

Input

4 3 12

3 4

2 4

3 5

3 4

3 5

5 2

3 4

Output

11

Input

2 2 2

5 3

6 3

4 2

8 1

Output

0

Note

In the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most significant cup for Physics (its significance equals 5). After that Stepan can not expose more cups on the shelf, because there is no enough free space. Thus, the maximum total significance of exposed cups equals to 8.

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/24/2019 02:39:23 (d2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|