You are playing a game with a stack of $N$ disks. The goal is to remove every disk from your stack. Each removal has a cost, and you want the total cost to be as small as possible.
Every disk carries a label $L$, and $1 \le L \le 20$.
You also get a Master stack of $N$ disks to help you clear your own stack.
There are two ways to remove the disk on top of your stack.
You may also reorder the top $K$ disks of your stack. Immediately after each reorder you must remove the top disk, so one removal is preceded by at most one reorder. A reorder applies to a range of disks at the top of your stack, and the size of that range cannot exceed the number of disks still on the stack. Three reorders are allowed.
If the reorder leaves the top of the Master stack and the top of your stack carrying the same label, the pair comes off for free. Rule 1 is still available in that case, so you may instead pay the label and remove only your own disk. When the labels differ, rule 1 is the only option.
One more rule constrains the order of removals. Number the levels of your stack starting at $0$ for the bottom. When the disk that started at level $j$ is removed, every disk that started at level $j + M$ or higher must already be gone.
Find the minimum total cost of emptying your stack.
The first line contains six space separated integers $N$, $K$, $M$, $D$, $U$, $R$.
Then $2N$ lines follow, each with one label $L$ ($1 \le L \le 20$). The first $N$ of them give the labels of the Master stack from top to bottom, and the remaining $N$ give the labels of your stack from top to bottom.
Print one integer on a single line, the minimum cost of removing every disk from your stack.