from typing import Union
from typing import Tuple
from typing import Any


def flatten(not_flat: Union[Tuple[Any, Any], Any]) -> Tuple[Any, ...]:
    """
    Given an input which is a tree of tuples,
    returns a single tuple containing the leaves
    """
    if not isinstance(not_flat, tuple):
        return (not_flat,)

    out: Tuple[Any, ...] = ()
    for ll in not_flat:
        out = out + flatten(ll)
    return out