405899: GYM102155 A Ability Draft

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Ability Drafttime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

Dota 2 is a competitive multiplayer computer game. In this game, two teams of n players are fighting each other in order to destroy the enemy main building, Ancient. Each player controls one hero, and each hero has exactly s standard abilities and exactly one ultimate ability.

Ability Draft is a fun mode of Dota 2. In this mode, at the start of the game each player gets random hero without abilities at all. Then players pick abilities in certain order from the pool of abilities provided by the game. At his turn, player may either pick any of the remaining standard abilities, or, if he didn't pick his ultimate ability, pick any of the remaining ultimate abilities. The pool contains enough abilities of both kinds so that each player can always pick his s standard abilities and one ultimate ability.

The strength of the team is the sum of strengths of all abilities of all heroes in this team. All players are picking abilities in such a way that the difference between the strength of their own team and the strength of the enemy team at the end of draft procedure is maximum possible.

Knowing the strengths of abilities in the pool and the order of ability picks, find the difference of strengths of the teams if all players perform their picks optimally.

Input

The first line of input contains two integers n and s (1 ≤ n ≤ 5, 1 ≤ s ≤ 3) — the number of players in the team and the number of standard abilities of the heroes.

The second line contains 2n·(s + 1) indices of players — the order of ability picks. Each index from 1 to 2n appears exactly s + 1 times in this array. Players with indices between 1 and n belong to the first team, and players with indices between n + 1 and 2n belong to the second team.

The third line contains an integer ps (2n·s ≤ ps ≤ 36) — the number of standard abilities in the pool.

The fourth line contains ps integers from 1 to 106 — strengths of the standard abilities.

The fifth line contains an integer pu (2n ≤ pu ≤ 12) — the number of ultimate abilities in the pool.

The sixth line contains pu integers from 1 to 106 — strengths of the ultimate abilities.

Output

Output a single integer — the difference of strengths of the teams after all ability picks.

ExamplesInput
1 1
1 2 2 1
2
5 3
2
7 2
Output
3
Input
1 2
2 1 1 2 2 1
4
4 8 8 9
2
6 7
Output
2
Input
2 1
1 3 4 2 2 4 3 1
6
1 4 4 8 9 11
5
14 11 10 8 5
Output
-1

加入题单

算法标签: