405899: GYM102155 A Ability Draft
Description
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.
InputThe 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.
OutputOutput a single integer — the difference of strengths of the teams after all ability picks.
ExamplesInput1 1Output
1 2 2 1
2
5 3
2
7 2
3Input
1 2Output
2 1 1 2 2 1
4
4 8 8 9
2
6 7
2Input
2 1Output
1 3 4 2 2 4 3 1
6
1 4 4 8 9 11
5
14 11 10 8 5
-1