# -*- coding: utf-8 -*-
"""Problem 2
19 October 2001

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million."""

def fib(to):
	r=[]
	r.append(1)
	r.append(2)
	while True:
		new=r[-1]+r[-2]
		if new<=to:
			r.append(new)
		else:
			break
	return r


f=fib(4000000)

s=0
for i in f:
	if i%2==0:
		s=s+i

print s
	