# 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, ...
# By considering the terms in the Fibonacci sequence whose values do not exceed four million,
# find the sum of the even-valued terms.
def problem0002(MaxValue):
    fib_Present = 1
    fib_Future = 2
    answer = 0
    while True:
        if fib_Present % 2 == 0:
            answer += fib_Present
        if fib_Future > MaxValue:
            return answer
        fib_Present,fib_Future = fib_Future,fib_Present + fib_Future

if __name__ == "__main__":
    assert problem0002(1) == 0
    assert problem0002(10) == 10
    assert problem0002(50) == 44
    assert problem0002(100) == 44
    print (problem0002(4000000))