import math


def compute_segmentation_mdl_cost(seg_len_list):
    """
    This function computes the MDL cost associated with the lengths split BS sequence.
    This is a middle step in the MDL cost computation proposed by Tanaka et all
    as proposed by Tanaka et all

    :param seg_len_list: list of split BS lengths
    :type seg_len_list: list of list of int
    :return: mdl cost
    :rtype: float
    """
    par_cost_list = []
    data_cost_list = []
    for seg in seg_len_list:
        seg_len_sum = float(sum(seg))
        seg_par_cost = math.log2(seg_len_sum)
        par_cost_list.append(seg_par_cost)
        seg_data_cost_list = [-l*math.log2(l/seg_len_sum) for l in seg]
        seg_data_cost = sum(seg_data_cost_list)
        data_cost_list.append(seg_data_cost)
    par_cost = sum(par_cost_list)
    data_cost = sum(data_cost_list)
    seg_cost = len(seg_len_list)*math.log2(sum(sum(seg_len_list, [])))
    mdl_cost = round(par_cost + data_cost + seg_cost, 2)
    return mdl_cost