#!/usr/bin/env python elves = [] with open('input') as f: elf = [] for line in f: if line == "\n": elves.append(elf) elf = [] else: calories = int(line) elf.append(calories) topX = [0,0,0] for elf in elves: calories = sum(elf) for idx, most in enumerate(topX): if calories > most: topX[idx] = calories break print(sum(sorted(map(sum, elves), reverse=True)[0:3]))