#P15491. [IOI 2004] Farmer 农民

[IOI 2004] Farmer 农民

Description

A farmer has a set of fields, each of which is surrounded by cypress trees. Also, the farmer has a set of strips of land, each of which has a row of cypress trees. In both fields and strips, between every two consecutive cypress trees is a single olive tree. All of the farmer's cypress trees either surround a field or are in a strip and all of the farmer's olive trees are between two consecutive cypress trees in a field or in a strip.

One day the farmer became very ill and he felt that he was going to die. A few days before he passed away he called his eldest son and told him, "I give you any QQ cypress trees of your choice and all the olive trees which are between any two consecutive cypress trees you have chosen. " From each field and from each strip the son can pick any combination of cypress trees. Since the eldest son loves olives he wants to pick the QQ cypress trees which will allow him to inherit as many olive trees as possible.

In Figure 1, assume that the son is given Q=17Q=17 cypress trees. To maximize his olive inheritance he should choose all the cypress trees in Field 1 and Field 2, inheriting 1717 olive trees.

You are to write a program which, given the information about the fields and the strips and the number of cypress trees the son can pick, determines the largest possible number of olive trees the son may inherit.

Input Format

The first line contains first the integer QQ: the number of cypress trees the son is to select; then the integer MM, the number of fields; and then the integer KK, the number of strips. The second line contains MM integers N1,N2,,NMN_1, N2,\dots ,N_M, : the numbers of cypress trees in fields. The third line contains KK integers R1,R2,,RKR_1, R_2,\dots ,R_K: the numbers of cypress trees in strips.

Output Format

The file is to contain one line with one integer: the largest possible number of olive trees the son may inherit.

17 3 3 
13 4 8 
4 8 6 
17

Hint

In all inputs, 0Q1500000\le Q\le 150000, 0M20000\le M\le 2000, 0K20000\le K\le 2000, $3\le N_1\le 150, 3\le N_2\le 150,\dots ,3\le N_M\le 150$, $2\le R_1\le 150, 2\le R_2\le150,\dots, 2\le R_K \le 150$. The total number of cypress trees in the fields and strips is at least QQ. Additionally, in 50%50\% of the inputs, Q1500Q\le1500.