"""
Project Euler #2: Even Fibonacci numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1  and  2, the first  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 , find the sum of the even-valued terms.

"""


def solution(n: int):
    """
    pass integer and loop while keep buffer(last one before) and current and keep updating
    the value of current fibonacci = current + buffer which current = fibonacci and buffer = current
    :param n: input
    :type n: int
    :return: sum of value that's even and not over n
    :rtype: int
    """
    if n < 2:
        return 0
    buffer = 1
    current = 1
    count = 0
    while current < n:
        temp = current + buffer
        if temp % 2 == 0 and temp < n:
            count += temp
        buffer = current
        current = temp
    return count


if __name__ == '__main__':
    print(solution(100))