def parse(f): data = [] for chunk in f.read().split("\n\n"): data.append([int(x) for x in chunk.split()]) return data with open("input") as f: data = parse(f) sums = [sum(x) for x in data] print(max(sums)) sums.sort() print(sum(sums[-3:]))