from functools import cache
from sys import maxsize, stdin


ORE = 0
CLAY = 1
OBSIDIAN = 2
GEODE = 3


RESOURCES = dict(ore=ORE, clay=CLAY, obsidian=OBSIDIAN, geode=GEODE)


def add(a, b):
    return tuple(i + j for i, j in zip(a, b))


def subtract(a, b):
    return tuple(i - j for i, j in zip(a, b))


def parse_cost(sentence):
    _, cost_str = sentence.split(" robot costs ")
    cost = [0] * 4

    for consumption_str in cost_str.split(" and "):
        amount_str, consumed_resource_str = consumption_str.split()
        cunsumed_resource = RESOURCES[consumed_resource_str]
        cost[cunsumed_resource] = int(amount_str)

    return tuple(cost)


def parse_blueprint(line):
    _, line = line.split(":")
    return tuple(parse_cost(s) for s in line.split(".")[:-1])


def solve(blueprint, max_minute):
    max_geode_amounts = {}

    max_robot_counts = [
        max(c[i] for c in blueprint)
        for i in range(4)
    ]
    max_robot_counts[GEODE] = maxsize

    @cache
    def recurse(minute, robot_counts, resource_amounts):
        new_resource_amounts = add(resource_amounts, robot_counts)

        if minute == max_minute:
            return new_resource_amounts[GEODE]

        if minute in max_geode_amounts and new_resource_amounts[GEODE] < max_geode_amounts[minute]:
            return 0

        max_geode_amounts[minute] = new_resource_amounts[GEODE]
        result = recurse(minute + 1, robot_counts, new_resource_amounts)

        for robot_resource in reversed(range(4)):
            if robot_counts[robot_resource] >= max_robot_counts[robot_resource]:
                continue

            if min(subtract(resource_amounts, blueprint[robot_resource])) < 0:
                continue

            new_robot_counts = list(robot_counts)
            new_robot_counts[robot_resource] += 1

            new_new_resource_amounts = subtract(new_resource_amounts, blueprint[robot_resource])

            result = max(
                result,
                recurse(
                    minute + 1, tuple(new_robot_counts), tuple(new_new_resource_amounts)
                ),
            )

        return result

    return recurse(1, (1, 0, 0, 0), (0, 0, 0, 0))


def main():
    blueprints = [parse_blueprint(line) for line in stdin]
    quality_level_sum = 0

    for i, blueprint in enumerate(blueprints):
        max_geode_amount = solve(blueprint, 24)
        # print(f"... {max_geode_amount}")
        quality_level_sum += (i + 1) * max_geode_amount

    print(quality_level_sum)
    max_geode_amount_product = 1

    for blueprint in blueprints[:3]:
        max_geode_amount = solve(blueprint, 32)
        # print(f"... {max_geode_amount}")
        max_geode_amount_product *= max_geode_amount

    print(max_geode_amount_product)


if __name__ == "__main__":
    main()
