Cossack Vus has created his first game and is seeking your help to test it.
You are given an array of length and a number . All elements in the array are positive integers that do not exceed . Each integer from to has an associated price. Your task is to find a subarray with the highest price. The price of a subarray is calculated as the sum of the prices of numbers that appear exactly once in that subarray.
Assist Cossack in determining the maximum price of a subarray for the given array and number prices.
The first line contains two integers and (1 \leq m \leq n \leq 200\,000) — representing the size of the array and the maximum number in the array.
The second line contains integers a_1, a_2, \ldots, a_n (1 \leq a_i \leq m) — the elements of the array. It is guaranteed that each number from to appears at least once.
The third line contains integers c_1, c_2, \ldots, c_m (1 \leq c_i \leq 1\,000\,000) — the prices of the numbers.
Output a single integer on one line — the maximum price of a subarray.
Example 1
Example 2
In the first example, the subarray with the maximum price is [6\,\ldots\,7].
In the second example, the subarray with the maximum price is [2\,\ldots\,6].