def cppn_rem(
    template,
    grid: list,
    ) -> list:
    """Obtain the list of elements to be removed according to the generated CPPN

    Parameters
    ----------
    template
        The unit template parameters
    grid : list
        The grid generated by the CPPN

    Returns
    -------
    list
        The list of element IDs to be removed
    """

    #   Initialisations
    rem = []

    #   Create a copy of the grid
    g_temp = grid[:]

    #   Reverse the order of the grid
    g_temp = g_temp[::-1]

    #   Calculate the element ID offset according to the boundary thickness
    offset = template.x_e*template.b + template.b + 1

    #   Loop through rows of the grid
    for i in g_temp:

        #   Loop through the elements in the current row
        for j in range(0, len(i)):

            #   Check if the current element needs to be removed
            if i[j] == 0:

                #   Add the element ID to the list of element IDs to be removed
                rem.append(j + offset)

        #   Increment the offset
        offset += template.x_e

    return rem