#!/usr/bin/python3 import fileinput x = 1 cycle = 0 total = 0 def tick(): global cycle, total cycle += 1 if cycle in (20, 60, 100, 140, 180, 220): total += (cycle * x) for line in fileinput.input(): line = line.rstrip() if line == 'noop': tick() else: _, addx = line.split(' ') tick() tick() x += int(addx) print(total)