Given two sequences s1…sn and w1…wn. A graph is built with n vertices and n directed edges (i,si). Cost to change some si is wi . Your goal is to make the graph strongly connected with minimum cost.
Input
The first line contains an integer n.
The second line contains n intergers, s1…sn.
The third line contains n integers w1…wn.
Output
An integer representing the answer.
Constraints
1≤n≤105
1≤si≤n
1≤wi≤109
Change s2 to 3 and s3 to 4.