codeparrot/codecomplex huggingface dataset:
// Problem: 817_C. Really Big Numbers
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long s = in.nextLong();

            if (n - digitSum(n) < s) {
                out.println(0);
                return;
            }

            long left = 0;
            long right = n;
            while (left < right) {
                long mid = left + (right - left) / 2;
                if (mid - digitSum(mid) >= s) { // if condition(mid) == true
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            out.println(n - left + 1);
        }

        long digitSum(long a) {
            long result = 0;
            while (a > 0) {
                result += a % 10;
                a /= 10;
            }
            return result;
        }

    }

    static class InputReader {
        private static BufferedReader in;
        private static StringTokenizer tok;

        public InputReader(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
        }

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

        public String next() {
            try {
                while (tok == null || !tok.hasMoreTokens()) {
                    tok = new StringTokenizer(in.readLine());
                    //tok = new StringTokenizer(in.readLine(), ", \t\n\r\f"); //adds commas as delimeter
                }
            } catch (IOException ex) {
                System.err.println("An IOException was caught :" + ex.getMessage());
            }
            return tok.nextToken();
        }

    }
}
// Problem: 817_C. Really Big Numbers
// Time complexity: logn
import java.io.*;

import java.util.*;

public class Solution {

    public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);

       long n =   scanner.nextLong();
       long s =   scanner.nextLong();
       long myLong = s;
       long count =0;
      while(true){
    	  if(myLong>n){
    		  break;
    	  }
    	  char[] num = (""+myLong).toCharArray();
		int sum = 0;
			for (int j = 0; j < num.length; j++)
				sum += num[j] - '0';
    	
    	  if(myLong- sum>=s){
    		  //count++;
    		  break;
    	  }
    	  
    	  myLong++;
      }
      System.out.println(Math.max(n-myLong+1,0));
        scanner.close();
    }
}
// Problem: 817_C. Really Big Numbers
// Time complexity: logn
import java.util.Scanner;

public class ReallyBigNumbers {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong(); // max
		long s = sc.nextLong(); // differential
		long bigNums = 0;
		long inARow = 0;
		for (long i = s; i <= n; i++) {
			if (inARow == 9) {
				bigNums += (n - i+1);
				break;
			} else {
				if (i >= s + digitSum(i)) {
					bigNums++;
					inARow++;
				} else {
					inARow = 0;
				}
			}
		}
		System.out.println(bigNums);
	}

	public static long digitSum(long a) {
		long sum = a % 10;
		if (9 < a) {
			a /= 10;
			sum += digitSum(a);
		}
		return sum;
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.util.Scanner;

public class Main {
    
    final static long Mod = 1000000009;
    static long n, m, k, t, l, u, ans;
    static Scanner cin = new Scanner(System.in); 
    
    static long multi_mod(long base, long cur) {
        long res = 1;
        while(cur > 0) {
            if(cur % 2 == 1) res = (res * base) % Mod;
            cur >>= 1;
            base = (base * base) % Mod;
        }
        return res;
    }
    
    public static void main(String[] args) {
        n = cin.nextLong(); m = cin.nextLong(); k = cin.nextLong();
        l = (k - 1)*(n / k) + n % k;
        if(m <= l) {
            System.out.println(m);
        }
        else {
            t = n / k;
            u = m - l;
            ans = (0 + (t - u) * (k - 1) + n % k) % Mod;
            ans = (ans + ((k)*((multi_mod(2, u + 1) - 2 + Mod) % Mod)) % Mod) % Mod;
            System.out.println(ans);
        }
    }
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.math.BigInteger;
import java.util.Scanner;


public class C {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long s=0,mod=1000000009;
		int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt(),c=n/k;
		if(m<=c*(k-1)+(n%k))System.out.println(m);
		else {
			int a=m-c*(k-1)-(n%k);
			long l=0,pase=0;
			//System.out.println(a);
			long pot=BigInteger.valueOf(2).modPow(BigInteger.valueOf(a), BigInteger.valueOf(mod)).longValue();
			pot=(2*(pot-1))%mod;
			/*System.out.println(pot);
			System.out.println(k);*/
			System.out.println(((pot*k)%mod+(m-a*k))%mod);
		}
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		new TaskC().solve(in, out);
		out.close();
	}
}

class TaskC {
	
	static final long mod=1000000009;
	
	public void solve(InputReader in,PrintWriter out) {
		int n=in.nextInt();
		int m=in.nextInt();
		int k=in.nextInt();
		
		int l=0,r=m/k;
		while(l<r) {
			int mid=(l+r)>>>1;
			if(good(n,m,k,mid)){
				r=mid;
			}
			else{
				l=mid+1;
			}
		}
		Mat u=new Mat();
		u.set(k,1,0,0);
		Mat v=new Mat();
		v.set(2,0,k,1);
		u=u.mul(v.powMat(l));
		out.println((u.e[0][0]-k+(m-l*k)+mod)%mod);
	}

	private boolean good(int n, int m, int k, int mid) {
		n-=mid*k;
		m-=mid*k;
		int ans=n/k*(k-1)+n%k;
		if(ans>=m)
			return true;
		return false;
	}
	
	private static class Mat {
		long[][] e=new long[2][2];
		
		Mat mul(Mat u) {
			Mat s=new Mat();
			s.set(0,0,0,0);
			for(int i=0;i<2;i++) {
				for(int j=0;j<2;j++) {
					for(int k=0;k<2;k++){
						s.e[i][j]=(s.e[i][j]+e[i][k]*u.e[k][j])%mod;
					}
				}
			}
			return s;
		}
		
		Mat powMat(int k) {
			Mat u=this;
			Mat s=new Mat();
			s.set(1,0,0,1);
			while(k!=0) {
				if(k%2==1) {
					s=s.mul(u);
				}
				u=u.mul(u);
				k/=2;
			}
			return s;
		}

		void set(long i, long j, long k, long l) {
			e[0][0]=i;
			e[0][1]=j;
			e[1][0]=k;
			e[1][1]=l;
		}
	}
	
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        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());
    }

}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class CFFF {
	static PrintWriter out;
	static final int oo = 987654321;
	static final long mod = (long)(1e9)+9;
	public static void main(String[] args) {
		MScanner sc = new MScanner();
		out = new PrintWriter(System.out);

		long N = sc.nextLong();
		long M = sc.nextLong();
		long K = sc.nextLong();
		
		if(M<=N-N/K)
			out.println(M);
		else{
			long ans = (fastModExpo(2,M-(N-N%K)/K*(K-1)-N%K+1,mod)-2)*K+M-(M-(N-N%K)/K*(K-1)-N%K)*K;
			out.println((mod+ans)%mod);
		}		
		out.close();
	}
	static long fastModExpo(int base, long pow, long mod) {
		if (pow == 0) 
			return 1L;
		if ((pow & 1) == 1)
			return (base*fastModExpo(base, pow - 1,mod))%mod;
		long temp = fastModExpo(base, pow / 2, mod);
		return (temp*temp)%mod;
	}

	static class MScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner() {
			stream = System.in;
			// stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		int[] nextInt(int N) {
			int[] ret = new int[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt();
			return ret;
		}

		int[][] nextInt(int N, int M) {
			int[][] ret = new int[N][M];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt(M);
			return ret;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLong(int N) {
			long[] ret = new long[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLong();
			return ret;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDouble(int N) {
			double[] ret = new double[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextDouble();
			return ret;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] next(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = next();
			return ret;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		String[] nextLine(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLine();
			return ret;
		}

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

/**
 * @author pvasilyev
 * @since 8/16/13
 */
public class ProblemC {

    public static final String FILE_IN = "std.in";
    public static final String FILE_OUT = "std.out";
    private static boolean debugMode = true;
    private static final long MOD = 1000 * 1000 * 1000 + 9;

    public static void main(String[] args) throws IOException {

        final Scanner reader = new Scanner(new InputStreamReader(debugMode ? System.in : new FileInputStream(FILE_IN)));
        final PrintWriter writer = new PrintWriter(debugMode ? System.out : new FileOutputStream(FILE_OUT));

//        final long start = System.currentTimeMillis();
        solveTheProblem(reader, writer);
//        System.out.println(System.currentTimeMillis() - start);

        reader.close();
        writer.close();
    }

    private static void solveTheProblem(final Scanner reader, final PrintWriter writer) {

        final long n = reader.nextLong();
        final long m = reader.nextLong();
        final long k = reader.nextLong();

        if (n - n/k >= m) {
            writer.println(m);
            return;
        } else {
            long sum = 1;
            long maxK = m - n + n/k;
            sum = fastPow(2, maxK);
            sum = 2 * (sum - 1);
            sum = sum % MOD;
            sum *= k;
            sum += m - maxK * k;
            writer.println(sum % MOD);
        }

    }

    private static long fastPow(final int exp, final long deg) {
        if (deg == 0) {
            return 1;
        } else if (deg == 1) {
            return exp;
        } else if (deg % 2 == 0) {
            long temp = fastPow(exp, deg / 2);
            temp = (temp * temp) % MOD;
            return temp;
        } else {
            long temp = fastPow(exp, deg / 2);
            temp = (temp * temp) % MOD;
            return (temp * exp) % MOD;
        }
    }


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

public class Quiz {
    public static int mod = 1000000009;
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        long n = Long.parseLong(st.nextToken());
        long m = Long.parseLong(st.nextToken());
        long k = Long.parseLong(st.nextToken());
        long d = n-m;
        n -= d*k;
        if (n <= 0)
        {
            System.out.println(m);
            return;
        }
        long sum = (n%k) + d*(k-1);
        sum += 2*k*(pow(2,n/k)-1);
        sum %= mod;
        System.out.println(sum);
    }
    
    public static long pow(long a, long n)
    {
        if (n == 0)
            return 1;
        long pow = pow(a,n/2);
        pow = pow*pow % mod;
        if (n % 2 == 1)
            pow = pow*a % mod;
        return pow;
    }
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class A {	
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;
    
    long MOD = 1000000009;
    public long mod_add(long n1, long n2){
    	return (n1 + n2) % MOD;
    }    
    public long mod_time(long n1, long n2){
    	return (n1 * n2) % MOD;
    }
    public long mod_power(long a, int k) {
        if (k == 0) return 1;
        if (k % 2 == 0) return mod_power(a * a % MOD, k / 2);
        return a * mod_power(a, k - 1) % MOD;
	}
    
	public void solve() throws IOException {				
		int N = nextInt();
		int M = N - nextInt(); //wrong
		int K = nextInt();
		
		int full = N/K - M;	
		if( full < 0){
			out.println( N - M );return;
		}
		long ans = mod_time( K * 2, mod_power(2, full) - 1 );
//		out.println( full + ", " + ans );
		
		ans = mod_add(ans, N-M-full*K );
		
		out.println( ans );
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new A().run();
	}
	
	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

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

}
// Problem: 338_A. Quiz
// Time complexity: logn


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A {
	public static void main(String[] args) throws Exception {
		int n=nextInt();
		int m=nextInt();
		int k=nextInt();
		int wa=n-m;
		if(n/k<=wa){
			System.out.println(m);
		}else{
			int notFull=wa;
			int full=n/k-wa;
			long res=1;
			int power=full+1;
			int mod=1000000009;
			long powTwo=2;
			while(power>0){
				if((power&1)==1){
					res=(res*powTwo)%mod;
				}
				power>>=1;
				powTwo=(powTwo*powTwo)%mod;
			}
			res=(((res-2+mod)%mod)*k)%mod;
			res=((res+notFull*(k-1))%mod+n%k)%mod;
			System.out.println(res);
		}
	}
	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static StringTokenizer tokenizer = new StringTokenizer("");

	static int nextInt() throws Exception {
		return Integer.parseInt(next());
	}

	static double nextDouble() throws Exception {
		return Double.parseDouble(next());
	}

	static String next() throws Exception {
		while (true) {
			if (tokenizer.hasMoreTokens()) {
				return tokenizer.nextToken();
			}
			String s = br.readLine();
			if (s == null) {
				return null;
			}
			tokenizer = new StringTokenizer(s);
		}
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.util.*;
import java.io.*;
public class Quiz
{
	public static final int MOD = 1000000009;
	
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		
		long n = in.nextInt();
		long m = in.nextInt();
		long k = in.nextInt();
		
		long low = Math.min(n - (k * (n - m)), m);
		
		if(low < 0)
		{
			low = 0;
		}
		
		long result = 0;
		if(low >= k)
		{
			long b = low / k;
			
			result += fastExp(2, b + 1);
			result -= 2;
			if(result < 0)
			{
				result += MOD;
			}
			
			result *= k;
			result %= MOD;
		}
		
		result += low % k;
		result %= MOD;
		
		result += m - low;
		result %= MOD;
		
//		System.out.println(low);
		
		System.out.println(result);
	}
	
	public static long fastExp(int x, long pow)
	{
		if(pow == 0)
		{
			return 1;
		}
		
		long result = fastExp(x, pow / 2);
		result *= result;
		result %= MOD;
		
		if(pow % 2 == 1)
		{
			result *= x;
			result %= MOD;
		}
		
		return result;
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.awt.Point;

public class CodeForces {
    static boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private final long MOD = 1000000009;

    long power(long a, long b)
    {
        long res = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                res *= a;
                if (res >= MOD)
                    res %= MOD;
            }
            a *= a;
            if (a >= MOD)
                a %= MOD;
            b >>= 1;
        }
        return res;
    }

    void runCase(int caseNum) throws IOException {
        long n = nextLong();
        long m = nextLong();
        long k = nextLong();

        if (n - m >= n / k) {
            System.out.println(m);
            return;
        }
        long res = 0;
        long rem = (k - 1) * (n - m);
        m -= rem;
        long bound = m / k;
        res = (power(2, bound + 1) + MOD - 2) % MOD;
        res *= k;
        res %= MOD;
//        for (long i = 0; i < bound; ++i) {
//            res += k;
//            res <<= 1;
//            if (res >= MOD)
//                res %= MOD;
//        }
        res += rem;
        res += m % k;
        res %= MOD;
        System.out.println(res);
    }


    public static void main(String[] args) throws IOException {
        if (ONLINE_JUDGE){
            System.out.println();
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(System.out);
            //out = new PrintWriter("output.txt");
        }
        new CodeForces().runIt();
        out.flush();
        out.close();
        return;
    }

    static BufferedReader in;
    private StringTokenizer st;
    static PrintWriter out;

    static int pos;
    static String curInput = "";

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

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

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

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


    void runIt() throws IOException {
        st = new StringTokenizer("");

//        int N = nextInt();
//        for (int i = 0; i < N; i++) {
//            runCase(i + 1);
//        }
        runCase(0);
        out.flush();
    }

}
// Problem: 338_A. Quiz
// Time complexity: logn
//package cf196;

import java.util.*;
import java.io.*;

public class A {
	FastScanner in;
	PrintWriter out;
	final long mod = (long) 1e9 + 9 ; 
	public void solve() throws IOException {
		long n = in.nextInt();
		long m = in.nextInt();
		long k = in.nextInt();
		long l = n / k;
		long c = n - m;
		long mul2 = Math.max(0, l - c);
		if (mul2 == 0) {
			out.println(m);
			return;
		}
		long ans = power(2, mul2 + 1, mod);
		ans = (ans + mod - 2) % mod;
		ans = (ans * k) % mod;
		long z = mul2 * k;
		long r = m - z;
		ans = (ans + r) % mod;
		out.print(ans);
	}
	public long power(long x, long pow, long mod) {
		if (pow == 0) {
			return 1;
		}
		if ((pow % 2) == 0) {
			return power(((x * x) % mod), pow / 2, mod);
		} else {
			return (power(x, pow - 1, mod) * x) % mod;
		}
	}
	public void run() {
		try {
			in = new FastScanner(System.in);
			out = new PrintWriter(System.out);

			solve();

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

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}
	}

	public static void main(String[] arg) {
		new A().run();
	}
}
// Problem: 338_A. Quiz
// Time complexity: logn
// practice with rainboy
import java.io.*;
import java.util.*;

public class CF338A extends PrintWriter {
	CF338A() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF338A o = new CF338A(); o.main(); o.flush();
	}

	static final int MD = 1000000009;
	long power(int a, int k) {
		if (k == 0)
			return 1;
		long p = power(a, k / 2);
		p = p * p % MD;
		if (k % 2 == 1)
			p = p * a % MD;
		return p;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int z = n - m;
		if (z >= (n + k - 1) / k) {
			println(m);
			return;
		}
		int d = (n - z * k) / k;
		println(((power(2, d + 1) - 2 + MD) * k + m - d * k) % MD);
	}
}