Kozak Vus and the New Game
Cossack Vus has created his first game and is seeking your help to test it.
You are given an array a of length n and a number m. All elements in the array are positive integers that do not exceed m. Each integer from 1 to m 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.
Input Format
The first line contains two integers n and m (1 ≤ m ≤ n ≤ 200,000) — representing the size of the array and the maximum number in the array.
The second line contains n integers a[1]
, a[2]
, ..., a[n]
(1 ≤ a[i]
≤ m) — the elements of the array. It is guaranteed that each number from 1 to m appears at least once.
The third line contains m integers c[1]
, c[2]
, ..., c[m]
(1 ≤ c[i]
≤ 1,000,000) — the prices of the numbers.
Output Format
Output a single integer on one line — the maximum price of a subarray.
Examples
Note
In the first example, the subarray with the maximum price is [6 . . . 7].
In the second example, the subarray with the maximum price is [2 . . . 6].