def toggle_middle_bits(n):
    def set_middle_bits(n):  
        n |= n >> 1; 
        n |= n >> 2; 
        n |= n >> 4; 
        n |= n >> 8; 
        n |= n >> 16;  
        return (n >> 1) ^ 1
     
    if (n == 1): 
        return 1
    return n ^ set_middle_bits(n) 
def count_ways(n):
	 
	A = [0] * (n + 1) 
	B = [0] * (n + 1) 
	A[0] = 1
	A[1] = 0
	B[0] = 0
	B[1] = 1
	for i in range(2, n+1): 
		A[i] = A[i - 2] + 2 * B[i - 1] 
		B[i] = A[i - 1] + B[i - 2] 
	return A[n] 