finished calc_optimal_sequences