with open("input.txt") as f: lines = [int(i) for i in f.readlines()] hits = 0 window = lines[0:3] for line in lines[3:]: oldwindow = list(window) window.pop(0) window.append(line) if sum(oldwindow) < sum(window): hits += 1 print(hits) # 5m41s