fn test_pattern(towels : list(bytes), pattern : bytes) : int [ var reachable := fill(false, len(pattern)); reachable[0] := true; for i := 0 to len(pattern) do [ if reachable[i] then [ for t in towels do [ if list_begins_with(pattern[i .. ], t) then [ if i + len(t) = len(pattern) then return 1; reachable[i + len(t)] := true; ] ] ] ] return 0; ] 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); ]