Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Fibonacci Number

  Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula:

\begin{equation*}
fib(n)= \left \{
\begin{array}{ll}
1　         &   (n = 0)          \\
1　         &  (n = 1) \\
fib(n - 1) + fib(n - 2)  & \\
\end{array}
\right.
\end{equation*}

Input

  An integer $n$ is given.

output

  Print the $n$-th fibonacci number in a line.

Constraints

$0 \leq n \leq 44$

Sample Input 1

3

Sample Output 1

3



Sample input:
3


Sample output:
3

Submission status: Wrong Answer

Solution code:
def fib(n):
    n=int(n)
    F=[1,1]
    for i in range(1,n):
        F.append(F[i-1]+F[i])
    
    return F[n]

Submission status: Wrong Answer

Solution code:
def fib(n):
    n=int(n)
    F=[1,1]
    for i in range(1,n):
        F.append(F[i-1]+F[i])
    
    return F[n]
    
a=input(int())
fib(a)

Submission status: Wrong Answer

Solution code:
def fib(n):
    n=int(n)
    F=[1,1]
    if n>=2:
        for i in range(1,n):
            F.append(F[i-1]+F[i])
    
    return F[n]
    
a=input(int())
fib(a)

Submission status: Wrong Answer

Solution code:
n = input()

if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    fib = [0 for i in range(n + 1)]

    fib[0] = 1
    fib[1] = 1

    for i in range(2, n):
        fib[i] = fib[i - 1] + fib[i - 2]

    print(fib[n - 1])

Submission status: Wrong Answer

Solution code:
n = input()

if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    fib = [0 for i in range(n + 1)]

    fib[0] = 1
    fib[1] = 1

    for i in range(2, n):
        fib[i] = fib[i - 1] + fib[i - 2]

    print(fib[n])

Submission status: Wrong Answer

Solution code:
n = input()

if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    fib = [0 for i in range(n + 1)]

    fib[0] = 1
    fib[1] = 1

    for i in range(2, n + 1):
        print(i)
        fib[i] = fib[i - 1] + fib[i - 2]

    print(fib[n])

Submission status: Wrong Answer

Solution code:
def fib_iter(n):
  fib_n  = 0
  fib_n2 = 1
  fib_n1 = 1
  for i in range(n - 1):
    fib_n  = fib_n1 + fib_n2
    fib_n2 = fib_n1
    fib_n1 = fib_n
  return fib_n

x = int(raw_input())

print fib_iter(x)

Submission status: Wrong Answer

Solution code:
def fib2(n):
    a1, a2 = 1, 0
    while n > 0:
        a1, a2 = a1 + a2, a1
        n -= 1
    return a1

Submission status: Wrong Answer

Solution code:
answer_list = [1, 1] + [None] * 43

def fib(num):
    ans = answer_list[num]
    if ans:
        return ans
    ans = fib(num - 1) + fib(num - 2)
    answer_list[num] = ans
    return ans

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = input()
    F = []
    F.append(1)
    F.append(1)
    for i in range(2,n+1):
        F.append(F[i-1] + F[i-2])
        print(F[i])

    print(F[n])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

memo = ['' for i in xrange(45)]
dp = [0 for i in xrange(45)]


# ?????°?????¨?¨??????????O(2^n)?????????
def recursion(n):
    if n == 0 or n == 1:
        return 1

    return recursion(n - 1) + recursion(n - 2)


# ?????¢??????????????°?¨??????????O(n)?????§????????§??????
def memo_search(n):
    if memo[n] != '':
        return memo[n]
    else:
        if n == 0 or n == 1:
            memo[n] = 1
            return 1
        memo[n] = memo_search(n - 1) + memo_search(n - 2)
        return memo[n]


# ???????¨?????????§????¨??????????O(n)??¨??????
def dynamic_programming(n):
    for i in xrange(n):
        if i == 0 or i == 1:
            dp[i] = 1
        else:
            dp[i] = dp[i - 1] + dp[i - 2]
    # print dp
    return dp[n - 1]


if __name__ == '__main__':
    n = input()
    # print recursion(n)
    # print memo_search(n)
    print dynamic_programming(n)

Submission status: Wrong Answer

Solution code:

n=input()

fn_first=1
fn_second=1

if n <= 2:
    print fn_first
else:
    for x in xrange(n-1):
        tmp = fn_first
        fn_first = fn_first + fn_second
        fn_second = tmp

print fn_first

Submission status: Wrong Answer

Solution code:
n=input()

fn_first=1
fn_second=1

if n > 2:
    for x in xrange(n-1):
        tmp = fn_first
        fn_first = fn_first + fn_second
        fn_second = tmp

print fn_first

Submission status: Wrong Answer

Solution code:
def fib(n, a, b):
    if n == 0:
        return 0
    elif n == 1:
        return a
    else: return fib(n-1, a+b, a)

N = int(input())
a = fib(N, 1, 0)
print(a)

Submission status: Wrong Answer

Solution code:
#coding: UTF-8

s = input()
h = s/3600
s = s%3600
m = s/60
s = s%60

print str(h) + ":" + str(m) + ":" + str(s)

Submission status: Wrong Answer

Solution code:
def makeFibonacci(n):
    if n <= 2:
        return str(1)
    F = [None]*n
    F[0] = 1
    F[1] = 1
    for i in range(2, n):
        F[i] = F[i-1] + F[i - 2]
    return str(F[n-1])

n = int(input())
print(makeFibonacci(n))

Submission status: Wrong Answer

Solution code:
def fib(n):
  if n < 0:
    print("error")
    exit()
  if n < 2:
    result = 1
  result = fib(n-1) + fib(n-2)
  return result

n = int(input())
fib(n)

Submission status: Wrong Answer

Solution code:
F = {}

def fib(n):
  global F
  if n < 0:
    print("error")
    exit()
  if n < 2:
    F[n] = 1
    return F[n]
#  F[n] = fib(n-1) + fib(n-2)
  F[n] = F[n-1] + F[n-2]
  return F[n]

#n = int(input())
#print(fib(n))
#n = int(input())
#print(fib(n))
#fib(44)
for i in range(44+1):
  print(fib(i))
#  print(F[i])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
print(round((pow((1+math.sqrt(5))/2,n) - pow((1-math.sqrt(5))/2,n)) / math.sqrt(5)))

Submission status: Wrong Answer

Solution code:
def fib(a, b, fiboli):
    if len(fiboli) < n:
        fiboli.append(a + b)
        fib(b, a + b, fiboli)
    else:
        print(fiboli[-1])

fibo_list = []
n = int(input())
fibo_list.append(n-2)
fibo_list.append(n-1)

fib(n - 2, n - 1, fibo_list)

Submission status: Wrong Answer

Solution code:
def fib(a, b, fiboli):
    if len(fiboli) < n:
        fiboli.append(fiboli[-1] + fiboli[-2])
        fib(fiboli[-1], fiboli[-1] + fiboli[-2], fiboli)
    else:
        print(fiboli[-1])
        print(fiboli)

n = int(input())
if n != 0 and n != 1:
    fibo_list = []
    fibo_list.append(n - 1)
    fibo_list.append(n - 2)
    fib(n - 1, n - 2, fibo_list)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
def fib(a, b, fiboli):
    if len(fiboli) < n:
        fiboli.append(fiboli[-1] + fiboli[-2])
        fib(fiboli[-1], fiboli[-1] + fiboli[-2], fiboli)
    else:
        print(fiboli[-1])
        print(fiboli)

n = int(input())
if n == 0 or n == 1:
    print(1)
elif n == 2:
    print(2)
else:
    fibo_list = []
    fibo_list.append(n - 1)
    fibo_list.append(n - 2)
    fib(n - 1, n - 2, fibo_list)

Submission status: Wrong Answer

Solution code:
def fib(a, b, fiboli):
    if len(fiboli) < n:
        fiboli.append(fiboli[-1] + fiboli[-2])
        fib(fiboli[-1], fiboli[-1] + fiboli[-2], fiboli)
    else:
        print(fiboli[-1])
        print(fiboli)

n = 4
    # n = int(input())
if n == 0 or n == 1:
    print(1)
elif n == 2:
    print(2)
else:
    fibo_list = []
    fibo_list.append(n - 1)
    fibo_list.append(n - 2)
    fib(n - 1, n - 2, fibo_list)

Submission status: Wrong Answer

Solution code:
def fib(a, b, fiboli):
    if len(fiboli) < n:
        fiboli.append(fiboli[-1] + fiboli[-2])
        fib(fiboli[-1], fiboli[-1] + fiboli[-2], fiboli)
    else:
        print(fiboli[-1])
        print(fiboli)

# n = 4
n = int(input())
if n == 0 or n == 1:
    print(1)
elif n == 2:
    print(2)
else:
    fibo_list = []
    fibo_list.append(n - 1)
    fibo_list.append(n - 2)
    fib(n - 1, n - 2, fibo_list)

Submission status: Wrong Answer

Solution code:
def fib(numbers, find):
    if len(numbers) <= find:
        numbers.append(numbers[-1] + numbers[-2])
        fib(numbers, find)
    else:
        print(numbers)
        print(numbers[find-1])


# n = 4
n = int(input())
number_list = []


if n == 0 or n == 1:
    print(1)
else:
    number_list.append(n-2)
    number_list.append(n-1)
    fib(number_list, n)

Submission status: Wrong Answer

Solution code:
def fib(numbers, find):
    if len(numbers) < find:
        numbers.append(numbers[-1] + numbers[-2])
        fib(numbers, find)
    else:
        print(numbers)
        print(numbers[-1])


# n = 4
n = int(input())
number_list = []


if n == 0 or n == 1:
    print(1)
else:
    number_list.append(n-2)
    number_list.append(n-1)
    fib(number_list, n)

Submission status: Wrong Answer

Solution code:
target = int(input())
fib = [0 for n in range(target + 1)]
for i in range(target):
    if i == 0:
        continue
    elif i == 1:
        fib[i] = 1
    else:
        fib[i] = fib[i - 1] + fib[i - 2]
print(fib[target])

Submission status: Wrong Answer

Solution code:
target = int(input()) + 1
fib = [0 for n in range(target + 1)]
for i in range(target):
    if i == 0:
        continue
    elif i == 1:
        fib[i] = 1
    else:
        fib[i] = fib[i - 1] + fib[i - 2]
print(fib[target])

Submission status: Wrong Answer

Solution code:
n = int(input()) - 1
fib = [1, 1]
for i in range(n):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Wrong Answer

Solution code:
n = int(input()) - 1
fib = [1, 1] + [0] * n
for i in range(n):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Wrong Answer

Solution code:
n = int(input()) - 1
fib = [1, 1] + [0] * n
for i in range(2, n):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n])

Submission status: Wrong Answer

Solution code:
n = int(input()) - 1
fib = [1, 1] + [0] * n
for i in range(2, n):
    fib[i] = fib[i-1] + fib[i-2]
print(fib[n+1])

Submission status: Wrong Answer

Solution code:
memo = [0, 1]

def fib(n):
    if (n in memo):
        return memo[n]
    ans = fib(n-1) + fib(n-2)
    memo.append(ans)
    return ans

n = int(input())
print(fib(n))

Submission status: Wrong Answer

Solution code:

f = [-1 for i in range(45)]
f[0] = f[1] = 1

def fib(n):
    global f
    for i in range(2,n+1):
        f[i] = f[i - 1] + f[i - 2]
        #print(i,f[i])
    return f[n]

if __name__ == "__main__":
    n = input("input number: ")
    n = int(n)
    #print(type(n))
    print(fib(n))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May  4 20:13:10 2018
ALDS1_10_A
@author: maezawa
"""

fib_arr = [None for _ in range(45)]
fib_arr[1] = 1
fib_arr[2] = 1

def fib(n):
    if fib_arr[n] != None:
        return fib_arr[n]
    fib_arr[n] = fib(n-1)+fib(n-2)
    return fib_arr[n]
    
n = int(input())
print(fib(n))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())
F = [False for i in range(n+1)]
def fib(n):
    if n == 1 or n == 2:
        F[n] = 1
        return 1
    if F[n]:
        return F[n]
    F[n] = fib(n-2) + fib(n-1)
    return F[n]

a = fib(n)
print(a)

Submission status: Wrong Answer

Solution code:
import sys

n=input()
a,b = 0,1

for i in range(0,n):
    a,b = b,a+b;
print a

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1

    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n == 0 or n == 1:
        return 1
    else :
        return fib(n - 1) + fib(n - 2)

def main():
    print( fib( int( input() ) ) )

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n == 0 or n == 1:
        return 1
    else :
        return fib(n - 1) + fib(n - 2)


print( fib( int( input() ) ) )

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
def fib(n):
    if (n == 0 or n == 1):
        return 1
    else:
        return fib(n-1) + fib(n-2)
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
def fib(n):
    if (n == 0 or n == 1):
        return 1
    return fib(n-1) + fib(n-2)
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n==0 or n==1:
        return 1
    else:
        return fib(n-1) + fib(n-2)
print(fib(int(input())))

Submission status: Time Limit Exceeded

Solution code:
def fibonacci(n):
    if n == 0 or n == 1:
        return 1
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)
        

print(fibonacci(int(input())))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N=INT()

memo=[0]*50
memo[0]=memo[1]=1
def rec(n):
    if memo[n]:
        return memo[n]
    return rec(n-1)+rec(n-2)

print(rec(N))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
	if n == 0:
		return 1
	elif n == 1:
		return 1
	else:
		return fib(n - 1) + fib(n - 2)

n = input()
print fib(n)

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n == 0 or n == 1: return 1
    else: return fib(n-1) + fib(n-2)
print fib(int(raw_input()))

Submission status: Time Limit Exceeded

Solution code:
def Fibonacci(n):
	if n==0 or n==1 : return 1
	return Fibonacci(n-1)+Fibonacci(n-2)

print( Fibonacci( int(input()) ) )

Submission status: Time Limit Exceeded

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A
# Fibonacci Number
# Result:
import sys

fibs = []
for i in range(0, 45):
    fibs.insert(i, -1)

def calc_fib(n):
    if fibs[n] != -1: return fibs[n]
    if n == 0 or n == 1:
        fibs[n] = 1
        return 1
    else:
        return calc_fib(n - 1) + calc_fib(n - 2)

num = int(sys.stdin.readline().rstrip())
print calc_fib(num)

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
	if n<2:return 1
	else: return fib(n-1)+fib(n-2)
n=int(raw_input())
print fib(n)

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n == 0 or n == 1:
        return 1
    else :
        return fib(n-1) + fib(n-2)

n = int(input())
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
F = [0] * (n+1)

def makeFibonacci(n):
    global F
    F[0] = 1
    F[1] = 1
    for i in xrange(2,n+1):
        F[i] = makeFibonacci(i-2) + makeFibonacci(i-1)
    return F[n]

def main():
    ans = makeFibonacci(n)
    print ans
    return 0

main()

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    return 1 if n == 0 or n == 1 else fib(n - 1) + fib(n - 2)

print(fib(int(input())))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n <= 1:
        return 1
    else:
        return fib(n - 1) + fib(n - 2)

print fib(int(input()))

Submission status: Time Limit Exceeded

Solution code:
F_list = [1,1] + [None]*43

def fibo(n):
  F=F_list[n]
  if n==0 or n==1: return F
  F = fibo(n-1)+fibo(n-2)
  F_list[n]=F
  return F


n = int(input())

print(fibo(n))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


def dp(n):
    if n == 0 or n == 1:
        return 1

    for i in xrange(n):
        return dp(n - 1) + dp(n - 2)


if __name__ == '__main__':
    n = input()
    print dp(n)

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n == 0:
        return 1
    if n == 1:
        return 1
    return fib(n-1) + fib(n-2)

n = int(input())
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
#coding:UTF-8
def FN(n):
    if n==0 or n==1:
        return 1
    else:
        ans=FN(n-1)+FN(n-2)
        return ans
if __name__=="__main__":
    n=int(input())
    ans=FN(n)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def fib_1(n):
    if not n or n == 1:
        return 1
    return fib_1(n - 2) + fib_1(n - 1)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    index = int(_input[0])
    print(fib_1(index))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n <= 1:
        return 1
    else:
        return fib(n - 1) + fib(n - 2)

n = int(input())
ans = fib(n)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
  if n ==1 or n == 0:
    return 1
  else:
    return fib(n-1) + fib(n-2)
  
print(fib(int(input())))

Submission status: Time Limit Exceeded

Solution code:
def fibonacci(n):
    if n==0:
        return 1
    elif n==1:
        return 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)

n = int(input())
print(fibonacci(n))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def main():
    def _fibonacci(n):
        if n == 0:
            return 1
        elif n == 1:
            return 1
        else:
            return _fibonacci(n - 1) + _fibonacci(n - 2)

    N = int(raw_input())
    return _fibonacci(N)


print main()

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n == 0 or n == 1:
        return 1
    return fib(n-1) + fib(n-2)

n = int(input())
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
  if n < 0:
    print("error")
    exit()
  if n < 2:
    return 1
  result = fib(n-1) + fib(n-2)
  return result

n = int(input())
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
  if n < 0:
    print("error")
    exit()
  if n < 2:
    return 1
  result = fib(n-1) + fib(n-2)
  return result

#n = int(input())
for n in range(44+1):
	print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
F = {}

def fib(n):
  global F
  if n < 0:
    print("error")
    exit()
  if n < 2:
    F[n] = 1
    return F[n]
  F[n] = fib(n-1) + fib(n-2)
  return F[n]

#n = int(input())
#print(fib(n))
#n = int(input())
#print(fib(n))
fib(44)
for i in range(5+1):
  print(F[i])

Submission status: Time Limit Exceeded

Solution code:
F = {}

def fib(n):
  global F
  if n < 0:
    print("error")
    exit()
  if n < 2:
    F[n] = 1
    return F[n]
  F[n] = fib(n-1) + fib(n-2)
#  F[n] = F[n-1] + F[n-2]
  return F[n]

n = int(input())
print(fib(n))
#n = int(input())
#print(fib(n))
#fib(44)
#for i in range(44+1):
#  print(fib(i))
#  print(F[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())

def fib(N):
    if N in [0, 1]:
        return 1
    else:
        return fib(N-1) + fib(N-2)

print fib(n)

Submission status: Time Limit Exceeded

Solution code:
def fibonacci(n):
    if n == 0 or n == 1:
        return 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)

if __name__ == '__main__':
    n = int(input())
    print(fibonacci(n))

Submission status: Time Limit Exceeded

Solution code:
def fibonacci(n):
    if n == 0 or n == 1:
        return 1
    return fibonacci(n - 2) + fibonacci(n - 1)

print(fibonacci(int(input())))

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

dp = { 0: 1, 1: 1 }
def fibonacci(n):
  return dp[n] if n in dp else fibonacci(n - 1) + fibonacci(n - 2)

print(fibonacci(num))

Submission status: Time Limit Exceeded

Solution code:
f=lambda n:f(n-1)+f(n-2)if n>1 else 1
print(f(int(input())))

Submission status: Time Limit Exceeded

Solution code:
def fib(n):
    if n <= 1:
        return 1
    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8


def fib(number):
    if number == 0 or number == 1:
        return 1
    return fib(number-1) + fib(number-2)


if __name__ == '__main__':
    N = int(input())
    print(fib(N))

Submission status: Accepted

Solution code:
def memolize(f):
    cache = {}

    def helper(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]
    return helper

@memolize
def fib(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1

    return fib(n - 1) + fib(n - 2)

n = int(input())
print(fib(n))

Submission status: Accepted

Solution code:
N = int(input())

def memorize(f) :
    cache = {}
    def helper(*args) :
        if args not in cache :
            cache[args] = f(*args)
        return cache[args]
    return helper

@memorize
def fibonacci(n):
    if n == 0 or n == 1:
        return 1
    res = fibonacci(n - 2) + fibonacci(n - 1)
    return res

print(fibonacci(N))

Submission status: Accepted

Solution code:
n = int(input())
f = [1,1]
for i in range(n-1):
    fib = f[-1] + f[-2]
    f.append(fib)
print(f[n])

Submission status: Accepted

Solution code:
n = int(input().strip())
if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    lst = [0 for i in range(0,n+1)]
    lst[0] = 1
    lst[1] = 1
    for i in range(0,n-1):
        lst[i+2] = lst[i+1] + lst[i]
    print(lst[n])

Submission status: Accepted

Solution code:
def fib(n):
    if n ==0 or n == 1:
        return 1
    l = [0] * (n+1)
    l[0] = 1
    l[1] = 1

    for i in range(2,n+1):
        l[i] = l[i-2] + l[i-1]
    return l[i]

print(fib(int(input())))

Submission status: Accepted

Solution code:
n = int(input())
fib = [0] * (n + 1)
if n == 0 or n == 1:
    print(1)
    exit()
    
fib[0] = 1
fib[1] = 1
for i in range(2, n + 1):
    fib[i] = fib[i - 1] + fib[i -2]

print(fib[-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N=INT()

dp=[0]*50
dp[0]=dp[1]=1
for i in range(2, 50):
    dp[i]=dp[i-1]+dp[i-2]

print(dp[N])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N=INT()

memo=[0]*50
memo[0]=memo[1]=1
def rec(n):
    if memo[n]:
        return memo[n]
    memo[n]=rec(n-1)+rec(n-2)
    return memo[n]

print(rec(N))

Submission status: Accepted

Solution code:
fib = [0 for i in range(45)]
fib[0] = 1
fib[1] = 1
for i in range(2, 45):
  fib[i] = fib[i - 1] + fib[i - 2]
n = int(input())
print(fib[n])

Submission status: Accepted

Solution code:
cache = {}
def fib(x):
	if x in cache:
		return cache[x]
	elif x == 0 or x == 1:
		return 1
	else:
		v = fib(x - 1) + fib(x - 2)
		cache[x] = v
		return v

x = input()
print fib(x)

Submission status: Accepted

Solution code:
def memoize(f):  
    cache = {}  
    def helper(x):  
        if x not in cache:              
            cache[x] = f(x)  
        return cache[x]  
    return helper 
         
@memoize
def fib(n):
    if n in (0, 1):
        return 1
    else:
        return fib(n - 1) + fib(n - 2)
 
print(fib(int(input())))

Submission status: Accepted

Solution code:
def fib(n):
    def iter(a, b, cnt):
        if cnt == 0:
            return a
        return iter(b, a+b, cnt-1)
    return iter(1, 1, n)

if __name__ == '__main__':
    n = int(input())
    print(fib(n))

Submission status: Accepted

Solution code:
def Fibonacci(n, a1, a2):
	if n<1 : return a1
	return Fibonacci(n-1,a1+a2,a1)

print( Fibonacci( int(input()), 1, 0 ) )

Submission status: Accepted

Solution code:
def fib(n):
    global f
    if f[n]==False:
        val=fib(n-1)+fib(n-2)
        f[n]=val
        return val
    else:
        return f[n]


n=int(input())
N=44+1
f=[1,1]
f.extend([0]*N)
fib(N)
print(f[n])

Submission status: Accepted

Solution code:
#!/usr/bin/python3

# main
n = int(input()) - 1
fib = [1, 2]
for i in range(2, n + 1):
    fib.append(fib[i - 1] + fib[i - 2])
print(fib[n])

Submission status: Accepted

Solution code:
n = int(raw_input())
dp = {}

def fib(n):
    if n in dp: return dp[n]
    if n == 0:
        dp[n] = 1
        return 1
    elif n == 1:
        dp[n] = 1
        return 1
    else:
        dp[n] = fib(n-1)+fib(n-2)
        return dp[n]

print fib(n)

Submission status: Accepted

Solution code:
n = input()

if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    fib = [0 for i in range(n + 1)]

    fib[0] = 1
    fib[1] = 1

    for i in range(2, n + 1):
        fib[i] = fib[i - 1] + fib[i - 2]

    print(fib[n])

Submission status: Accepted

Solution code:
#-------------------------------------------------------------------------------
# coding: utf-8
# Created:     16/12/2015

import sys
io = sys.stdin

n = io.readline()

a0, a1 = [1, 1]
a2 = 1
for i in xrange(int(n)-1):
    a2 = a0 + a1
    a0, a1 = a1, a2

print a2

Submission status: Accepted

Solution code:
def fib(n):
  if F[n] != 0:
    return F[n]
  elif n==0 or n==1:
    F[n] = 1
  else:
    F[n] = fib(n-1) + fib(n-2)

  return F[n]



n = input()
F = [0 for row in range(n+1)]
print fib(n)

Submission status: Accepted

Solution code:
def fib_iter(n):
  fib_n  = 1
  fib_n2 = 1
  fib_n1 = 1
  for i in range(n - 1):
    fib_n  = fib_n1 + fib_n2
    fib_n2 = fib_n1
    fib_n1 = fib_n
  return fib_n

x = int(raw_input())

print fib_iter(x)

Submission status: Accepted

Solution code:
memo = {}

def fib_memo(n):
  if n <= 1:
    return 1
  if n in memo:
    return memo[n]
  memo[n] = fib_memo(n - 1) + fib_memo(n - 2)
  return memo[n]

x = int(raw_input())

print fib_memo(x)

Submission status: Accepted

Solution code:
n = int(input())


def memoize(f):
    memo = [1, 1] + [0] * max(0, n - 1)

    def main(i):
        if memo[i]:
            return memo[i]
        result = memo[i] = f(i)
        return result

    return main


@memoize
def fibonacci(i):
    return fibonacci(i - 1) + fibonacci(i - 2)


print(fibonacci(n))

Submission status: Accepted

Solution code:
n = int(raw_input())
F = [0] * (n+1)



def fibonacci(n):
    global F
    if n == 0 or n == 1:
        F[n] = 1
        return F[n]
    if F[n] != 0:
        return F[n]
    F[n] = fibonacci(n-2) + fibonacci(n-1)
    return F[n]

def makeFibonacci(n):
    global F
    F[0] = 1
    F[1] = 1
    for i in xrange(2,n+1):
        F[i] = makeFibonacci(i-2) + makeFibonacci(i-1)
    return F[n]

def main():
    ans = fibonacci(n)
    print ans
    return 0

main()

Submission status: Accepted

Solution code:
class Fib():
    f = [1] * 50
    def fib(self, n):
        for i in range(2, n + 1):
            self.f[i] = self.f[i - 1] + self.f[i - 2]
        return(self.f[n])

x = Fib()
print(x.fib(int(input())))

Submission status: Accepted

Solution code:

fibo_list=[0 for i in range(48)]

def fibo(n):
    f=fibo_list[n]
    if f:
        return f
    else:
        if n==0 or n==1:
            return 1
        else:
            f=fibo(n-1)+(fibo(n-2))
    fibo_list[n]=f
    return f


n=input()
print(fibo(n))

Submission status: Accepted

Solution code:
def fib(n):
    n1 = n2 = tmp = 1
    for _ in range(n - 1):
        tmp = n1 + n2
        n1, n2 = n2, tmp
    return tmp

print(fib(int(input())))

Submission status: Accepted

Solution code:
a,b = 1,1
n = int(input())
for i in range(n):
	a,b = b,a+b


print(a)

Submission status: Accepted

Solution code:
def fibo(n):
	S=[1,1]
	s=1
	if n>1:
		for i in range(2,n+1):
			S.append(S[i-1]+S[i-2])
			s=S[i]
	return s

def main():
	if __name__=="__main__":
		n=input()
		print(fibo(n))

main()

Submission status: Accepted

Solution code:
def fibo(n):
	S=[1,1]
	s=1
	if n>1:
		for i in range(2,n+1):
			S.append(S[i-1]+S[i-2])
			s=S[i]
	return s

def main():
	if __name__=="__main__":
		n=int(input())
		print(fibo(n))

main()

Submission status: Accepted

Solution code:
def fib2(n):
    a1, a2 = 1, 0
    while n > 0:
        a1, a2 = a1 + a2, a1
        n -= 1
    return a1


n = int(input())

print(fib2(n))

Submission status: Accepted

Solution code:
answer_list = [1, 1] + [None] * 43

def fib(num):
    ans = answer_list[num]
    if ans:
        return ans
    ans = fib(num - 1) + fib(num - 2)
    answer_list[num] = ans
    return ans


n = int(input())

print(fib(n))

Submission status: Accepted

Solution code:
def deco_fibo(func):
    answer_list = [1, 1] + [None] * 43
    def main_fibo(i):
        ans = answer_list[i]
        if ans:
            return ans
        ans = func(i)
        answer_list[i] = ans
        return ans
    return main_fibo

@deco_fibo
def fibo(num):
    return fibo(num - 1) + fibo(num - 2)


n = int(input())

print(fibo(n))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

fib = [1, 1]
for i in range(2, 45):
    fib.append(fib[i-1]+fib[i-2])

n = int(raw_input())
print fib[n]

Submission status: Accepted

Solution code:
def fibonum():
    global F
    F[0]=1
    F[1]=1
    for i in xrange(2,n+1):
        F[i]=F[i-1]+F[i-2]
    return F[n]

n=input()
F=[0]*(n+1)
num=fibonum()
print(num)

Submission status: Accepted

Solution code:
def fib(n):
    if ft[n] != 0:
        return ft[n]
    else:
        ft[n] = fib(n - 1) + fib(n - 2)
        return ft[n]

ft = [0] * 45
ft[0] = ft[1] = 1
print fib(int(input()))

Submission status: Accepted

Solution code:
def fib(n, fib_memo=None):                                                                                                                                                    
    if fib_memo == None:                                                                                                                                                      
        fib_memo = [None]*n                                                                                                                                                   
    if n <= 1:                                                                                                                                                                
        return 1                                                                                                                                                              
    else:                                                                                                                                                                     
        if fib_memo[n-1] == None:                                                                                                                                             
            fib_memo[n-1] = fib(n-1, fib_memo)                                                                                                                                
        if fib_memo[n-2] == None:                                                                                                                                             
            fib_memo[n-2] = fib(n-2, fib_memo)                                                                                                                                
        return fib_memo[n-1] + fib_memo[n-2]                                                                                                                                  
                                                                                                                                                                              
                                                                                                                                                                              
if __name__ == '__main__':                                                                                                                                                    
    n = input()                                                                                                                                                               
    print(fib(int(n)))