There are $n$ warriors in a row. The power of the $i$-th warrior is $a_i$. All powers are pairwise distinct.

You have two types of spells which you may cast:   Fireball: you spend $x$ mana and destroy exactly $k$ consecutive warriors;  Berserk: you spend $y$ mana, choose two consecutive warriors, and the warrior with greater power destroys the warrior with smaller power. 

For example, let the powers of warriors be $[2, 3, 7, 8, 11, 5, 4]$, and $k = 3$. If you cast Berserk on warriors with powers $8$ and $11$, the resulting sequence of powers becomes $[2, 3, 7, 11, 5, 4]$. Then, for example, if you cast Fireball on consecutive warriors with powers $[7, 11, 5]$, the resulting sequence of powers becomes $[2, 3, 4]$.

You want to turn the current sequence of warriors powers $a_1, a_2, \dots, a_n$ into $b_1, b_2, \dots, b_m$. Calculate the minimum amount of mana you need to spend on it.


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the length of sequence $a$ and the length of sequence $b$ respectively.

The second line contains three integers $x, k, y$ ($1 \le x, y, \le 10^9; 1 \le k \le n$) — the cost of fireball, the range of fireball and the cost of berserk respectively.

The third line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$). It is guaranteed that all integers $a_i$ are pairwise distinct.

The fourth line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \le b_i \le n$). It is guaranteed that all integers $b_i$ are pairwise distinct.


-----Output-----

Print the minimum amount of mana for turning the sequnce $a_1, a_2, \dots, a_n$ into $b_1, b_2, \dots, b_m$, or $-1$ if it is impossible.


-----Examples-----
Input
5 2
5 2 3
3 1 4 5 2
3 5

Output
8

Input
4 4
5 1 4
4 3 1 2
2 4 3 1

Output
-1

Input
4 4
2 1 11
1 3 2 4
1 3 2 4

Output
0

Difficulty: interview

Starter code:

Solutions:
def get_val(x, k, y, left_val, right_val, arr):
    x, y = y, x
    if not arr:
        return 0
    if len(arr) < k:
        if max(arr) > max(left_val, right_val):
            return -1
        return len(arr) * x
    if y < x * k:
        n = len(arr)
        res = 0
        while n >= k:
            n -= k
            res += y
        res += n * x
        return res
    else:
        if max(arr) < max(left_val, right_val):
            return len(arr) * x
        else:
            return ((len(arr) - k) * x) + y


def solve(x, k, y, a, b):
    def check(a, b):
        j = 0
        i = 0
        while i < len(a) and j < len(b):
            if a[i] != b[j]:
                i += 1
            else:
                i += 1
                j += 1
        return j == len(b)

    if not check(a, b):
        return -1

    j = 0
    left_val = -1
    arr = []
    res = 0
    for num in a:
        if j == len(b) or num != b[j]:
            arr.append(num)
        else:
            val = get_val(x, k, y, left_val, num, arr)
            if val == -1:
                return -1
            res += val
            arr = []
            left_val = num
            j += 1
    if arr:
        val = get_val(x, k, y, left_val, -1, arr)
        if val == -1:
            return -1
        res += val
    return res


n, m = list(map(int, input().split()))
x, k, y = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(x, k, y, a, b))


__MULTITEST = False

## solve
def isSubseq(a, b):
    ptr = 0
    lenB = len(b)
    for x in a:
        if b[ptr] == x:
            ptr += 1
            if ptr == lenB:
                return True
    return False

def solve():
    n, m = map(int, input().split())
    x, k, y = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    
    ## check
    if not isSubseq(a, b):
        print(-1)
    else:
        a.insert(0, -1); a.append(-2);
        b.insert(0, -1); b.append(-2);

        lenA = len(a)
        lenB = len(b)

        #print(a, b)

        ans = 0

        pa1 = 0; pa2 = 1;
        pb = 0;
        while pb + 1 < lenB:
            ## find surrounded seg in a that has border is b[pb] and b[pb+1]
            maxOfSeg = -3
            
            #print(pb, pa1, pa2)

            while a[pa1] != b[pb]:
                pa1 += 1
            pa2 = pa1 + 1
            while a[pa2] != b[pb+1]:
                maxOfSeg = max(maxOfSeg, a[pa2])
                pa2 += 1

            ## solve that seg
            segLen = pa2 - pa1 - 1
            if segLen >= k:
                if x > y * k:
                    if a[pa1] < maxOfSeg and a[pa2] < maxOfSeg:
                        ans += (x + (segLen - k) * y)
                    else:
                        ans += (segLen * y)
                else:
                    ans += (segLen // k) * x + (segLen % k) * y
            else:
                if a[pa1] < maxOfSeg and a[pa2] < maxOfSeg:
                    print(-1)
                    return
                else:
                    ans += segLen * y
            
            ## after solve, increment pointers
            pb += 1
            pa1 = pa2
        print(ans)


## main
def __starting_point():
    t = (int(input()) if __MULTITEST else 1)
    for tt in range(t):
        try:
            solve();
        except IndexError:
            print("-1")
__starting_point()

import sys
n,m=map(int,input().split())
x,k,y=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if k*y<x:
  ycheap=1
else:
  ycheap=0
pointer=0
ans=0
for i in range(m):
  deletenum=0
  badnum=0
  if pointer==n:
    print(-1)
    return
  start=pointer
  deletnum=0
  while a[pointer]!=b[i]:
    if (i==0 and b[0]<a[pointer]) or (i>0 and b[i]<a[pointer] and b[i-1]<a[pointer]):
      badnum=1
    pointer+=1
    deletenum+=1
    if pointer==n:
      print(-1)
      return
  pointer+=1
  if badnum==1 and deletenum<k:
    print(-1)
    return
  if ycheap==1:
    if badnum==1:
      ans+=x
      ans+=y*(deletenum-k)
    else:
      ans+=y*deletenum
  else:
    ans+=y*(deletenum%k)
    ans+=x*(deletenum//k)
badnum=0
for i in range(pointer,n):
  if a[i]>b[-1]:
    badnum=1
deletenum=n-pointer
if badnum==1 and deletenum<k:
  print(-1)
  return
if ycheap==1:
  if badnum==1:
    ans+=x
    ans+=y*(deletenum-k)
  else:
    ans+=y*deletenum
else:
  ans+=y*(deletenum%k)
  ans+=x*(deletenum//k)
print(ans)

def sooolve(l,lst, r, x, k, y):
    n = len(lst)
    mx = max(l, r)
    ans = 0
    if n == 0:
        return 0
    if mx < max(lst):
        if n < k:
            return -1
        n -= k
        ans += x
    if x > k * y:
        ans += n * y
    else:
        ans += (n // k) * x + (n % k) * y
    return ans
def solve():
    n, m = map(int,input().split())
    x, k, y = map(int,input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    lastpos = -1
    pos = 0
    ans = 0
    for i in b:
        while pos < n and a[pos] != i:
            pos += 1
        if pos == n:
            print(-1)
            return 0
        if pos != lastpos + 1:
            if lastpos == -1:
                k1 = sooolve(0, a[0:pos], a[pos], x,k,y)
                if k1 == -1:
                    print(k1)
                    return 0
                ans += k1
            else:
                k1 = sooolve(a[lastpos], a[lastpos+1:pos], a[pos], x,k,y)
                if k1 == -1:
                    print(k1)
                    return 0
                ans += k1
        lastpos = pos
    k1 = sooolve(a[lastpos], a[lastpos+1:],0,x,k,y)
    if k1 == -1:
        print(k1)
        return 0
    ans += k1
    print(ans)
for i in range(1):
    solve()

import sys
input = sys.stdin.readline

n,m=list(map(int,input().split()))
x,k,y=list(map(int,input().split()))
B=list(map(int,input().split()))
A=list(map(int,input().split()))

inda=0
for b in B:
    if b==A[inda]:
        inda+=1
    if inda==len(A):
        break

if inda!=len(A):
    print(-1)
    return

B+=[0]
A=set(A)|{0}

ONE=0
TWO=0
C=[]
ANS=0

for b in B:
    if not(b in A):
        C.append(b)

    else:
        ONE=TWO
        TWO=b

        MAX=max(ONE,TWO)

        L=len(C)
        ST=0
        for c in C:
            if c>MAX:
                ST+=1

        if ST>0 and L<k:
            print(-1)
            return

        else:
            if ST>0:                
                COST=x           
                rest=L-k
                COST+=min((rest//k)*x+(rest%k)*y,rest*y)
                ANS+=COST
                C=[]
            else:
                COST=min((L//k)*x+(L%k)*y,L*y)
                ANS+=COST
                C=[]
                

print(ANS)
            
                





    

    
            

    


l=input().split()
n=int(l[0])
m=int(l[1])
l=input().split()
x=int(l[0])
k=int(l[1])
y=int(l[2])
a=input().split()
ai=[int(i) for i in a]
b=input().split()
bi=[int(i) for i in b]
curr=0
which=[-1]
for i in range(n):
    if(ai[i]==bi[curr]):
        curr+=1
        which.append(i)
        if(curr==m):
            break
which.append(n)
ans=0
if(curr!=m):
    print(-1)
else:
    poss=1
    for i in range(1,m+2):
        if(which[i-1]+1==which[i]):
            continue
        if(i==1):
            z=ai[which[i]]
        elif(i==m+1):
            z=ai[which[i-1]]
        else:
            z=max(ai[which[i]],ai[which[i-1]])
        maxa=max(ai[which[i-1]+1:which[i]])
        num=which[i]-which[i-1]-1
        if(maxa>z and num<k):
            poss=0
            break
        if(y*k<=x):
            if(maxa>z):
                ans+=x
                ans+=(num-k)*y
            else:
                ans+=num*y
        else:
            ans+=((num//k)*x)
            ans+=((num%k)*y)
    if(poss==0):
        print(-1)
    else:
        print(ans)

(n, m) = map(int, input().split())
(x, k, y) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
j = 0
for i in range(n):
    if j >= m:
        break
    if a[i] == b[j]:
        c.append(0)
        j += 1
    else:
        c.append(1)

if j != m:
    print(-1)
    return

while len(c) != n:
    c.append(1)

back_l = -1
back_r = -1
ans = 0
while True:
    l = back_l
    r = back_r
    for i in range(back_r+1, n):
        if c[i] == 1:
            l = i
            r = i
            break
    M = 0
    for i in range(r, n):
        M = max(M, a[i])
        if i + 1 >= n:
            r = i
        elif c[i+1] == 0:
            r = i
            break
        else:
            r = i

    if l == back_l or r == back_r:
        break

    N = r - l + 1
    left = -1
    right = -1
    if l > 0:
        left = a[l-1]

    if r < n-1:
        right = a[r+1]


    if N < k  and M > left and M > right:
        print(-1)
        return

    if x/k <= y:
        ans += (N//k) * x
        N -= (N//k)*k
        ans += y*N
    else:

        if M < left or M < right:
            ans += y*N
        else:
            ans += x
            N -= k
            ans += y*N
    back_l = l
    back_r = r
print(ans)


'''
9 5
12 1 11
1 2 3 4 5 6 7 8 9
1 3 5 7 9
'''

def subsequence(arr1,arr2,n,m):
    i = 0
    j = 0
    common = []
    while i < n and j < m:
        if arr1[i] == arr2[j]:
            common.append(i)
            j += 1
        i += 1

    if j == m:
        return common

    return []

def find(arr,start,end,x,y,k):
    stack = []
    second_use_limit = 0
    for i in range(start,end+1):
        if not stack:
            stack.append(arr[i])
        else:
            while stack and arr[i] > stack[-1]:
                second_use_limit += 1
                stack.pop()

            if (not stack) or (arr[i] > stack[-1]):
                stack.append(arr[i])
            elif stack and arr[i] < stack[-1]:
                second_use_limit += 1

    while stack and start-1 >= 0 and arr[start-1] > stack[0]:
        stack.pop(0)
        second_use_limit += 1

    while stack and end+1 < len(arr) and arr[end+1] > stack[-1]:
        stack.pop()
        second_use_limit += 1
    
    min_cost = float('inf')
    total = end-start+1
    #print(total,start,end)

    #print('here',x,y,k)
    i = 0
    while i*k <= total:
        rem = total-i*k
        if rem <= second_use_limit:
            #print(i*x+rem*y,i,rem)
            min_cost = min(min_cost,i*x+rem*y)

        i += 1

    if min_cost == float('inf'):
        return -1

    return min_cost

def main():
    n,m = list(map(int,input().split()))
    x,k,y = list(map(int,input().split()))
    arr1 = list(map(int,input().split()))
    arr2 = list(map(int,input().split()))
    common = subsequence(arr1,arr2,n,m)
    if not common:
        print(-1)
        return

    cost = 0
    for i in range(len(common)):
        if i == 0:
            if common[i] > 0:
                start = 0
                end = common[i]-1
                if end >= start:
                    curr_cost = find(arr1,start,end,x,y,k)
                    if curr_cost == -1:
                        cost = -1
                        break

                    cost += curr_cost
            
        start = common[i]+1
        if i+1 < len(common):
            end = common[i+1]-1
        else:
            end = n-1

        if end >= start:
            curr_cost = find(arr1,start,end,x,y,k)
            if curr_cost == -1:
                cost = -1
                break

            cost += curr_cost

    print(cost)

main()


n, m = list(map(int, input().split()))
x, k, y= list(map(int, input().split()))
start_ls = list(map(int, input().split()))
end_ls = list(map(int, input().split()))

len_start_ls = len(start_ls)
len_end_ls = len(end_ls)
mark = []

end_p = 0
curr = None
for item in start_ls:
    if end_p < (len_end_ls):
        if item == end_ls[end_p]:
            end_p += 1
            mark.append(0)
            curr = item
        else:
            if curr is not None:
                if item > curr:
                    mark.append(1)
                else:
                    mark.append(2)
            else:
                mark.append(1)
    else: 
        if curr is not None:
            if item > curr:
                mark.append(1)
            else:
                mark.append(2)
        else:
            mark.append(1)
        
if end_p < (len_end_ls):
    print(-1)
else:
    end_p = 0
    curr = None
    end_ls = end_ls[::-1]
    mark = mark[::-1]
    for idx, item in enumerate(start_ls[::-1]):
        if end_p < (len_end_ls):
            if item == end_ls[end_p]:
                end_p += 1
                curr = item
            else:
                if curr is not None:
                    if item < curr:
                        mark[idx] = 2
        else: 
            if curr is not None:
                if item < curr:
                    mark[idx] = 2
    mark = mark[::-1]
    
    if y*k >= x:
        smite = True
    else:
        smite = False

    segments = []
    segment = [0,True]
    for idx, item in enumerate(mark):
        if item != 0:
            segment[0] += 1
            if item == 1:
                segment[1] = False
        elif item == 0:
            if segment[0] != 0:
                segments.append(segment)
            segment = [0,True]

    if segment[0] != 0:
        segments.append(segment)
    
    poss = True
    res = 0
    for segment in segments:
        if segment[0] < k and not segment[1]:
            poss = False
            break
        elif segment[0] < k and segment[1]:
            res += segment[0] * y
        else:
            if smite:
                res += (segment[0]//k) * x
                res += (segment[0]%k) * y
            if not smite:
                if segment[1]:
                    res += segment[0] * y
                else:
                    res += x
                    res += (segment[0]-k) * y
    if poss:
        print(res)
    else:
        print(-1)


n,m=map(int,input().split())
x,k,y=map(int,input().split())
a=[-1]+list(map(int,input().split()))+[-2]
b=[-1]+list(map(int,input().split()))+[-2]
if m>n:print(-1)
elif m==n:print(-int(a!=b))
else:
    g={}
    for i in range(n+2):g[a[i]]=i
    binds=[]
    for i in b:
        if(i not in g)or(binds and binds[-1]>g[i]):print(-1);return()
        binds.append(g[i])
    #print(binds)
    dels=[]
    for i in range(len(binds)-1):
        dels.append([])
        for j in range(binds[i],binds[i+1]+1):
            dels[-1].append(a[j])
    ans=0
    #print(dels)
    for d in dels:
        todel=len(d)-2
        if todel:
            mx=max(d)
            allys=max(d[0],d[-1])==mx
            if y*k<x:
                if allys:ans+=todel*y
                else:
                    if todel<k:print(-1);return()
                    ans+=y*(todel-k)+x
            else:
                if todel<k:
                    if allys:ans+=todel*y
                    else:print(-1);return()
                else:
                    ans+=y*(todel%k)+x*(todel//k)
    # print(dels)
    print(ans)
'''
3 1
2 1 1
1 2 3
2
'''

n, m = map(int, input().split())
x, k, y = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * m
j = 0
for i in range(n):
    if j == m:
        break
    if a[i] == b[j]:
        c[j] = i + 1
        j += 1
if not j == m:
    print(-1)
    return
a.insert(0, 0)
a.append(0)
c.insert(0, 0)
c.append(n + 1)
ans = 0
for i in range(m + 1):
    if c[i + 1] - c[i] == 1:
        continue
    l = c[i + 1] - c[i] - 1
    s = 0
    t = max(a[c[i]], a[c[i + 1]])
    for j in range(c[i] + 1, c[i + 1]):
        if a[j] > t:
            s += 1
    if s == 0:
        ans += min(l * y, (l // k) * x + (l % k) * y)
    else:
        if k > l:
            print(-1)
            return
        ans += min((l - k) * y + x, (l // k) * x + (l % k) * y)
print(ans)

from math import ceil
def func(values, left, right, x, k, y, left_val, right_val):
    copy = values[left+1:right]
    if len(copy) == 0:
        return 0
    copy.sort()
    if len(copy) < k:
        if copy[-1] > max(left_val, right_val):
            return -1
        else:
            return len(copy) * y
    elif x <= k * y:
        return len(copy) // k * x + (len(copy) % k) * y
    else:
        if copy[-1] > max(left_val, right_val):
            return x + y * (len(copy) - k)
        else:
            return y * len(copy)


def main():
    n, m = map(int, input().split())
    x, k, y = map(int, input().split())
    s1 = list(map(int, input().split()))
    s2 = list(map(int, input().split()))
    if m > n:
        print(-1)
    else:
        j = 0
        l = -1
        ans = 0
        for i in range(n):
            if j == m:
                break
            if s1[i] == s2[j]:
                j += 1
                if l == -1:
                    left_val = -1
                else:
                    left_val = s1[l]
                a = func(s1, l, i, x, k, y, left_val, s1[i])
                if a == -1:
                    ans = -1
                    break
                ans += a
                l = i

        if j < m or ans == -1:
            print(-1)
        else:
            a = func(s1, l, n, x, k, y, s1[l], -1)
            if a == -1:
                print(-1)
            else:
                ans += a
                print(ans)
main()

from collections import defaultdict as dd
import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
x,k,y=list(map(int,input().split()))
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lol=0
if(y*k<x):
    #print(y*k,x)
    lol=1
j=0
ind=[]
for i in range(n):
    if(j==m):
        break
    if(la[i]==lb[j]):
        ind.append(i)
        j+=1
if(j!=m):
    print(-1)
else:
    #print(ind)
    l=la
    ans=0
    curr=ind[0]
    flag=0
    le=ind[0]
    mx=0
    for j in range(0,ind[0]):
        mx=max(mx,l[j])
    if(lol==1):
        if(mx<l[ind[0]]):
            ans+=le*y
        else:
            if(le and le<k):
                flag=1
            elif(le):
                ans+=(le-k)*y+x
    else:
        if(le and le<k):
            if(mx<l[ind[0]]):
                ans+=le*y
            else:
                flag=1
        else:
            rem=le%k
            ans+=rem*y
            ans+=(le//k)*x
    #print(le,ans)
    #print(lol)
    for i in range(1,len(ind)):
        le=ind[i]-curr-1
        mx=0
        for j in range(curr+1,ind[i]):
            mx=max(mx,l[j])
        if(lol==1):
            if(mx<l[curr] or mx<l[ind[i]]):
                #print("lol")
                ans+=le*y
                #print("lol",ans,le,y)
            else:
                #print("lol")
                if(le and le<k):
                    flag=1
                    break
                elif(le):
                    ans+=(le-k)*y+x
        else:
            #print("lol")
            if(le and le<k):
                if(mx<l[ind[i]] or mx<l[ind[i]]):
                    #print(mx)
                    ans+=le*y
                else:
                    flag=1
                    break
            else:
                rem=le%k
                ans+=rem*y
                ans+=(le//k)*x
        curr=ind[i]
        #print(le,ans)
    le=n-1-ind[-1]
    #print(le)
    mx=0
    for j in range(ind[-1]+1,n):
        mx=max(mx,l[j])
    if(lol==1):
        if(mx<l[ind[-1]]):
            ans+=le*y
        else:
            if(le and le<k):
                flag=1
            elif(le):
                ans+=(le-k)*y+x
    else:
        #print("lol")
        if(le and le<k):
            if(mx<l[ind[-1]]):
                ans+=le*y
            else:
                flag=1
        else:
            rem=le%k
            ans+=rem*y
            ans+=(le//k)*x

    if(flag):
        print(-1)
    else:
        print(ans)
        
                


def kill(left, a, right, x, k, y):

    g = len(a)
    if g < k:
        if max(a) > max(left, right):
            print(-1)
            return

    if x < y * k:
        return (g // k) * x + (g % k) * y
    else:
        if max(a) > max(left, right):
            return x + (g-k)*y
        else:
            return g * y


def main():
    (n, m,) = list(map(int, input().split(' ')))
    (x, k, y) = list(map(int, input().split(' ')))
    a = list(map(int, input().split(' ')))
    b = list(map(int, input().split(' ')))
    i = 0
    j = 0
    g = 0
    M = 0

    while i < n and j < m:
        if a[i] == b[j]:
            if g > 0:
                M += kill(b[j - 1] if j > 0 else 0, a[i - g:i], b[j], x, k, y)
                g = 0
            i += 1
            j += 1
        else:
            i += 1
            g += 1
    if i == n and j < m:
        print(-1)
        return
    g += n - i
    if g > 0:
        M += kill(b[j - 1] if j > 0 else 0, a[n - g:n], b[j] if j < m else 0, x, k, y)

    print(M)


# for _ in range(int(input())):
main()


#!/usr/bin/env python3
from sys import stdin, stdout, exit

stdin.readline()
x, k, y = [int(i) for i in stdin.readline().split(' ') if i]
a = [int(i) for i in stdin.readline().split(' ') if i]
b = [int(i) for i in stdin.readline().split(' ') if i]

a[:0] = [0]
a.append(0)
b.append(0)

if x >= y * k:  # BS cheaper or same
    def calc(a):
        n = len(a) - 2
        if max(a) == max(a[0], a[-1]):
            return n * y
        if n < k:
            stdout.write('-1\n')
            return
        return (n - k) * y + x
else:  # FB cheaper
    def calc(a):
        n = len(a) - 2
        if n < k:
            if max(a) == max(a[0], a[-1]):
                return n * y
            stdout.write('-1\n')
            return
        return n // k * x + n % k * y

n = 0
i = 0
for j in b:
    t = i + 1
    while t < len(a):
        if a[t] == j:
            break
        t += 1
    else:
        stdout.write('-1\n')
        return
    if t > i + 1:
        n += calc(a[i: t + 1])
    i = t
stdout.write(f'{n}\n')