fn main [ var lines := list_break_to_lines(read_lazy(h[0])); var conn := treeset_init(list(int)); var conn_list := treemap_init(int, int); for l in lines do [ var c1 := 26 * (l[0] - 'a') + (l[1] - 'a'); var c2 := 26 * (l[3] - 'a') + (l[4] - 'a'); var s := [ c1, c2 ]; s := list_sort(s); conn := treeset_set(conn, s); var tm := treemap_search_default(conn_list, c1, 0); tm bts= c2; conn_list := treemap_insert(conn_list, c1, tm); tm := treemap_search_default(conn_list, c2, 0); tm bts= c1; conn_list := treemap_insert(conn_list, c2, tm); ] process_larger: var new_set := treeset_init(list(int)); for s in conn do [ var common := -1; for i := 0 to len(s) do common and= treemap_search_default(conn_list, s[i], 0); for i := 0 to len(s) do common btr= i; while common <> 0 do [ var i := bsr common; common btr= i; var sx := s +< i; sx := list_sort(sx); new_set := treeset_set(new_set, sx); ] ] if treeset_is_nonempty(new_set), then [ conn := new_set; goto process_larger; ] var result := ""; var r := treeset_first(conn).j; for i := 0 to len(r) do [ if len_greater_than(result, 0) then result +<= ','; result +<= r[i] div 26 + 'a'; result +<= r[i] mod 26 + 'a'; ] write(h[1], result + nl); ]