class Colour:
    BLACK = '0'
    WHITE = '1'
    TRANSPARENT = '2'
    display_map = {BLACK: ' ', WHITE: '#', TRANSPARENT: '~'}

    @classmethod
    def display(cls, code):
        return cls.display_map[code]


def solve_1(layers):
    min_layer = min(layers, key=lambda layer: layer.count('0'))
    return min_layer.count('1') * min_layer.count('2')


def solve_2(layers):
    image = [Colour.TRANSPARENT] * len(layers[0])
    for layer in layers:
        for i, pixel in enumerate(layer):
            if image[i] == Colour.TRANSPARENT:
                image[i] = pixel
    return image


def draw_image(image, width, height):
    image = list(map(Colour.display, image))
    area = len(image)
    lines = (''.join(image[i:i + width]) for i in range(0, area, width))
    return '\n'.join(lines)


text = open('input.txt').read()
layers = []
width = 25
height = 6
area = width * height
for i in range(0, len(text), area):
    layers.append(text[i:i + area])
print(solve_1(layers))
print(draw_image(solve_2(layers), width, height))

fcf16c57f77cb1b0ee954ab1f83b7a12b2de5e59
class Colour:
    BLACK = '0'
    WHITE = '1'
    TRANSPARENT = '2'
    display_map = {BLACK: ' ', WHITE: '#', TRANSPARENT: '~'}

    @classmethod
    def display(cls, code):
        return cls.display_map[code]


def solve_1(layers):
    min_layer = min(layers, key=lambda layer: layer.count('0'))
    return min_layer.count('1') * min_layer.count('2')


<mask token>


def draw_image(image, width, height):
    image = list(map(Colour.display, image))
    area = len(image)
    lines = (''.join(image[i:i + width]) for i in range(0, area, width))
    return '\n'.join(lines)


<mask token>

class Colour:
    BLACK = '0'
    WHITE = '1'
    TRANSPARENT = '2'
    display_map = {BLACK: ' ', WHITE: '#', TRANSPARENT: '~'}

    @classmethod
    def display(cls, code):
        return cls.display_map[code]


def solve_1(layers):
    min_layer = min(layers, key=lambda layer: layer.count('0'))
    return min_layer.count('1') * min_layer.count('2')


def solve_2(layers):
    image = [Colour.TRANSPARENT] * len(layers[0])
    for layer in layers:
        for i, pixel in enumerate(layer):
            if image[i] == Colour.TRANSPARENT:
                image[i] = pixel
    return image


def draw_image(image, width, height):
    image = list(map(Colour.display, image))
    area = len(image)
    lines = (''.join(image[i:i + width]) for i in range(0, area, width))
    return '\n'.join(lines)


<mask token>

class Colour:
    BLACK = '0'
    WHITE = '1'
    TRANSPARENT = '2'
    display_map = {BLACK: ' ', WHITE: '#', TRANSPARENT: '~'}

    @classmethod
    def display(cls, code):
        return cls.display_map[code]


def solve_1(layers):
    min_layer = min(layers, key=lambda layer: layer.count('0'))
    return min_layer.count('1') * min_layer.count('2')


def solve_2(layers):
    image = [Colour.TRANSPARENT] * len(layers[0])
    for layer in layers:
        for i, pixel in enumerate(layer):
            if image[i] == Colour.TRANSPARENT:
                image[i] = pixel
    return image


def draw_image(image, width, height):
    image = list(map(Colour.display, image))
    area = len(image)
    lines = (''.join(image[i:i + width]) for i in range(0, area, width))
    return '\n'.join(lines)


<mask token>
for i in range(0, len(text), area):
    layers.append(text[i:i + area])
print(solve_1(layers))
print(draw_image(solve_2(layers), width, height))

class Colour:
    BLACK = '0'
    WHITE = '1'
    TRANSPARENT = '2'
    display_map = {BLACK: ' ', WHITE: '#', TRANSPARENT: '~'}

    @classmethod
    def display(cls, code):
        return cls.display_map[code]


def solve_1(layers):
    min_layer = min(layers, key=lambda layer: layer.count('0'))
    return min_layer.count('1') * min_layer.count('2')


def solve_2(layers):
    image = [Colour.TRANSPARENT] * len(layers[0])
    for layer in layers:
        for i, pixel in enumerate(layer):
            if image[i] == Colour.TRANSPARENT:
                image[i] = pixel
    return image


def draw_image(image, width, height):
    image = list(map(Colour.display, image))
    area = len(image)
    lines = (''.join(image[i:i + width]) for i in range(0, area, width))
    return '\n'.join(lines)


text = open('input.txt').read()
layers = []
width = 25
height = 6
area = width * height
for i in range(0, len(text), area):
    layers.append(text[i:i + area])
print(solve_1(layers))
print(draw_image(solve_2(layers), width, height))
