from PIL import Image


def parse_number(string):
    base, number = string.split(":")
    return int(number, int(base))


with open("barevna.in") as file:
    width, height = map(int, file.readline().split("x"))

    pixels = [(0, 0, 0) for _ in range(height * width)]
    for line in file:
        location, color = line.split(";")
        x, y = map(parse_number, location.split(","))
        r, g, b = map(parse_number, color.split(","))
        pixels[y * width + x] = (r, g, b)

im = Image.new("RGB", (width, height))
im.putdata(pixels)
im.save("barevna.png")
