codeparrot/codecomplex huggingface dataset:
// Problem: 338_A. Quiz
// Time complexity: logn
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author BSRK Aditya
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long numQuestions = in.nextInt();
        long numCorrectlyAnsweredQuestions = in.nextInt();
        long sizeForDoublingScore = in.nextInt();

        long score = 0;

        long numIncorrectlyAnsweredQuestions = numQuestions - numCorrectlyAnsweredQuestions;

        long numDoublings = Math.max(numQuestions / sizeForDoublingScore - numIncorrectlyAnsweredQuestions, 0);
        score += 2*sizeForDoublingScore*Long.parseLong(new BigInteger("2").modPow(new BigInteger(String.valueOf(numDoublings)), new BigInteger("1000000009")).subtract(BigInteger.ONE).toString());
        score += numCorrectlyAnsweredQuestions - sizeForDoublingScore*numDoublings;
        score %= 1000000009;

        out.println(score);
    }
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;


public class A {
	
	private long pow(long num, long pow, long mod) {
		if (pow <= 0) {
			return 1;
		}
		if ((pow & 1) != 0) {
			return (num * pow(num, pow-1, mod)) % mod;
		}
		else {
			long tmp = pow(num, pow>>1, mod) % mod;
			return (tmp*tmp)%mod;
		}
	}
	
	public void run() {
		long MOD = 1000000009;
		long n = nextInt();
		long m = nextInt();
		long k = nextInt();
		
		long critical = n/k;
		if (n-critical >= m) {
			out.println(m);
		}
		else {
			long doubles = m - (n-critical);
			long ans = (pow(2, doubles + 1, MOD) - 2 + MOD)%MOD;
			ans = (ans * k)%MOD;
			ans = (ans + (m-(doubles*k)))%MOD;
			out.println(ans);
		}
		out.flush();
	}
	
	private static BufferedReader br = null;
	private static StringTokenizer stk = null;
	private static PrintWriter out = null;
	
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		(new A()).run();
	}
	
	private void loadLine() {
		try {
			stk = new StringTokenizer(br.readLine());
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private int nextInt() {
		while (stk==null || !stk.hasMoreElements()) loadLine();
		return Integer.parseInt(stk.nextToken());
	}
	
	private long nextLong() {
		while (stk==null || !stk.hasMoreElements()) loadLine();
		return Long.parseLong(stk.nextToken());
	}
	
	private double nextDouble() {
		while (stk==null || !stk.hasMoreElements()) loadLine();
		return Double.parseDouble(stk.nextToken());
	}
	
	private String nextWord() {
		while (stk==null || !stk.hasMoreElements()) loadLine();
		return (stk.nextToken());
	}
	
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.util.*;

public class Quiz{
	static int MOD = (int)1e9 + 9;
	public static void main(String[] args){
		Scanner reader = new Scanner(System.in);
		long n = reader.nextInt();
		long m = reader.nextInt();
		long k = reader.nextInt();
		
		long r = (n + k - 1)/k;
		
		long longDrops = n%k;
		
		if(longDrops == 0){
			long d = m - (r * (k-1));
			
			if(d <= 0){
				System.out.println(m);
				return;
			}
			
			long sum = (fastExpo(2,d+1)-2) * k + (m - d*k);
			System.out.println((sum+MOD)%MOD);
		}else{
			long d = (m-longDrops*r) - (r-1)*(k-longDrops-1);
			
			if(d <= 0){
				System.out.println(m);
				return;
			}
			
			long sum = (fastExpo(2,d+1)-2) * k + (m - d*k);
			System.out.println((sum+MOD)%MOD);
		}
	}
	
	public static long fastExpo(long b, long p){
		if(p == 0)
			return 1;
		if(p % 2 == 1)
			return (b * fastExpo(b, p-1))%MOD;
		long x = fastExpo(b, p/2);
		return (x * x)%MOD;
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class cf337c {
  static long mod,n,m,k;
  public static void main(String[] args) {
    FastIO in = new FastIO(), out = in;
    n = in.nextLong();
    m = in.nextLong();
    k = in.nextLong();
    mod = (long)1e9 + 9;
    long x = m - (n-n%k)/k * (k-1) - n%k;
    if(x < 0) x = 0;
    long ans = (pow(2,x+1)-2)*k + m-x*k;
    ans = ((ans%mod)+mod)%mod;
    out.println(ans);
    out.close();
  }
  static long pow(long x, long p) {
    if(p == 0) return 1%mod;
    long ans = pow(x,p/2);
    ans = (ans*ans)%mod;
    if(p%2 == 1) ans = (ans*x)%mod;
    return ans;
  }
  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;
    
    public FastIO() {
      this(System.in,System.out);
    }
    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }
    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch(Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }
    public int numTokens() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }
    public String next() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }
    public double nextDouble() {
      return Double.parseDouble(next());
    }
    public long nextLong() {
      return Long.parseLong(next());
    }
    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.math.BigInteger;
import java.util.*;

public class A {
	private static Scanner in;
	
	final int M = 1000000009;

	public void run() {
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int z = n - m;
		if (z >= n / k) {
			System.out.println(m);
			return;
		}
		int f = n - k * z;
		int ans = BigInteger.ONE.shiftLeft(f / k + 1).remainder(BigInteger.valueOf(M)).intValue();
		System.out.println(((ans + M - 2L) * k + (f % k + (k - 1) * z)) % M);
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		in = new Scanner(System.in);
		new A().run();
		in.close();
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class A{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int mod=(int)1e9+9;

	long n, m, k;

	void run(){
		n=sc.nextLong();
		m=sc.nextLong();
		k=sc.nextLong();
		solve();
	}

	void solve(){
		long ans=0;
		long s=n-m;
		long remain=max(n-s*k, 0);
//		debug("remain", remain);
		ans=m-remain;
//		debug("ans", ans);
		long r=remain%k;
		ans=(ans+r)%mod;
		remain-=r;
//		debug("remain2", remain);
		long a=remain/k;
		long add=(powMod(2, a, mod)-1)*k%mod*2%mod;
//		debug("add", add);
		ans=(ans+add)%mod;
//		debug(ans);
		println(ans+"");
	}

	long powMod(long x, long k, long mod){
		if(k==0){
			return 1%mod;
		}else if(k%2==0){
			return powMod(x*x%mod, k/2, mod);
		}else{
			return x*powMod(x, k-1, mod)%mod;
		}
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args){
		Locale.setDefault(Locale.US);
		new A().run();
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class C {
    private static BufferedReader in;
    private static StringTokenizer st;
    private static PrintWriter out;
    
    public static void main(String[] args) throws NumberFormatException, IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        int mod = (int) (1e9+9);
        int correct = n - n / k;
        int carry = n % k;
        long ans;
        if(correct >= m){
            ans = m;
        }else{
            m -= correct;
            int block = n / k;
            BigInteger pow = BigInteger.valueOf(2).modPow(BigInteger.valueOf(m + 1), BigInteger.valueOf(mod));
            ans = (pow.longValue() - 2 + mod) % mod;
            ans = (ans * (long) k) % mod;
            ans = (ans + (long)(block - m)* (long)(k-1) + carry) % mod;
        }
        System.out.println(ans);
        
    }

    static String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
    static int nextInt() throws NumberFormatException, IOException{
        return Integer.parseInt(next());
    }
    static long nextLong() throws NumberFormatException, IOException{
        return Long.parseLong(next());
    }
    
    static double nextDouble() throws NumberFormatException, IOException{
        return Double.parseDouble(next());
    }

}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.*;
import java.util.*;

public class History {
	static final int INF = (int)1E9;
	static final double EPS = 1E-9;
	static final long MOD = INF + 9;
	
	static long powmod(long p) {
		long res = 1;
		long d = 2;
		while (p > 0) {
			if (p % 2 == 1) {
				res = (res * d) % MOD;
				p--;
			}
			else {
				d = (d * d) % MOD;
				p /= 2;
			}
		}
		return res % MOD;
	}
	
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		long n = in.nextLong();
		long m = in.nextLong();
		long k = in.nextLong();
		
		long ans = 0;
		
		long t = (k - 1) * (n - m);
		
		if (t <= m) {
			n -= k * (n - m);
			
			long g = n / k;
			
			ans = 2 * k * (powmod(g) - 1) + n % k;
			
			ans = (ans + t) % MOD;
		}
		else {
			ans = m;
		}
		
		System.out.println(ans % MOD);
	}
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
    	return Long.parseLong(next());
    };
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.*;
import java.util.StringTokenizer;

public class A {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void solve() throws IOException {
		final int mod = 1000*1000*1000+9;
		long n = readInt();
		long m = readInt();
		long k = readInt();
		long fail = n-m;
		long posl = n / k ;
		if(n % k != 0) {
			posl++;
		}
		if(posl <= fail) {
			out.println(m);
		} else {
			long d = fail - posl;
			long res = (k-1) * fail;
			m -= (k-1) * fail;
			long z = m / k;
			res += m % k;
			res %= mod;
			long x = binpow(2, z+1, mod);
			x -= 2;
			x += mod;
			x %= mod;
			x *= k;
			res += x;
			res %= mod;
			out.println(res);
		}
    }

	long binpow (long a, long n, long mod) {
		long res = 1;
		while (n != 0)
			if ((n & 1) != 0) {
				res *= a;
				res = res % mod;
				--n;
			}
			else {
				a *= a;
				a = a % mod;
				n >>= 1;
			}
		return res;
	}

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

    public static void main(String[] args) {
        new A().run();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class A {
	
	static StringTokenizer st;
	static BufferedReader in;
	static PrintWriter pw;
	
	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//		long a = 2;
//		int q = nextInt();
//		long sum = a;
//		int s = q;
//		for (int i = 2; i <= s; i++) {
//			a = a*2+2;
//			sum += a;
//		}
//		System.out.println(sum);
//		System.out.println((4*((long)Math.pow(2, s)-1)-2*s));
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		long t = (long)(n-m) * k;
		int mod = (int) (1e9+9);
		long ans = 0;
		int x = m / (k-1);
		if (m % (k-1) != 0)
			x++;
		if (n-m < x-1) {
			int s = (int) (n - t);
			int cnt = s / k;
			ans = BigInteger.valueOf(2).modPow(BigInteger.valueOf(cnt+1), BigInteger.valueOf(mod)).longValue();
			ans = (ans-2+mod) % mod;
//			ans = ans * 4 % mod;
//			ans = (ans-2*cnt+2*mod) % mod;
			ans = ans * k % mod;
			ans = (ans+(long)(k-1) * (n-m) % mod) % mod;
			ans = (ans+s % k) % mod;
		}
		else
			ans = m;
		System.out.println(ans);
		pw.close();
	}
	private static int nextInt() throws IOException{
		return Integer.parseInt(next());
	}
	
	private static long nextLong() throws IOException{
		return Long.parseLong(next());
	}
	
	private static double nextDouble() throws IOException{
		return Double.parseDouble(next());
	}
	
	private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.math.BigInteger;
import java.util.*;

public class A {
	private static Scanner in;
	
	final int M = 1000000009;

	public void run() {
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int z = n - m;
		if (z >= n / k) {
			System.out.println(m);
			return;
		}
		int f = n - k * z;
		int last = f % k + (k - 1) * z;
		f /= k;
		int ans = BigInteger.ONE.shiftLeft(f + 1).remainder(BigInteger.valueOf(M)).intValue();
		System.out.println(((ans + M - 2L) * k + last) % M);
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		in = new Scanner(System.in);
		new A().run();
		in.close();
	}
}
// Problem: 992_C. Nastya and a Wardrobe
// Time complexity: logn
import java.util.Scanner;

public class R489C {
	static long MOD=(long)1e9+7;
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		long n=scan.nextLong(), k=scan.nextLong();
		if(n==0) {
			System.out.println(0);
			return;
		}
		long x=2*n-1;
		long e=exp(2,k);
		System.out.println((x%MOD*e%MOD+1)%MOD);
	}
	public static long exp(long x, long e) {
		long res=1;     

		while (e>0)	{
			if(e%2==1) res=(res*x)%MOD;
			
			e/=2;
			x=(x*x)%MOD;
		}
		return res;
	}
}
// Problem: 992_C. Nastya and a Wardrobe
// Time complexity: logn
import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * Created by aditya on 5/3/17.
 */
public class Main3 {

    static long x, k;
    static long MOD = (long)1e9 + 7;

    public static void main(String args[]) throws Exception{
        FastInput fi = new FastInput(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        x = fi.nextLong();
        k = fi.nextLong();

        if(x == 0) {
            System.out.println(0);
            return;
        }

//        System.out.println(pow(2, k+1));
        long q1 = (pow(2, k+1) * (x%MOD)) % MOD;
        long q2 = pow(2, k);
        long q3 = 1;
//        System.out.println(q1);
//        System.out.println(q2);
//        System.out.println(q3);


        long exp = (q1-q2 + MOD + MOD)%MOD;
        exp = (exp + q3)%MOD;

//        exp = (exp*2)%MOD;

        pw.println(exp);

        pw.close();
    }

    static long pow(long n, long k) {
        if(k == 0)
            return 1;
        if(k == 1)
            return n;
        long ret = pow(n, k/2)%MOD;
        ret = (ret*ret)%MOD;
        if(k%2 == 1)
            ret = (ret*n)%MOD;

        return ret;
    }

    static class FastInput {

        private Reader in;
        private BufferedReader br;
        private StringTokenizer st;

        public FastInput(Reader in) {
            this.in=in;
            br = new BufferedReader(in);
        }

        public String nextString() {

            while(st==null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    System.out.println(e.getStackTrace());
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public double nextDouble() {

            return Double.parseDouble(nextString());
        }

    }

}
// Problem: 992_C. Nastya and a Wardrobe
// Time complexity: logn
import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class C {

    public static void main(String[] args) throws IOException {
        init(System.in);
        BigInteger x = new BigInteger(next());
        if (x.compareTo(BigInteger.ZERO) == 0) {
            System.out.println(0);
            return;
        }
        BigInteger k = new BigInteger(next());
        BigInteger mod = new BigInteger("1000000007");
        BigInteger two = BigInteger.ONE.add(BigInteger.ONE);
        BigInteger ans = two.modPow(k, mod);
        ans = ans.multiply(two.multiply(x).subtract(BigInteger.ONE)).add(BigInteger.ONE).mod(mod);
        System.out.println(ans);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

//    private static int nextInt() throws IOException {
//        return Integer.parseInt(next());
//    }

//    private static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    private static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    private static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}
// Problem: 992_C. Nastya and a Wardrobe
// Time complexity: logn
import java.io.*;
import java.math.BigInteger;
import java.util.Locale;
import java.util.StringTokenizer;

public class C {
    String fileName = "<name>";

    public static final int MOD = (int) (1e9 + 7);

    public void solve() throws IOException {
        long x = nextLong();
        if (x == 0) {
            out.print(0);
            return;
        }
        long k = nextLong();
        BigInteger power = BigInteger.valueOf(2)
                .modPow(BigInteger.valueOf(k), BigInteger.valueOf(MOD));
        BigInteger r = BigInteger.valueOf(x).multiply(power);
        BigInteger l = r.subtract(power).add(BigInteger.ONE);
        out.print(l.add(r).mod(BigInteger.valueOf(MOD)));
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new C().run();
    }
}