from sys import stdin monkeys = {} for line in stdin: out = line[:4] parts = line[6:].split() if len(parts) == 1: parts = int(parts[0]) monkeys[out] = parts def get(k): m = monkeys[k] if type(m) != int: a = get(m[0]) b = get(m[2]) op = m[1] if op == '+': m = a + b if op == '-': m = a - b if op == '*': m = a * b if op == '/': m = a // b monkeys[k] = m return m print(get('root'))