Ray-UCPL
Ray and his subordinates, Jay and May, are planning to overthrow AUCPL and rename it Ray-UCPL. As part of this effort, Ray has assigned them the task of replacing every AUCPL logo with a new logo featuring his likeness. Each logo has an importance value - higher values indicate more important logos to replace.
Ray has created a list of all AUCPL logos and their importance values. Jay and May work through the list from beginning to end, never skipping a logo. Ray makes exactly assignments, each sending either Jay or May to process the next unprocessed block. Jay processes the next
logos, while May processes the next
logos.
Jay is fast, but sometimes fails to replace a logo correctly. May is slower, but always replaces her logos correctly.
Ray and co. have limited time, so they cannot replace every logo. Even if Jay is assigned all times, only
logos are processed.
Input
The first line contains four integers ,
,
, and
: the number of logos, the number of assignments, and the number of logos Jay and May process per assignment, respectively.
,
, and
.
The next line contains integers
, the importance values of the logos from front to back.
.
The next line contains integers
, each equal to
or
. If Jay is assigned logo
, he successfully replaces it exactly when
. A failed replacement contributes zero importance, but the logo is still processed.
Output
Output the maximum possible sum of importance values of successfully replaced logos.
Examples
Input 1
7 3 2 1
4 8 1 3 4 4 2
0 1 1 0 0 1 0
Output 1
16
Assign in the order May, Jay, May. May replaces logos worth , Jay successfully replaces logos worth
, and May then replaces a logo worth
, for a total of
.
Input 2
7 3 2 1
4 8 1 3 4 4 2
0 0 0 0 0 0 0
Output 2
13
Assign in the order May, May, May. May replaces logos worth , then
, then
, for a total of
.
Comments