import sys


def main():
    calorie_counts = sorted(
        sum(int(line) for line in block.split())
        for block in sys.stdin.read().split("\n\n")
    )

    for i in [1, 3]:
        print(sum(calorie_counts[-i:]))


if __name__ == "__main__":
    main()
