from typing import List


def calculate_magnitude(reduced_form: List[List[int]]) -> int:
    """
    Generate the magnitude by reducing from inside out.
    Ex: [[9,1], [1,9]]
        => [(9, 2), (1, 2), (1, 2), (9, 2)]
        => [(29, 1), (1, 2), (9, 2)]
        => [(29, 1), (21, 1)]
        => [(129, 0)]
        => 129
    :param reduced_form: Final math form to reduce from (Value Depth list)
    :return: Magnitude
    """
    while len(reduced_form) > 1:
        deepest_found = -1
        deep_index = -1

        for index, (value, depth) in enumerate(reduced_form):
            if depth > deepest_found:
                deepest_found = depth
                deep_index = index

        max_depth_found = reduced_form[deep_index][1]

        # Replace the pair of points with the calculated result, removing the depth
        total = 3 * reduced_form[deep_index][0] + 2 * reduced_form[deep_index + 1][0]
        del reduced_form[deep_index + 1]
        del reduced_form[deep_index]
        reduced_form.insert(deep_index, [total, max_depth_found - 1])

    return reduced_form[0][0]