···11+import fileinput
22+from collections import Counter, defaultdict
33+44+from utils import parse_line
55+66+SQUARES = Counter()
77+CLAIMS = defaultdict(list)
88+99+for i, line in enumerate(fileinput.input()):
1010+ _id, x, y, w, h = parse_line(r'#(\d+) @ (\d+),(\d+): (\d+)x(\d+)', line)
1111+1212+ for i in range(x, x + w):
1313+ for j in range(y, y + h):
1414+ SQUARES[(i, j)] += 1
1515+ CLAIMS[_id].append((i, j))
1616+1717+print "Square inches of fabric within multiple claims:", sum(n > 1 for c, n in SQUARES.items())
1818+1919+for _id in CLAIMS:
2020+ for pos in CLAIMS[_id]:
2121+ if SQUARES[pos] != 1:
2222+ break
2323+ else:
2424+ print "ID of only non-overlapping claim:", _id