import math
import re
print(sum(math.prod(max(map(int, re.findall(fr"(\d+) {c}", line))) for c in "rgb") for line in open(0)))