Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

There are $N$ workers; each worker is of one of the following three types:
A *translator* translates some text from Chef's language to another langague.
An *author* writes some text in Chef's language.
An *author-translator* can both write a text in Chef's language and translate it to another language.

Chef wants to have some text written and translated into some language (different from Chef's language). Chef can't do either of those tasks, but he can hire workers. For each $i$ ($1 ≤ i ≤ N$), if he hires the $i$-th worker, he must pay that worker $c_{i}$ coins.

Help Chef find the minimum total number of coins he needs to pay to have a text written and translated. It is guaranteed that it is possible to write and translate a text.

------  Input ------
The first line of the input contains a single integer $N$ denoting the number of workers.
The second line contins $N$ space-separated integers $c_{1}, c_{2}, ..., c_{N}$ denoting the numbers of coins Chef has to pay each hired worker.
The third line contains $N$ space-separated integers $t_{1}, t_{2}, ..., t_{N}$ denoting the types of workers. For each valid $i$, the $i$-th worker is a translator if $t_{i} = 1$, an author if $t_{i} = 2$ or an author-translator if $t_{i} = 3$.

------  Output ------
Print a single line containing one integer — the minimum number of coins Chef has to pay.

------  Constraints ------
$1 ≤ N ≤ 1,000$
$1 ≤ c_{i} ≤ 100,000$ for each valid $i$
$1 ≤ t_{i} ≤ 3$ for each valid $i$

------  Subtasks ------
Subtask #1 (15 points): all workers are author-translators

Subtask #2 (85 points): original constraints

----- Sample Input 1 ------ 
5
1 3 4 6 8
1 2 1 2 3
----- Sample Output 1 ------ 
4
----- explanation 1 ------ 
Chef can hire 2 workers: worker 1, who is a translator, and worker 2, who is an author. In total, he pays them $1 + 3 = 4$ coins.