Multiples of three from 0, 1, and 2 (Large)

Count N-digit numbers made only of the digits 0, 1, and 2 that are divisible by 3, with no leading zero, modulo 1e9+9.

Medium4Dynamic programmingCombinatoricsMathNo attempts yetTime limit2sMemory limit256 MB

Problem

Ukje likes the syllable sam, which is how Korean reads the number 3. He tacks it onto the end of his sentences for fun, so he decided to spend the day playing with the number 3 as well.

Build NN-digit multiples of 3 using only the three digits 0, 1, and 2. The number you build is a natural number, so it cannot start with 0. How many such numbers are there?

Input

The first line contains NN. (1 ≤ NN ≤ 33,333)

Output

Print how many NN-digit multiples of 3 can be written with only the digits 0, 1, and 2. The count can grow very large, so print it modulo 1,000,000,009 (109+910^9+9).