def memoize(f):
    """Memoization decorator."""
    cache = {}

    def helper(*args, **kwargs):
        t = (tuple(args), tuple(sorted(kwargs.items())))
        if t not in cache:
            cache[t] = f(*args, **kwargs)
        return cache[t]
    return helper