fn main [ var lists := list_break(list_break_to_lines(read_lazy(h[0])), ""); var ordering := treeset_init(tuple2(int, int)); for l in lists[0] do [ var p := map(list_break(l, '|'), ston); ordering := treeset_set(ordering, mktuple2(p[0], p[1])); ] var sum := 0; for l in lists[1] do [ var p := map(list_break(l, ','), ston); for i := 0 to len(p) do [ for j := i + 1 to len(p) do [ if not treeset_test(ordering, mktuple2(p[i], p[j])) then goto misordered; ] ] sum += p[len(p) shr 1]; misordered: ] write(h[1], ntos(sum) + nl); ]