← Home
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	buf := make([]byte, 65536)
	scanner.Buffer(buf, 1024*1024)

	if !scanner.Scan() {
		return
	}
	ti, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	td, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	tr, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	te, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	A := scanner.Text()
	scanner.Scan()
	B := scanner.Text()

	n := len(A)
	m := len(B)

	dp := make([]int32, (n+1)*(m+1))
	cols := m + 1

	for i := 0; i <= n; i++ {
		dp[i*cols+0] = int32(i * td)
	}
	for j := 0; j <= m; j++ {
		dp[0*cols+j] = int32(j * ti)
	}

	var lastPosB [26]int

	for i := 1; i <= n; i++ {
		lastPosA := 0
		for j := 1; j <= m; j++ {
			var cost int32
			if A[i-1] == B[j-1] {
				cost = dp[(i-1)*cols+(j-1)]
			} else {
				cost = dp[(i-1)*cols+(j-1)] + int32(tr)
			}

			delCost := dp[(i-1)*cols+j] + int32(td)
			if delCost < cost {
				cost = delCost
			}

			insCost := dp[i*cols+(j-1)] + int32(ti)
			if insCost < cost {
				cost = insCost
			}

			lA := lastPosB[B[j-1]-'a']
			lB := lastPosA

			if lA > 0 && lB > 0 {
				transCost := dp[(lA-1)*cols+(lB-1)] + int32(i-lA-1)*int32(td) + int32(j-lB-1)*int32(ti) + int32(te)
				if transCost < cost {
					cost = transCost
				}
			}

			dp[i*cols+j] = cost

			if A[i-1] == B[j-1] {
				lastPosA = j
			}
		}
		lastPosB[A[i-1]-'a'] = i
	}

	fmt.Println(dp[n*cols+m])
}