f :: [Int] -> Int f [] = 1 f [x] = x + 1 f (x:y:xs) = mod ((x*f(y:xs))+y*f(xs)) 1000000007 main = do print (f (map (2^) [0,3,0,1,2,1,3,1,0]))