```
export function stampTable(dies: [string, number][]): Map<string, number> {
  const table = new Map<string, number>();
  for (const [fragment, price] of dies) {
    if (typeof fragment !== "string" || fragment.length === 0) {
      throw new Error("a die fragment must be a non-empty string");
    }
    if (!Number.isInteger(price) || price <= 0) {
      throw new Error("a die price must be a positive integer");
    }
    if (table.has(fragment)) {
      throw new Error("die listed twice: " + fragment);
    }
    table.set(fragment, price);
  }
  return table;
}

export function stampCover(label: string, dies: [string, number][]): number {
  const table = stampTable(dies);

  if (typeof label !== "string" || label.length === 0) {
    throw new Error("label must be a non-empty string");
  }

  const n = label.length;
  const dp = Array.from({ length: n + 1 }, () => Infinity);
  dp[0] = 0;

  for (let i = 1; i <= n; i++) {
    for (const [fragment, price] of table) {
      if (i >= fragment.length && label.slice(i - fragment.length) === fragment) {
        dp[i] = Math.min(dp[i], dp[i - fragment.length] + price);
      }
    }
  }

  return dp[n] === Infinity ? dp[0] : dp[n];
}
```