fn test_pattern(towels : list(bytes), pattern : bytes) : int [ var reachable := fill(0, len(pattern) + 1); reachable[0] := 1; for i := 0 to len(pattern) do [ if reachable[i] > 0 then [ for t in towels do [ if list_begins_with(pattern[i .. ], t) then [ reachable[i + len(t)] += reachable[i]; ] ] ] ] return reachable[len(pattern)]; ] fn main [ var lines := list_break_to_lines(read_lazy(h[0])); var towels := list_break_whitespace(list_replace_substring(lines[0], ", ", " ")); var patterns := lines[2 .. ]; var reachable := 0; for p in patterns do reachable += test_pattern~spark(towels, p); write(h[1], ntos(reachable) + nl); ]