#!/usr/bin/env python3 import re from collections import defaultdict from itertools import repeat lines = (x.strip() for x in open("input.txt")) points = defaultdict(int) for line in lines: [x1, y1, x2, y2] = list(map(int, re.match(r"(\d+),(\d+) -> (\d+),(\d+)", line).groups())) for x, y in zip( range(x1, x2+(x1 <= x2)*2-1, (x1 <= x2)*2-1) if x1 != x2 else repeat(x1), range(y1, y2+(y1 <= y2)*2-1, (y1 <= y2)*2-1) if y1 != y2 else repeat(y1) ): key = '{},{}'.format(x, y) points[key] = points[key] + 1 print(sum(val >= 2 for val in points.values()))