// always initially ignore outer products, but save if no inners can be found
if input_sets[positions[0]].isdisjoint(input_sets[positions[1]]):
outer_positions.append(positions)
continue
result = _parse_possible_contraction(positions, input_sets, output_set, idx_dict,
memory_limit, path_cost, naive_cost)
if result is not None:
After Change
// Next iteration only compute contractions with the new tensor
input_sets = best[2]
new_tensor_pos = len(input_sets) - 1
comb_iter = ((i, new_tensor_pos) for i in range(new_tensor_pos))
// Update path and total cost
path.append(best[1])