top_three = [0, 0, 0] def insert(calories): top_three.sort() if calories > top_three[0]: top_three.pop(0) top_three.append(calories) with open("input.txt", "r") as f: count = 0 for line in f.readlines(): try: count += int(line) except: insert(count) count = 0 insert(count) print(top_three[0] + top_three[1] + top_three[2])