""" day_10_02.py """

# usage: python3 day_10_02.py < input

import sys


class Device():
    """ simulate puzzle device """
    def __init__(self, program):
        self.program = program.splitlines()
        self.x = None
        self.cycle = None
        self.pc = None
        self.solution = None

    def sprite(self, cycle):
        """ check if sprite visible when pixel is drawn """
        y, x = divmod(cycle, 40)
        if x in [self.x - 1, self.x, self.x + 1]:
            self.solution[y][x] = '#'

    def step(self):
        """ execute current line """
        self.sprite(self.cycle)
        line = self.program[self.pc]
        if line == 'noop':
            self.cycle += 1
        elif line.startswith('addx '):
            self.sprite(self.cycle + 1)
            _, value = line.split()
            self.x += int(value)
            self.cycle += 2
        self.pc += 1

    def run(self):
        """ execute program """
        self.x = 1
        self.cycle = 0
        self.pc = 0
        self.solution = [['.' for _ in range(40)] for _ in range(6)]
        while self.pc < len(self.program):
            self.step()

    def crt(self):
        """ render solution as CRT """
        output = []
        for line in self.solution:
            output += [''.join(line)]
        return '\n'.join(output)


handheld = Device(sys.stdin.read())
handheld.run()
print(handheld.crt())
