import sys from collections import deque D = { ">":"<", ")":"(", "]":"[","}":"{", } S = { "(":1, "[":2, "{":3, "<":4, } L = sys.stdin.read().splitlines() N = [] for l in L: Q = deque(["y"]) # add buffer to pop fail = False for c in l: p = Q.pop() if c in D: # if closing char e = D[c] if p != e: # fail case fail = True break else: # just discard the pair pass else: # not closing Q.append(p) Q.append(c) if not fail: R = list(Q)[1:] s = 0 for r in reversed(R): s = s*5 + S[r] N.append(s) print(sorted(N)[len(N)//2])