def tribonacci_memo(n, memo):
    """
    Uses memoization to calculate the nth tribonacci number
    Args:
        n: the number
        memo: the dictionary that stores intermediate results
    Returns:
        nth tribonacci number
    """
    if n in memo:
        return memo[n]
    else:
        ans1 = tribonacci_memo(n - 1, memo)
        ans2 = tribonacci_memo(n - 2, memo)
        ans3 = tribonacci_memo(n - 3, memo)
        res = ans1 + ans2 + ans3
        memo[n] = res
        return res