from operator import add, sub, mul, truediv
from sys import stdin


OPERATORS = {"+": add, "-": sub, "*": mul, "/": truediv}


def main():
    monkeys = {}

    for line in stdin:
        name, expr_str = line.split(":")
        tokens = expr_str.split()

        if len(tokens) == 1:
            assert tokens[0].isdigit()
            monkeys[name] = float(tokens[0])
        else:
            left, op, right = tokens
            assert left.isalpha()
            assert op in OPERATORS
            assert right.isalpha()
            monkeys[name] = [left, OPERATORS[op], right]

    def evaluate(name):
        expr = monkeys[name]

        if type(expr) is float:
            return expr

        left, op, right = expr
        return op(evaluate(left), evaluate(right))

    print(round(evaluate("root")))

    lower_bound = 0.0
    upper_bound = 1.0

    monkeys["root"][1] = sub
    monkeys["humn"] = upper_bound

    while evaluate("root") > 0.0:
        lower_bound = upper_bound
        upper_bound *= 2.0
        monkeys["humn"] = upper_bound

    while round(lower_bound) < round(upper_bound):
        new_bound = 0.5 * (lower_bound + upper_bound)
        monkeys["humn"] = new_bound

        if evaluate("root") > 0.0:
            lower_bound = new_bound
        else:
            upper_bound = new_bound

    print(round(lower_bound))


if __name__ == "__main__":
    main()
