# Unbounded B3/S23. Coordinates are integer (x, y) tuples.
from collections import Counter


def next_generation(live):
    counts = Counter(
        (x + dx, y + dy)
        for x, y in live
        for dy in (-1, 0, 1)
        for dx in (-1, 0, 1)
        if dx != 0 or dy != 0
    )
    return {
        position
        for position, count in counts.items()
        if count == 3 or (count == 2 and position in live)
    }


if __name__ == "__main__":
    live = {(0, 1), (1, 1), (2, 1)}
    for generation in range(3):
        print(generation, sorted(live))
        live = next_generation(live)
