#include #include #include using namespace std; class VM { int x = 1; int cycles = 0; void delay(int amt) { for (int i = 0; i < amt; i++) { cycles++; if (cycles % 40 == 20) { part1 += cycles * x; } int sx = (cycles-1) % 40; int sy = (cycles-1) / 40; if (abs(x - sx) <= 1) cout << "\u2588"; else cout << ' '; if (sx == 39) cout << endl; } } public: int part1 = 0; void parse(string line) { istringstream stream(line); string cmd; stream >> cmd; if (cmd == "noop") { delay(1); } else if (cmd == "addx") { int d; stream >> d; delay(2); x += d; } } }; int main() { VM vm; for (string line; getline(cin, line); ) { vm.parse(line); } cout << vm.part1 << endl; }