def fib(): prev = 0 current = 1 while True: yield current temp = prev + current prev = current current = temp def powersof2(): current = 1 while True: yield current current *= 2 def countGuards(tot, func): guards = 0 for i in func(): tot -= i if tot < 0: if func == powersof2: tot += i if tot >= i / 2 + i / 4: guards += 1 break guards += 1 return guards def answer(total_lambs): return countGuards(total_lambs, fib) - countGuards(total_lambs, powersof2) import sys print answer(int(sys.argv[1])) # print "".join(["._-^@|X"[answer(i)] for i in range(int(sys.argv[1]))])