#!/usr/bin/env python3 import re lines = (x.strip() for x in open("input.txt")) # all lines of possible positions # mx+b; tl/br have m=1; tr/bl have m=-1 tl, tr, bl, br = set(), set(), set(), set() stations = [] for line in lines: x, y, bx, by = map(int, re.search(r"(-?\d+).+?(-?\d+).+?(-?\d+).+?(-?\d+)", line).groups()) dist = abs(x-bx) + abs(y-by) + 1 tl.add(y-dist+x) br.add(y+dist+x) bl.add(y+dist-x) tr.add(y-dist-x) stations.append((x, y, dist)) for bu, bd in ((a, b) for a in tl & br for b in tr & bl): # -x+bu=x+bd <=> x=(bd-bu)/2 x = (bu-bd)//2 y = x+bd if all(abs(x-sx)+abs(y-sy) >= dist for sx, sy, dist in stations): print(x*4000000+y)