"""(c) WhiZTiM -------- ionogu(<_at_>)acm.org"""
"""Very Fast reusable and Dynamic Fibonacci calculator """
class Fibonacci:
def __init__(self):
self.memory = [0, 1, 1]
def compute(self, n):
if n < len(self.memory):
return self.memory[n]
c1 = self.compute(n - 1)
c2 = self.compute(n - 2)
self.memory.append(c1 + c2)
return c1 + c2
def solve(limit):
fib = Fibonacci(); rtn = []
for x in range(limit):
n = fib.compute(x)
if n > limit: return rtn
if n % 2 == 0: rtn.append(n)
print(sum(solve(4000000)))
IiIiKGMpIFdoaVpUaU0gICAtLS0tLS0tLSBpb25vZ3UoPF9hdF8+KWFjbS5vcmciIiIKCiIiIlZlcnkgRmFzdCByZXVzYWJsZSBhbmQgRHluYW1pYyBGaWJvbmFjY2kgY2FsY3VsYXRvciAiIiIKY2xhc3MgRmlib25hY2NpOgoJZGVmIF9faW5pdF9fKHNlbGYpOgoJCXNlbGYubWVtb3J5ID0gWzAsIDEsIDFdCglkZWYgY29tcHV0ZShzZWxmLCBuKToKCQlpZiBuIDwgbGVuKHNlbGYubWVtb3J5KToKCQkJcmV0dXJuIHNlbGYubWVtb3J5W25dCgkJYzEgPSBzZWxmLmNvbXB1dGUobiAtIDEpCgkJYzIgPSBzZWxmLmNvbXB1dGUobiAtIDIpCgkJc2VsZi5tZW1vcnkuYXBwZW5kKGMxICsgYzIpCgkJcmV0dXJuIGMxICsgYzIKCmRlZiBzb2x2ZShsaW1pdCk6CglmaWIgPSBGaWJvbmFjY2koKTsgcnRuID0gW10KCWZvciB4IGluIHJhbmdlKGxpbWl0KToKCQluID0gZmliLmNvbXB1dGUoeCkKCQlpZiBuID4gbGltaXQ6IHJldHVybiBydG4KCQlpZiBuICUgMiA9PSAwOiBydG4uYXBwZW5kKG4pCgpwcmludChzdW0oc29sdmUoNDAwMDAwMCkpKQ==