def METHOD_NAME(
    lines: list[list[Segment]],
    style: Style,
    size: Size,
    horizontal: AlignHorizontal,
    vertical: AlignVertical,
) -> Iterable[list[Segment]]:
    """Align lines.
    Args:
        lines: A list of lines.
        style: Background style.
        size: Size of container.
        horizontal: Horizontal alignment.
        vertical: Vertical alignment.
    Returns:
        Aligned lines.
    """
    width, height = size
    shape_width, shape_height = Segment.get_shape(lines)
    def blank_lines(count: int) -> list[list[Segment]]:
        return [[Segment(" " * width, style)]] * count
    top_blank_lines = bottom_blank_lines = 0
    vertical_excess_space = max(0, height - shape_height)
    if vertical == "top":
        bottom_blank_lines = vertical_excess_space
    elif vertical == "middle":
        top_blank_lines = vertical_excess_space // 2
        bottom_blank_lines = height - top_blank_lines
    elif vertical == "bottom":
        top_blank_lines = vertical_excess_space
    yield from blank_lines(top_blank_lines)
    horizontal_excess_space = max(0, width - shape_width)
    adjust_line_length = Segment.adjust_line_length
    if horizontal == "left":
        for line in lines:
            yield adjust_line_length(line, width, style, pad=True)
    elif horizontal == "center":
        left_space = horizontal_excess_space // 2
        for line in lines:
            yield [
                Segment(" " * left_space, style),
                *adjust_line_length(line, width - left_space, style, pad=True),
            ]
    elif horizontal == "right":
        get_line_length = Segment.get_line_length
        for line in lines:
            left_space = width - get_line_length(line)
            yield [Segment(" " * left_space, style), *line]
    yield from blank_lines(bottom_blank_lines)