#!/usr/bin/env python import sys def solve(input: list[list[int]]) -> int: totals: list[int] = sorted(map(sum, input), reverse=True) return sum(totals[:3]) def main() -> None: input = [ [int(line) for line in group.split("\n") if line] for group in sys.stdin.read().split("\n\n") if group ] print(solve(input)) if __name__ == "__main__": main()