from typing import Callable
from typing import Any
from typing import OrderedDict


def multimap(f: Callable, *xs: Any) -> Any:
    """
    Each x in xs is a tree of the same structure.
    Apply f at each leaf of the tree with len(xs) arguments.
    Return a tree of the same structure, where each leaf contains f's return value.
    """
    first = xs[0]
    if isinstance(first, dict) or isinstance(first, OrderedDict):
        assert all(isinstance(x, dict) or isinstance(x, OrderedDict) for x in xs)
        assert all(x.keys() == first.keys() for x in xs)
        return {k: multimap(f, *(x[k] for x in xs)) for k in sorted(first.keys())}
    else:
        return f(*xs)