import sys


brackets = "()[]{}<>"
syntax_error_scores = [3, 57, 1197, 25137]


def main():
    total_syntax_error_score = 0
    autocomplete_scores = []

    for line in sys.stdin:
        stack = []

        for c in line.strip():
            i = brackets.index(c)

            if i % 2 == 0:
                stack.append(i)
            elif i != stack.pop() + 1:
                total_syntax_error_score += syntax_error_scores[i // 2]
                break
        else:
            autocomplete_scores.append(
                sum((i // 2 + 1) * 5 ** j for j, i in enumerate(stack))
            )

    print(total_syntax_error_score)
    print(sorted(autocomplete_scores)[len(autocomplete_scores) // 2])


if __name__ == "__main__":
    main()
