def check_hv(p1, p2):
    return p1[0] == p2[0] or p1[1] == p2[1]

def draw(g, p1, p2):
    # print(list(zip(range(p1[0], p2[0], 1 if p1[0] < p2[0] else -1), range(p1[1], p2[1], 1 if p1[0] < p2[0] else -1))))
    if not check_hv(p1, p2):
        # print(f"{p1}, {p2}")
        n_steps = (max(p1[0], p2[0]) + 1) - min(p1[0], p2[0])
        # print(n_steps)
        # n_steps = max((max(p1[0], p1[0]) + 1) - min(p1[0], p1[0]), (max(p1[1], p1[1]) + 1) - min(p1[1], p1[1]))
        for i in range(n_steps):
            g[p1[1] + (i if p1[1] < p2[1] else -i)][p1[0] + (i if p1[0] < p2[0] else -i)] += 1
    elif p1[0] == p2[0]:
        for i in range(min(p1[1], p2[1]), max(p1[1], p2[1]) + 1):
            grid[i][p1[0]] += 1
    else:
        for i in range(min(p1[0], p2[0]), max(p1[0], p2[0]) + 1):
            # print(f"{i}, {p1[1]}")
            grid[p1[1]][i] += 1

with open("input.txt", 'r') as f:
    coords = []
    max_x = 0
    max_y = 0
    grid = []

    for line in f.readlines():
        if line:
            c1, c2 = line.strip().split(" -> ")
            p1 = list(map(int, c1.split(',')))
            p2 = list(map(int, c2.split(',')))

            coords.append([p1, p2])
            max_x = max([max_x, p1[0], p2[0]])
            max_y = max([max_y, p1[1], p2[1]])

    for i in range(max_y + 1):
        grid.append([0] * (max_x + 1))

    print(len(coords))
    print(f"{max_x}, {max_y}")
    print(f"{len(grid[0])}, {len(grid)}")

    # exit()

    for c in coords:
        draw(grid, *c)

    with open("output.txt", 'w') as of:
        of.write(str(grid))

    c_two = 0

    for i in range(len(grid)):
        for j in range(len(grid[0])):
            if grid[i][j] >= 2:
                c_two += 1

    print(c_two)
