You are given equal-length lowercase strings source and target. You may apply substring replacement operations. Operation i replaces an occurrence of original[i] with changed[i] and costs cost[i]. The two strings in every rule have equal length, so replacements preserve positions.
The canonical function receives one packed string array because the platform's native functional adapter supports a variable-length rule list. Its layout is:
[source, target, original[0], changed[0], cost[0], original[1], changed[1], cost[1], ...]
The decimal cost strings are parsed as positive integers. This packing is a faithful transport adapter for the typed conceptual contract (source, target, original, changed, cost), not a different problem. Each operation must replace a contiguous range, and any two operation ranges must be disjoint or exactly equal. Thus a range may undergo a chain of replacements, but partially overlapping ranges are not allowed.
Return the minimum total cost, or -1 when the target cannot be reached. If source already equals target, return 0.