#!/usr/bin/env -S awk -f BEGIN { cycle = x = 1 } { cycle++ } cycle % 40 == 20 { strength += cycle * x } { x += $2 } /^addx/ { cycle++ } /^addx/ && cycle % 40 == 20 { strength += cycle * x } END { print strength }