You are given a string expression representing a Lisp-like expression to return the integer value of.

The syntax for these expressions is given as follows.

An expression is either an integer, a let-expression, an add-expression, a mult-expression, or an assigned variable.  Expressions always evaluate to a single integer.

(An integer could be positive or negative.)

A let-expression takes the form (let v1 e1 v2 e2 ... vn en expr), where let is always the string "let", then there are 1 or more pairs of alternating variables and expressions, meaning that the first variable v1 is assigned the value of the expression e1, the second variable v2 is assigned the value of the expression e2, and so on sequentially; and then the value of this let-expression is the value of the expression expr.

An add-expression takes the form (add e1 e2) where add is always the string "add", there are always two expressions e1, e2, and this expression evaluates to the addition of the evaluation of e1 and the evaluation of e2.

A mult-expression takes the form (mult e1 e2) where mult is always the string "mult", there are always two expressions e1, e2, and this expression evaluates to the multiplication of the evaluation of e1 and the evaluation of e2.

For the purposes of this question, we will use a smaller subset of variable names.  A variable starts with a lowercase letter, then zero or more lowercase letters or digits.  Additionally for your convenience, the names "add", "let", or "mult" are protected and will never be used as variable names.

Finally, there is the concept of scope.  When an expression of a variable name is evaluated, within the context of that evaluation, the innermost scope (in terms of parentheses) is checked first for the value of that variable, and then outer scopes are checked sequentially.  It is guaranteed that every expression is legal.  Please see the examples for more details on scope.


Evaluation Examples:

Input: (add 1 2)
Output: 3

Input: (mult 3 (add 2 3))
Output: 15

Input: (let x 2 (mult x 5))
Output: 10

Input: (let x 2 (mult x (let x 3 y 4 (add x y))))
Output: 14
Explanation: In the expression (add x y), when checking for the value of the variable x,
we check from the innermost scope to the outermost in the context of the variable we are trying to evaluate.
Since x = 3 is found first, the value of x is 3.

Input: (let x 3 x 2 x)
Output: 2
Explanation: Assignment in let statements is processed sequentially.

Input: (let x 1 y 2 x (add x y) (add x y))
Output: 5
Explanation: The first (add x y) evaluates as 3, and is assigned to x.
The second (add x y) evaluates as 3+2 = 5.

Input: (let x 2 (add (let x 3 (let x 4 x)) x))
Output: 6
Explanation: Even though (let x 4 x) has a deeper scope, it is outside the context
of the final x in the add-expression.  That final x will equal 2.

Input: (let a1 3 b2 (add a1 1) b2) 
Output 4
Explanation: Variable names can contain digits after the first character.



Note:
The given string expression is well formatted: There are no leading or trailing spaces, there is only a single space separating different components of the string, and no space between adjacent parentheses.  The expression is guaranteed to be legal and evaluate to an integer.
The length of expression is at most 2000.  (It is also non-empty, as that would not be a legal expression.)
The answer and all intermediate calculations of that answer are guaranteed to fit in a 32-bit integer.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'class Solution(object):\n \tdef parse(self,expression,d,i):\n \t\tcount = 0\n \t\tstart = i\n \t\tif expression[i] == "(":\n \t\t\tcount += 1\n \t\t\ti += 1\n \t\t\twhile count != 0:\n \t\t\t\tif expression[i] == "(":\n \t\t\t\t\tcount += 1\n \t\t\t\telif expression[i] == ")":\n \t\t\t\t\tcount -= 1\n \t\t\t\ti += 1\n \t\t\tval = self.evaluate(expression[start:i],d)\n \t\telse:\n \t\t\twhile i < len(expression) and expression[i] != " " and expression[i] != ")":\n \t\t\t\ti += 1\n \t\t\tval = expression[start:i]\n \t\t\tif self.isnumber(val):\n \t\t\t\tval = int(val)\n \t\treturn i,val\n \tdef get_left_right(self,expression,d):\n \t\ti = 0\n \t\tcount = 0\n \t\ti,left = self.parse(expression,d,0)\n \t\tif i == len(expression) or expression[i] == ")":\n \t\t\treturn left,None,i\n \t\ti += 1\n \t\ti,right = self.parse(expression,d,i)\n \t\treturn left,right,i\n \tdef isnumber(self,s):\n \t\tfor c in s:\n \t\t\tif ord("0") <= ord(c) <= ord("9") or c == "+" or c == "-":\n \t\t\t\tcontinue\n \t\t\telse:\n \t\t\t\treturn False\n \t\treturn True\n \tdef evaluate(self, expression,d = {}):\n \t\t"""\n \t\t:type expression: str\n \t\t:rtype: int\n \t\t"""\n \t\tif self.isnumber(expression):\n \t\t\treturn int(expression)\n \t\tnewd = {}\n \t\tfor key in d:\n \t\t\tnewd[key] = d[key]\n \t\texpression = expression[1:len(expression)-1]\n \t\toper = ""\n \t\tif expression[0:3] == "add" or expression[:3] == "let":\n \t\t\toper = expression[0:3]\n \t\t\texpression = expression[4:]\n \t\telse:\n \t\t\toper = "mult"\n \t\t\texpression = expression[5:]\n \t\t\n \t\tif oper == "mult" or oper == "add":\n \t\t\tleft,right,_ = self.get_left_right(expression,newd)\n \t\t\tif isinstance(left,str):\n \t\t\t\tleft = newd[left]\n \t\t\tif isinstance(right,str):\n \t\t\t\tright = newd[right]\n \t\t\tif oper == "mult":\n \t\t\t\treturn left*right\n \t\t\telse:\n \t\t\t\treturn left + right\n \t\ti = 0\n \t\twhile True:\n \t\t\tleft,right,i = self.get_left_right(expression,newd)\n \t\t\texpression = expression[i+1:]\n \t\t\tif right == None:\n \t\t\t\tif isinstance(left,str):\n \t\t\t\t\treturn newd[left]\n \t\t\t\treturn left\n \t\t\tif isinstance(right,str):\n \t\t\t\tright = newd[right]\n \t\t\tnewd[left] = right\n \t\t\t\n \t\t\t\n \t\t\t\n # s = Solution()\n # print(s.evaluate("(let x 2 (mult x (let x 3 y 4 (add x y))))"))\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'evaluate'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 7115