Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.

Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109 + 9).

Input

The single line contains three space-separated integers n, m and k (2 ≤ k ≤ n ≤ 109; 0 ≤ m ≤ n).

Output

Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 9).

Examples

Input

5 3 2


Output

3


Input

5 4 2


Output

6

Note

Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.

Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.

Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though 2000000020 mod 1000000009 is a smaller number.
import java.util.*;
import java.io.*;


public class A2 {
/*



 */
    public static void main(String[] args) throws Exception {
        uu.s1();
        uu.out.close();
    }
    public static class uu {
        public static BR in = new BR();
        public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        public static boolean bg = true;
        public static MOD m1 = new MOD(1000000000+9);
        public static long mod = 1000000000+9;
        public static void s1() throws Exception {
            long n = in.ni();
            long m = in.ni();
            long k = in.ni();
            long lose = n - m;
            long aval = m / (k - 1l);
            long times1 = Math.min(lose, aval);
            long notused = times1 * (k - 1l);
            long used = m - notused;
            long blocks = used / k;
            long left = used % k;
            long k1 = 0;
            if (blocks != 0){
                k1 = m1.pow(2, blocks+1);
                k1 = m1.s(k1, 2);
            }
            long ans = (m1.t(k, k1)+left + notused)%mod;
            pn(ans);
        }
        public static void geom(long f1){
        }
        
        public static void s2() throws Exception {
            
        }
        public static void s3() throws Exception {
            
        }
        
        private static void pn(Object... o1) {
            for (int i = 0; i < o1.length; i++){
                if (i!= 0) out.print(" ");
                out.print(o1[i]);
            }
            out.println();
        }

        public static boolean allTrue(boolean ... l1){
            for (boolean e: l1) if (!e) return false;
            return true;
        }
        public static boolean allFalse(boolean ... l1){
            for (boolean e: l1) if (e) return false;
            return true;
        }
    }
    private static class MOD {
        public long mod = -1;

        public MOD(long k1) {
            mod = k1;
        }

        public long cl(long n1){
            long fin = n1%mod;
            if (fin<0) fin+= mod;
            return fin;
        }
        
        public long s(long n1, long n2) {
            long k1 = (n1 - n2) % mod;
            if (k1 < 0)
                k1 += mod;
            return k1;
        }

        public long t(long n1, long n2) {
            long k1 = (n1 * n2) % mod;
            if (k1 < 0)
                k1 += mod;
            return k1;
        }

        public static long xgcd(long n1, long n2) {
            long k1 = n1;
            long k2 = n2;
            long[] l1 = { 1, 0 };
            long[] l2 = { 0, 1 };
            for (;;) {
                long f1 = k1 / k2;
                long f2 = k1 % k2;
                if (f2 == 0)
                    break;

                long[] l3 = { 0, 0 };
                l3[0] = l1[0] - f1 * l2[0];
                l3[1] = l1[1] - f1 * l2[1];
                l1 = l2;
                l2 = l3;

                k1 = k2;
                k2 = f2;
            }
            long fin = l2[1] % n1;
            if (fin < 0) {
                fin += n1;
            }
            return fin;
        }

        public long pow(long n1, long pow) {
            if (pow == 0)
                return 1;
            else if (pow == 1)
                return t(1l, n1);
            else if ((pow & 1) == 0) {
                long half = pow(n1, pow >> 1);
                return t(half, half);
            } else {
                long half = pow(n1, pow >> 1);
                return t(half, t(half, n1));
            }
        }

        public long factorial(long k1, long n1) {
            long fin = 1;
            long q1 = k1;
            for (int i = 0; i < n1; i++) {
                fin = t(fin, q1);
                q1--;
                if (q1 <= 0)
                    break;
            }
            return cl(fin);
        }

    }
    
    private static class BR {
        BufferedReader k1 = null;
        StringTokenizer k2 = null;

        public BR() {
            k1 = new BufferedReader(new InputStreamReader(System.in));
        }
        public String nx() throws Exception {
            for (;;) {
                if (k2 == null || !k2.hasMoreTokens()) {
                    String temp = k1.readLine();
                    if (temp == null)
                        return null;
                    k2 = new StringTokenizer(temp);
                }
                else
                    break;
            }

            return k2.nextToken();
        }

        public int ni() throws Exception {
            return Integer.parseInt(nx());
        }
    }
}
