import sys
from functools import reduce


def parse_number(s):
    return [int(c) if c.isdigit() else c for c in s]


def format_number(number):
    return "".join(map(str, number))


def explode_number(number):
    depth = 0

    for i, token in enumerate(number):
        if token == "[":
            depth += 1
        elif number[i] == "]":
            depth -= 1

            if (
                depth >= 4
                and type(number[i - 1]) is int
                and number[i - 2] == ","
                and type(number[i - 3]) is int
                and number[i - 4] == "["
            ):
                for j in range(i - 5, -1, -1):
                    if type(number[j]) is int:
                        number[j] += number[i - 3]
                        break

                for j in range(i + 1, len(number)):
                    if type(number[j]) is int:
                        number[j] += number[i - 1]
                        break

                number[i - 4 : i + 1] = [0]
                return True

    return False


def split_number(number):
    for i, token in enumerate(number):
        if type(token) is int and token >= 10:
            number[i : i + 1] = ["[", token // 2, ",", (token + 1) // 2, "]"]
            return True

    return False


def reduce_number(number):
    while explode_number(number) or split_number(number):
        pass


def add_numbers(a, b):
    result = ["["] + a + [","] + b + ["]"]
    reduce_number(result)
    return result


def get_magnitude(node):
    if type(node) is int:
        return node

    left, right = node
    return 3 * get_magnitude(left) + 2 * get_magnitude(right)


def main():
    numbers = [parse_number(line.strip()) for line in sys.stdin]
    print(get_magnitude(eval(format_number(reduce(add_numbers, numbers)))))

    print(
        max(
            get_magnitude(eval(format_number(add_numbers(a, b))))
            for a in numbers
            for b in numbers
            if a != b
        )
    )


if __name__ == "__main__":
    main()
