#!/usr/bin/env python3 lim = 10**12 x, y = 3, 1 blue = 3 total = 4 while total <= lim: x, y = 3*x + 8*y, 3*y + x blue = (2*y + x + 1) // 2 total = (4*y + x + 1) // 2 print(blue)