from sys import stdin
n, m, k = map(int, stdin.readline().split(' '))
doublesNeeded = int(m - (n - n / k))
score = 0
if doublesNeeded > 0:
    score = 1
    score <<= (doublesNeeded + 1)
    score *= k
    score -= 2 * k
if m > 0 and doublesNeeded >= 0:
    score += m - doublesNeeded * k
elif doublesNeeded < 0:
    score = m
score %= 1000000009
print(score)

 #COPIED

MOD = 1000000009

n,m,k = [int(x) for x in input().split()]

num0 = n-m
num1fin = num0*(k-1)
if num1fin >= m:
    print(m)
else:
    num1open = m-num1fin
    sets = num1open//k
    rem = num1open%k
    print(((pow(2,sets,MOD)-1)*2*k+rem+num1fin)%MOD)

mod = 1000000009

def mpow(x, y):
	if y == 0:
		return 1
	ans = mpow(x, y/2)
	ans = (ans * ans) % mod
	if y%2 > 0:
		ans = (ans * x) % mod
	return ans

n, m, k = map(int, raw_input().split())
fr = n % k + (n/k)*(k - 1)
if fr >= m:
	ans = m
else:
	a = m - fr
	fr -= a*(k-1)
	ans = mpow(2, a)
	ans = (ans + mod - 1) % mod
	ans = (ans * 2) % mod
	ans = (ans * k) % mod
	ans = (ans + fr) % mod
print ans

MOD = 1000000009

def log_mult(a, p):
  if p == 0:
    return 1
  else:
    z = log_mult(a, p//2)
    z = (z*z) % MOD
    if (p % 2) == 1:
      return (a*z) % MOD
    else:
      return z

def log_iterative(a, p):
  res = 1
  while p > 0:
    if p % 2 == 1:
      res = (res*a) % MOD
    a = (a*a) % MOD
    p //= 2
  return res

n, m, k = list(map(int, input().split()))
c = (n//k) * (k-1) + n % k
if c >= m:
  print(m)
else:
  d = m - c
  res = log_iterative(2, d+1) - 2
  res = (res * k) % MOD
  print((res + m-d*k) % MOD)

# Filename : Quiz.py
# arr = raw_input().split();
# t = [raw_input().split() for i in range(0,n,1)]

Mod = 1000000009
def mPow(x, y):
    if y == 0:
        return 1
    ans = mPow(x, y/2)
    ans = (ans * ans) % Mod
    if y%2 > 0:
        ans = (ans * x) % Mod
    return ans

n, m, k = map(int, raw_input().split())
fr = n % k + (n/k)*(k-1)
if fr >= m:
        ans = m
else:
        a = m - fr
        fr -= a*(k-1)
        ans = mPow(2,a)
        ans = (ans + Mod - 1) % Mod
        ans = (ans * 2) % Mod
        ans = (ans * k) % Mod
        ans = (ans + fr) % Mod
print ans

import sys

n, m, k = [int(x) for x in raw_input().strip().split()]

zeroes = n-m
if zeroes >= n/k:
    print m
    sys.exit()
fullsets = n/k - zeroes
remaining = n - k*fullsets - zeroes

bignum = 1000000009

score = (k * (pow(2, fullsets+1, bignum) - 2)) % bignum

score += remaining
score %= bignum

print score

I=lambda:map(int, raw_input().split())
bignum = 10**9+9

n, m, k = I()
zeroes = n-m
if zeroes >= n/k:
    print m
    exit()

fullsets = n/k - zeroes
remaining = n - k*fullsets - zeroes

score = (k * (pow(2, fullsets+1, bignum) - 2)) % bignum

score += remaining
score %= bignum

print score

n, m, k = map(int, raw_input().split(" "))
if m % (k - 1) == 0:
	diff = (m / (k - 1) * k - 1) - n
#	print "initial diff", diff
	if diff <= 0:
		print m
	else:
		doubles = diff / k * (k - 1)
		doubles += diff % k
		ones = m - doubles * k
#		print "doubles", doubles
#		print "ones", ones
		print ((pow(2, doubles, 1000000009) - 1) * 2 * k + ones) % 1000000009

else:
	diff = (m / (k - 1) * k + m % (k - 1)) - n
#	print "initial diff", diff
	if diff <= 0:
		print m
	else:
		if m % (k - 1) + 1 == diff:
			doubles = m % (k - 1)
			ones = m - doubles * k
#			print "doubles", doubles
#			print "ones", ones
			print ((pow(2, doubles, 1000000009) - 1) * 2 * k + ones) % 1000000009
		elif m % (k - 1) + 1 > diff:
			doubles = diff
			ones = m - doubles * k
#			print "doubles", doubles
#			print "ones", ones
			print ((pow(2, doubles, 1000000009) - 1) * 2 * k + ones) % 1000000009
		else:
			diff -= (m % (k - 1) + 1)
			doubles = m % (k - 1)
			doubles += diff / k * (k - 1)
			doubles += diff % k
			ones = m - doubles * k
#			print "doubles", doubles
#			print "ones", ones
			print ((pow(2, doubles, 1000000009) - 1) * 2 * k + ones) % 1000000009

n, m, k = map(int, raw_input().split())

wrongNum = n - m
intervalNum = n / k

M = (10 ** 9 + 9)
if wrongNum >= intervalNum :
    score = m
else :
    prefixSum = 2*k * (pow(2, intervalNum - wrongNum, M) - 1)
    suffixSum = (m - ((intervalNum-wrongNum) * k))
    score = (prefixSum + suffixSum) % M

print score

#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+9
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
# vsInput()

def bigmod(a,b,c):
    if(b==0): return 1
    if(b%2==0):
        x=bigmod(a,b/2,c)
        return (x*x)%c
    else:
        return (a%c * bigmod(a,b-1,c))%c

n,m,k=value()

sections=n//(k)
minScore=n%(k)+sections*(k-1)

covered=max(m-minScore,0)
# print(covered)

score=(bigmod(2,covered,M)-1+M)%M
score=(score* (2*k)%M)%M
# print(score)

score=(score+(m-covered*k))%M

print(score)

# BruteForce
# ans=0
# for i in range(covered):
#     ans=(ans+k)%M
#     ans=(ans*2)%M
# print(ans)

import os
import sys
from io import BytesIO, IOBase
import math

def main():
    pass

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

import os
import sys
from io import BytesIO, IOBase

def main():
    pass

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

n,m,k=map(int,input().split())
p=n//k
mws=(k-1)*p+n%k
mod=1000000009
#print(mws)
if(m<=mws):
    print(m)
else:
    con=m-mws
    #print(con,mws)
    acon=(k*(pow(2,con+1,mod)-2))%mod
    m-=(k*con)
    ans=(acon+m)%mod
    print(ans)

'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:05/05/2020

'''
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def powmod(y,m):
    res=1
    x=2
    while(y>0):
        if(y&1):
            res=(res*x)%m
        y>>=1
        x=(x*x)%m
    return res
def solve():

    mod=1000000009
    n,m,k=mi()
    x=n//k*(k-1)
    n-=(n//k)*k
    x+=n
    if(m<=x):
        print(m)
    else:

        x1=(m-x)
        #print(x1)
        ans=0
        x3=powmod(x1+1,mod)
        x3=(x3-2+mod)%mod
        # print(x3)
        ans=(x3*k)%mod
        ans+=(m-x1*k)
        ans%=mod
        print(int(ans))

if __name__== "__main__":
    solve()

n,m,k=map(int,input().split())
mod=10**9+9
x=n-m
if x>=n//k:
    print(m)
else:
    y=n-k*x
    a=y//k
    b=y%k
    c=pow(2,a,mod)
    if c==0:
        c=mod-1
    else:
        c-=1
    ans=((2*k)%mod)*c
    ans%=mod
    ans+=x*(k-1)+b
    ans%=mod
    print(ans)

from collections import defaultdict
mod = int(1000000009)
def is_good(n, a, b):
	while n:
		digit = n%10
		if digit != a and digit != b:
			return False
		n = n//10

	return True

if __name__ == '__main__':
	n, m, k = map(int, input().split())
	m -= n%k
	score = n%k
	n -= n%k

	sets = n//k

	used = sets*(k-1)

	if used >= m:
		print(m+score)
		exit()

	else:
		filled = m - used
		# print(score, filled)
		score += (2*k*(((2**filled)%mod)-1)%mod)
		# print(score, sets)
		score += ((int(sets - filled)*(k-1))%mod)

	print(score%mod)

R = lambda: map(int, input().split())
n, m, k = R()
rem = n % k
zeros = n // k
if n - zeros >= m:
    print(m)
else:
    fulls = max(0, m - zeros * (k - 1) - n % k)
    zeros -= fulls
    acc = ((1<<fulls) - 1) % (10**9 + 9) * k * 2
    print((acc + zeros * (k - 1) + rem) % (10**9 + 9) if m else 0)

MOD = int(1e9+9)

def fast_power(x, y):
    res = 1
    while y > 0:
        if y % 2 == 1:
            res = res * x%MOD
        x = x * x % MOD
        y //= 2
    return res

n, m, k = map(int, input().split())
x = max(0, m - n // k * (k - 1) - n % k)
z = (m - x * k) % MOD
res = fast_power(2, x+1)
res = (res - 2) % MOD * k % MOD
res = (res + z) % MOD
print(res)

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

def main():
    n, m, k = [ int(x) for x in input().split() ]
    mod = 1000000009

    availablePositions = (k - 1) * (n // k) + n % k

    if availablePositions >= m:
        points = m
    else:
        positionsLeft = m - availablePositions

        points = (
            ((pow(2, positionsLeft + 1, mod) - 2) * k) % mod
            + (m - k * positionsLeft) % mod
        ) % mod

    print(points)

BUFFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

input = lambda: sys.stdin.readline().rstrip("\r\n")

def print(*args, **kwargs):
    sep = kwargs.pop("sep", " ")
    file = kwargs.pop("file", sys.stdout)

    atStart = True
    for x in args:
        if not atStart:
            file.write(sep)
        file.write(str(x))
        atStart = False
    file.write(kwargs.pop("end", "\n"))

    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

main()

MOD = 10**9 + 9

n,m,k = map(int,input().split())

x = (n//k) + m -n

if (n - n//k) < m:
    x = n//k +m -n
    ans = pow(2,x+1,MOD)-2
    ans = ans*k+m-x*k
    print(ans%MOD)

else :
    print(m)

#!/usr/bin/python3

def modulo_power(modulo, power, base):
    if power == 0:
        return 1
    if power == 1:
        return base

    remainder = power % 2
    power -= remainder

    half = modulo_power(modulo, power/2, base)

    return (half * half * modulo_power(modulo, remainder, base)) % modulo

data = [int(token) for token in input().split()]
num_questions, num_correct, doubler = data

num_wrong = num_questions - num_correct
tail = num_wrong * (doubler - 1)
head = num_correct - tail

if head < 0:
    print(num_correct)
    exit()

num_doublings = head // doubler
remainder = head - num_doublings * doubler
modulo = 10**9 + 9
result = ((2 * doubler * (modulo_power(modulo, num_doublings, 2) - 1)) +
            remainder + tail) % modulo

print(result)

import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def add(a,b):
	return (a+b)%1000000009

def sub(a,b):
	return (a-(b%1000000009)+1000000009)%1000000009

def mul(a,b):
	return (a*b)%1000000009

def qpow(a,n):
	k = a
	r = 1
	for i in range(32):
		if n & (1<<i):
			r = mul(r,k)
		k = mul(k,k)
	return r

n, m, k = mints()
c = (n+1)//k
z = c*(k-1)
if n-c*k >= 0:
	z += n-c*k
d = 0
if z < m:
	d = m-z
else:
	print(m)
	exit(0)
s = mul(k,mul(2, sub(qpow(2, d), 1)))
#print(c,d,z,s)
s = sub(add(s, z),mul(d,(k-1)))
print(s)

n, corecte, k = map(int, input().split())
incorecte = n - corecte
mod = 10**9 + 9

corecte_consecutive = max(0, n - incorecte * k)
dublari = corecte_consecutive // k
corecte_ramase = corecte - corecte_consecutive

def power(b, exp):
    if exp == 0: return 1

    half = power(b, exp//2)
    if exp%2 == 0: return (half*half) % mod
    return (half*half*b) % mod

score = (power(2, dublari+1) - 2) * k + corecte_ramase + corecte_consecutive % k

print(score % mod)

MOD  =1000000009
n,m,k=map(int,input().split())
x=max(0,m-(n-n%k)//k*(k-1)-n%k)
res=((((pow(2,x+1,MOD))-2)%MOD)*k)%MOD
z=(m-x*k)%MOD
res=(res+z)%MOD
print (res)

n,m,k=map(int,input().split())
if n-n//k>=m:exit(print(m))
mod=int(1e9+9)
x=n//k+m-n
r=pow(2,x+1,mod)-2
a=r*k+m-x*k
print((a%mod+mod)%mod)

# -*- coding: cp1251 -*-
import sys
import itertools
MODULO = 10**9 + 9
def pow(n,k):
    if k==0:
        return 1
    if k==1:
        return n
    pp = pow(n,k/2)
    if k%2 == 0:
        return (pp * pp) % MODULO
    else:
        return (pp * pp * n) % MODULO

def calc(cnt, k, lll):
    ydv = cnt/k
    ostat = cnt - ydv * k
    #ydv
    #1 - 2*k, 2 - 6*k, 3 - 14*k, 30*k
    if False:
        b1 = k<<1
    else:
        b1 = k*2

    if False:
        ppc = s = "0b1" + ''.join(['0']*(ydv))
        ppc = eval(ppc)
        res = b1*ppc - b1
    else:
        if True:
            if True:
                res = b1 * (pow(2, ydv) - 1)
            else:
                res = (b1 * (1<<(ydv)) - b1) %(10**9+9)
        else:
            res = (b1 * (2**ydv) - b1) %(10**9+9)

    return res + ostat + lll
'''
def calc___________(cnt, k):
    res = 0
    acc = 0
    for i in xrange(cnt):
        res += 1
        acc += 1
        if acc == k:
            acc = 0
            res *= 2

    return res
'''
def solve(n, m, k):
    ans_plus = m
    ans_minus = n-m
    #fails_cnt = n/k
    if ans_minus * k + k - 1 >= n:
    #if fails_cnt <= ans_minus:
        #print "!"
        return m
    else:
        #++++++++++++ ____ .+++.+++.+++|
        ans_plus -= ans_minus * (k - 1)
        return calc(ans_plus, k, m - ans_plus)

n, m, k = map(int, sys.stdin.readline().split())

print str(solve(n, m, k) % (MODULO))

d = 1000000009
n, m, k = map(int, input().split())
if (n - m) * k > n:
    print(m)
else:
    t = n // k - n + m + 1
    print(((pow(2, t, d) - 1 - t) * k + m) % d)

import math
def get_res(n, m, k):
    D = 1000000009
    if m <= (n-m)*(k-1):
        return m%D
    p = max(0, m-(n-m)*(k-1))
    result = (2*k*(pow(2,p/k, D)-1) + p%k + (n-m)*(k-1)) % D
    return result

#N = int(raw_input())
n, m, k= [int(s) for s in raw_input().split(" ")]
result = get_res(n, m, k)
print "{}".format(result)

def chk(x):
    d = (m - x) // (k - 1) * k
    if (m - x) % (k - 1):
        d += 1 + (m - x) % (k - 1)
    if d <= n - x:
        return True
    else:
        return False

def calc(e):
    if e == 1:
        return 2
    if e & 1:
        d = 2
    else:
        d = 1
    f = calc(e >> 1)
    d = d * f % D * f % D
    return d

n, m, k = map(int, input().split())
D = 1000000009

l = 0
h = n

while l < h:
    mid = l + h >>1
    if chk(mid):
        h = mid
    else:
        l = mid + 1

h = calc(l // k + 1) - 2
if h < 0:
    h += D

print((k * h % D + m - l // k * k) % D)

n, m, k = map(int, input().split())

if (n - m) >= n//k:
	print (m)
else:
	longest_correct_streak = n - k*(n - m)
	p = longest_correct_streak//k
	print ((k*(pow(2, p+1, 1000000009) - 2) + (longest_correct_streak % k) + (n - m)*(k - 1)) % 1000000009)

n, m, k = map(int, raw_input().split())
a = 1000000009

udv = m - n + n / k
if udv <= 0:
    print m
else:
    x = (pow(2, udv + 1, a) - 2) * k
    print (x + m - udv * k ) % a

import sys, math
def rs():
    return sys.stdin.readline().strip()
def ri():
    return int(sys.stdin.readline().strip())
def ras():
    return list(sys.stdin.readline().strip())
def rai():
    return map(int,sys.stdin.readline().strip().split())
MAX = 1000000009
def bp(a,b):
    r = 1
    while b != 0:
        if b % 2:
            r = r*a%MAX
            b -= 1
        else:
            a = a*a%MAX
            b /= 2
    return r

def solve():
 n,m,k = rai()
 t = n - m

 if m < k:
     return m

 count = m / (k - 1)

 if count*(k-1) == m:
     count -= 1

 if count <= t:
     return m

 r = (k - 1) * t

 v = m - r

 o = v / k

 ost = v - o*k

 rr = k*(bp(2, (o + 1)) - 2) % MAX + ost

 return (r + rr) % MAX

print solve()

n , m , k = map(int, raw_input().split())
M = 10**9 + 9
x = max(0, m - n + n / k)
print (m - k * x + k * (pow(2, x + 1, M) - 2) + M) % M

'''
Created on 16.08.2013

@author: Sergei Zalivako
'''

def powmod(b,e,n):
    """powmod(b,e,n) computes the eth power of b mod n.
    (Actually, this is not needed, as pow(b,e,n) does the same thing for positive integers.
    This will be useful in future for non-integers or inverses.  Currently assumes e>0.)"""
    accum = 1; i = 0; bpow2 = b
    while ((e>>i)>0):
        if((e>>i) & 1):
            accum = (accum*bpow2) % n
        bpow2 = (bpow2*bpow2) % n
        i+=1
    return accum

MOD = 1000000009

n, m, k = raw_input().split()

n = int(n)
m = int(m)
k = int(k)

doubles = n / k
wrong = n - m

if ( doubles <= wrong):
    ans = m
else:
    ost = n - k * wrong
    nth = ost / k
    plus = ost % k
    sum = (((powmod(2, nth, MOD) - 1) * 2) * k + plus) % MOD
    ans = ((k - 1) * wrong + sum) % MOD

print ans

from sys import stdin
import fractions

def line():
    return stdin.readline().split()
def read_int():
    return int(line()[0])
def read_ints():
    return [int(x) for x in line()]
def memo(fn):
    table = {}
    def memoized(*args):
        if args not in table:
            table[args] = fn(*args)
        return table[args]
    return memoized

def solve(n, m, k):
    original_n = n
    if (n - m)*k >= n:
        return m

    skips = (n - m)
    n -= skips*k
    doubles, last = n / k, n % k
    #print "D%s S%s L%s" % (doubles, skips, last)
    assert doubles*k + skips*k + last == original_n
    assert doubles*k + skips*(k-1) + last == m

    score = 2*k*(pow(2, doubles, 1000000009) + 1000000008)
    score += (k - 1) * skips
    score += last
    score = score % 1000000009

    assert score >= 0
    return score

n, m, k = read_ints()
print solve(n, m, k)

n,m,k = map(int, raw_input().split())
mod = 10**9+9
x = max(0, n/k-n+m)
p = pow(2,x+1,mod)-2
print (p*k+m-x*k)%mod

n,m,k=map(int,raw_input().split())
M=10**9+9
x=max(n/k-n+m,0)
a=k*2*(pow(2,x,M) - 1)
print (a+m-k*x+M)%M

import math
import sys

def exp_by_squaring(x, n):
    mod = 1000000009

    if n < 0:
        x = 1 / x
        n = -n

    if n == 0:
        return 1

    y = 1
    while n > 1:
        if n % 2 == 0:
            x = x % mod * x % mod
            n = n / 2
        else:
            y = x % mod * y % mod
            x = x % mod * x % mod
            n = (n - 1) / 2

    return x % mod * y % mod

i = raw_input().split()
n, m, k = int(i[0]), int(i[1]), int(i[2])

mod = 1000000009
min_of_double = max(0, m - (n - n % k) / k * (k - 1) - n % k)

output = (exp_by_squaring(2, min_of_double + 1) - 2) * k + m - min_of_double * k
print output % mod

import sys
from collections import defaultdict, Counter
from itertools import permutations, combinations
from math import sin, cos, asin, acos, tan, atan, pi

sys.setrecursionlimit(10 ** 6)

def pyes_no(condition, yes = "YES", no = "NO", none = "-1") :
  if condition == None:
    print (none)
  elif condition :
    print (yes)
  else :
    print (no)

def plist(a, s = ' ') :
  print (s.join(map(str, a)))

def rint() :
  return int(sys.stdin.readline())

def rstr() :
  return sys.stdin.readline().strip()

def rints() :
  return map(int, sys.stdin.readline().split())

def rfield(n, m = None) :
  if m == None :
    m = n

  field = []
  for i in xrange(n) :
    chars = sys.stdin.readline().strip()
    assert(len(chars) == m)
    field.append(chars)
  return field

def pfield(field, separator = '') :
  print ('\n'.join(map(lambda x: separator.join(x), field)))

def check_field_equal(field, i, j, value) :
  if i >= 0 and i < len(field) and j >= 0 and j < len(field[i]) :
    return value == field[i][j]
  return None

def digits(x, p) :
  digits = []
  while x > 0 :
    digits.append(x % p)
    x //= p
  return digits[::-1]

def undigits(x, p) :
  value = 0
  for d in x :
    value *= p
    value += d
  return value

def modpower(a, n, mod) :
  r = a ** (n % 2)
  if n > 1 :
    r *= modpower(a, n // 2, mod) ** 2
  return r % mod

def gcd(a, b) :
  if a > b :
    a, b = b, a

  while a > 0 :
    a, b = b % a, a

  return b

def vector_distance(a, b) :
  diff = vector_diff(a, b)

  return scalar_product(diff, diff) ** 0.5

def vector_inverse(v) :
  r = [-x for x in v]

  return tuple(r)

def vector_diff(a, b) :
  return vector_sum(a, vector_inverse(b))

def vector_sum(a, b) :
  r = [c1 + c2 for c1, c2 in zip(a, b)]

  return tuple(r)

def scalar_product(a, b) :
  r = 0
  for c1, c2 in zip(a, b) :
    r += c1 * c2

  return r

def check_rectangle(points) :
  assert(len(points) == 4)

  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    sides = (
      vector_diff(A1, A2),
      vector_diff(A2, A3),
      vector_diff(A3, A4),
      vector_diff(A4, A1),
    )
    if all(scalar_product(s1, s2) == 0 for s1, s2 in zip(sides, sides[1:])) :
       return True
  return False

def check_square(points) :
  if not check_rectangle(points) :
    return False
  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    side_lengths = [
      (first[0] - next[0]) ** 2 + (first[1] - next[1]) ** 2 for first, next in zip([A1, A2, A3, A4], [A2, A3, A4, A1])
    ]
    if len(set(side_lengths)) == 1 :
      return True

  return False

def check_right(p) :
  # Check if there are same points
  for a, b in [
    (p[0], p[1]),
    (p[0], p[2]),
    (p[1], p[2]),
  ] :
    if a[0] == b[0] and a[1] == b[1] :
      return False

  a, b, c = p
  a, b, c = vector_diff(a, b), vector_diff(b, c), vector_diff(c, a)

  return scalar_product(a, b) * scalar_product(a, c) * scalar_product(b, c) == 0

def modmatrixproduct(a, b, mod) :
  n, m1 = len(a), len(a[0])
  m2, k = len(b), len(b[0])

  assert(m1 == m2)
  m = m1

  r = [[0] * k for i in range(n)]
  for i in range(n) :
    for j in range(k) :
      for l in range(m) :
        r[i][j] += a[i][l] * b[l][j]
      r[i][j] %= mod
  return r

def modmatrixpower(a, n, mod) :
  magic = 2
  for m in [2, 3, 5, 7] :
    if n % m == 0 :
      magic = m
      break

  r = None
  if n < magic :
    r = a
    n -= 1
  else :
    s = modmatrixpower(a, n // magic, mod)
    r = s
    for i in range(magic - 1) :
      r = modmatrixproduct(r, s, mod)

  for i in range(n % magic) :
    r = modmatrixproduct(r, a, mod)

  return r

n, m, k = rints()
e = n - m
x = max(n / k - e, 0)

mod = 10 ** 9 + 9
s = 0
if x > 0 :
  s += 2 * (pow(2, x, mod) - 1) * k

s += m - k * x

print s % mod

MOD = 10 ** 9 + 9
n, m, k = map(int, raw_input().split())
X = max(0, m - (n - n % k) / k * (k - 1) - n % k)
print ((pow(2, X + 1, MOD) - 2) * k + m - X * k) % MOD

from sys import stdin,stdout,setrecursionlimit,maxint,exit
#setrecursionlimit(2*10**5)
def listInput():
 return map(long,stdin.readline().split())
def printBS(li):
 for i in xrange(len(li)-1):
  stdout.write("%d "%li[i])
 stdout.write("%d\n"%li[-1])
def sin():
 return stdin.readline().rstrip()
MOD=10**9+9
n,m,k=listInput()
en=max(0, m - ((n - n% k) / k) * (k-1) - n% k)
#print en
ans=(k*(pow(2,en+1,MOD)-2)+m-en*k)%MOD
print ans

BASE = 1000000009

def mul(a, b):
    return [[sum((r*c)%BASE for r, c in zip(row, col))%BASE for col in zip(*b)] for row in a]

def power(a, n):
    if n==0: return [[1, 0], [0, 1]]
    if n==1: return a
    if n & 1: return mul(a, power(mul(a, a), n >> 1))
    return power(mul(a, a), n >> 1)

N, M, K = map(int, raw_input().split())

quo = N/K
rem = N%K
ext = 0

if M<=quo*(K-1)+rem:
    print M
else:
    ext = M-(quo*(K-1)+rem)
    v = mul(power([[2, (2*K)%BASE], [0, 1]], ext), [[0], [1]])
    print ( v[0][0]+M-(ext*K) )%BASE

n,m,k = map(int,raw_input().split())

#x + y*(k - 1) = m
#x + y*k + z = n
#m + y + z = n
y = min(n-m,m/(k-1));
x = m - y*(k - 1);
#print x,y;
num = x/k;

mod = 10**9 + 9;
ans = (pow(2,num + 1,mod) - 2)*k + x%k + (k-1)*y;
ans = (ans%mod + mod)%mod;
print ans;

BASE=1000000009
def pow(x,y):
	res=1
	while (y):
		if (y%2==1):res=res*x%BASE
		x=x*x%BASE
		y/=2
	return res%BASE
n,m,k=map(long,raw_input().split())
x=((n/k)*(k-1))+n%k;
if (x>=m):
	print m
	exit(0)
t=m-x
u=pow(2,t)
u=(2*(u-1)*k+m-t*k)%BASE
print u

n,m,k = map(int,input().split())

chunks = n//k

freespots = chunks*(k-1) + n%k

if m <= freespots:
    print(m)
else:
    doubles = m-freespots

    dchunks = doubles
    chunks -= dchunks

    total = (pow(2,dchunks,1000000009)-1)*k*2

    total += n%k + chunks*(k-1)

    print(total%1000000009)

mod = 10**9 + 9

def f(n,m,k):
	s = 0
	w = m-n+n/k
	if w > 0:
		n -= w * k
		m -= w * k
		s = 2*(pow(2,w,mod)-1)*k
	return (s + m)%mod

from sys import *

n, m, k = map(int, raw_input().strip().split())

print f(n,m,k)

n,m,k=map(int,input().split())
pri=pow(10,9)+9
x=n%k
y=n//k
if(m<=y*(k-1)+x):
    print(m)
    exit()
else:

    sert=n-m
    left=m-sert*(k-1)

    g=m-left

    sets=left//k
    le=left%k
    total=k*((pow(2,sets+1,pri))-2)
    total%=pri
    print((total+g+le)%pri)

    #nth term is 2^n-2

#/usr/bin/python
# -*- coding: utf-8 -*-

# exam
# 5 3 2
# o x o x o
# 1 1 2 0 3
# 5 4 2
# o o o x o
# 1 4 5 5 6

def modconst():
	return 1000000009;

def modpow(b, e, m):
	""" from Wikipedia(ja): 冪剰余 """
	ret = 1
	while(e > 0):
		if(e & 1):
			ret = (ret * b) % m
		e >>= 1
		b = (b * b) % m
	return ret

# n - num of questions (max: 10E9)
# m - num of correct answers
# k - when his points double
n, m, k = [ int(x) for x in raw_input().split(" ") ]

# n = 11, k = 3
# o o x o o x o o x o o
# max m that has no double = 8 ( = k-1 * (n // k ) + n % k)
maxm = (k-1) * (n // k) + n % k
if( m <= maxm):
	# no double
	print m % modconst()
else:
	# has double
	# to minumum point, we should use double as faster as possible.
	numdouble = m - maxm
	point = 0
	# point += k * (2**(numdouble+1) - 2)
	# point += m - (numdouble * k)
	point = k * (modpow(2, numdouble+1, modconst()) - 2) + m - numdouble * k
	print point % modconst()

# 0 0 0 0 0 0 0 0 0 o
# 1 2 6 7 81819204243
# 3*  2     6    14   30
#                2^n -2
# o o o o o ... ... ... o o o x o o o x o o o

def pow(a, n, mod):
    if n == 1:
        return a
    if n%2 == 0:
        return pow(a, n/2, mod)**2 % mod
    else:
        return a*pow(a, n/2, mod)**2 % mod

n, m, k = map(int, raw_input().split())
mod = 10**9 + 9

l = n%k
t = n/k - (n-m)
if t <= 0:
    print m
else:
    print (k*(pow(2, (t+1), mod) - 2) + (m-k*t))%mod

INF = 10 ** 9 + 9

def solver():
    n,m,k = map(int, raw_input().split())
    x = max(0, m - n + n /k)
    score = (m - k * x + k * (pow(2,x+1,INF) - 2) + INF) % INF
    print score

if __name__ == "__main__":
    solver()

# author:heroming
# -*- coding:utf8-*-

def power(a, mod) :
    s, g = 1, 2
    while a > 0 :
        if (a & 1) :
            s = s * g % mod
        a >>= 1
        g = g * g % mod
    return s

mod = 1000000009

n, m, k = map(int, raw_input().split())
w = n / k
if m + w <= n :
    print m
else :
    e = m + w - n
    p = power(e + 1, mod)
    ans = ((p - 2) * k + m - e * k) % mod
    print ans

MOD = 10 ** 9 + 9
n, m, k = map(int, raw_input().split())
if k * (n - m + 1) - 1 >= n:
    print m
else:
    consecutive = n - k * (n - m)
    print ((2 * k * pow(2, consecutive / k, MOD) - 2 * k + consecutive % k + (k - 1) * (n - m)) % MOD + MOD) % MOD

def modexp(x, n, m):
	if n == 0: return 1;
	r = modexp(x, n >> 1, m);
	if n & 1: return r * r * x % m;
	return r * r % m;

n, m, c = map(int, raw_input().split());
x = n - m;
y = min(m, x * (c - 1));
r = m - y;
y += r % c;
t = r // c + 1;
MOD = 1000000009;
ret = (modexp(2, t, MOD) - 2) * c + y;
print ret % MOD;

n, m, k = map(int, raw_input().split())
mod = 10 ** 9 + 9

wrong = n - m
right = (k - 1) * wrong
left = m - right

def cal(k, times):
    if times == 0: return 0
    else:
        return (pow(2, times + 1, mod) - 2) * k

if left <= 0:
    print m % mod
else:
    times = left / k
    remain = left % k
    print (cal(k, times) + remain + right) % mod

I=lambda:map(int, raw_input().split())
bignum = 10**9+9

n, m, k = I()
zeroes = n-m
if zeroes >= n/k:
    print m
    exit()

fullsets = n/k - zeroes
remaining = n - k*fullsets - zeroes

score = (k * (pow(2, fullsets+1, bignum) - 2)) % bignum

score += remaining
score %= bignum

print score

n,m,k=map(int,input().split())

def ff(t):

    res=0

    while t>0:

        res+=2**t
        t-=1

    return res

if k*(n-m+1)>n:

    print(m)

else:

    minsc=(k-1)*(n-m+1)
    tem1=n-(k*(n-m+1)-1)
    tem2=m-(k-1)*(n-m+1)
    n=tem1
    m=tem2

    t=int(n/k)
    minsc+=n%k

    minsc+=ff(t)*k

    print(minsc)

n,m,k = map(int, raw_input().split())
w = n - m
s = (k-1) * w
m = max(0,m-s)
nn = m/k
res = 0
for i in xrange(nn):
	res += k
	res *=2
res += s + m%k
print res

n, corecte, k = map(int, input().split())
incorecte = n - corecte
mod = 10**9 + 9

corecte_consecutive = max(0, n - incorecte * k)
dublari = corecte_consecutive // k
corecte_ramase = corecte - corecte_consecutive

score = 0
score = (2**(dublari+1) - 2) * k

#print("scor chiar dupa dublari = %i" % score)
#print("corecte_consecutive = %i" % corecte_consecutive)
#print("dublari = %i" % dublari)
#print("corecte_ramase = %i" % corecte_ramase)

score += corecte_ramase
score += corecte_consecutive % k

print(score)

from sys import stdin
n, m, k = map(int, stdin.readline().split(' '))
doublesNeeded = int(m - (n - n / k))
score = 0
if doublesNeeded > 0:
    score += 1
    score <<= (doublesNeeded + 1)
    score -= 1
    score *= k
    score -= k
score += m - doublesNeeded * k
score %= 1000000009
print(score)

from sys import stdin
n, m, k = map(int, stdin.readline().split(' '))
doublesNeeded = int(m - (n - n / k))
score = 0
if doublesNeeded > 0:
    score += 1
    score <<= (doublesNeeded + 1)
    score -= 1
    score *= k
    score -= k
if m > 0:
    score += m - doublesNeeded * k

score %= 1000000009
print(score)

n,m,k = map(int,raw_input().split())
t = m/k
mod = 1000000009
if t > n-m :
	ans =  (((n-m))*k)%mod + ((((2**(t-(n-m) + 1))%mod - 2)%mod)*k)%mod
else:
	ans = m
print ans

# Allah is the most gracious and the Most Marchiful
num,m,k=map(int,input().split())
i=1
j=num
while(i<=j):
    mid=(i+j)//2
    if (mid+((num-mid)//2)>=m):
        MM=mid
        j=mid-1
    else:
       i=mid+1
#print(MM)
M=10**9+9
p=MM//k

ans=(pow(2,p+1,M)-2)*k
ans+=MM%k
ans=ans%M
ans+=m-MM
ans=ans%M
print(ans)

line = raw_input()
data = [int(i) for i in line.split()]
n,m,k = data

def power(g_base,a,p_mod):
  x=1
  bits = "{0:b}".format(a)
  for i, bit in enumerate(bits):
    if bit=='1': x = (((x**2)*g_base)%p_mod)
    elif bit=='0': x = ((x**2)%p_mod)
  return x%p_mod

import time
t = time.clock()
limit = n - (n/k)
if m <= limit :   print m % 1000000009
else:
    score = 0
    totry = m - limit
    i = 0
    m -=(totry*k)
    score = k*(((1-power(2,(totry+1),1000000009))/(1-2))-1) % 1000000009
    score += m
    print score

import sys

inputs = sys.stdin.readline().split()
n = int(inputs[0])
m = int(inputs[1])
k = int(inputs[2])

w = n - m

if k*w + (k-1) >= n:
    print m
else:
    no_double = n - k*w
    result = 0
    cycle = no_double/k
    remainer = no_double%k
    for i in xrange(cycle):
        result = (result + k) * 2
    result += remainer + w*(k-1)
    print result

N , M , K = map(int, raw_input().split() )
a = N - M
Mod = 1000000009 ;

def calc( n ):
    n += 1
    res = 1 ; add = 2 ;
    while( n ):
        if n&1 :
            res = ( res * add ) % Mod ;
        add = ( add * add ) % Mod ;
        n >>= 1 ;
    return res ;

if ( N<=a*K+K-1 ):
    ans = M ;
else:
    ans = ( calc( N / K - a ) + M - ( N / K - a ) * K ) % Mod
print ans

import sys
input=sys.stdin.readline
import bisect
from math import floor
def bo(i):
    return ord(i)-ord('a')
n,m,k=map(int,input().split())
mod=10**9+9
p=int(floor(m-((n+1)*(k-1))//k))
#print(n/k-n+m,p)
print((k*(pow(2,max(0,p+1),mod))-2*k+m-p*k+mod)%mod )

MOD=1000000009;
def solve(a,n):
    ans=1;
    p=a;
    while(n>0):
        if(n%2==1): ans*=p;
        n/=2;
        ans%=MOD;
        p=(p*p)%MOD;
    return ans;
n,m,k=map(int,input().split());
p=n-m+1;
if((k-1)*p>=m):
    print(m);
else:
    v=m-(p-1)*(k-1);
    ans=(p-1)*(k-1);
    t=v//k;
    ans=(ans+k*(solve(2,t)-1)*2%MOD+MOD+v%k)%MOD;
    print(ans);

n,m,k = map(int,raw_input().split())
y = min(n - m,m);
x = m - y;
num = x/k

mod = 10**9 + 9;
ans = (pow(2,num+1,mod) - 2)*k + x%k + y;
ans = (ans%mod + mod)%mod;
print ans;

n,m,k = map(int, raw_input().split())
mod = 10**9+9
x = max(0, n/k-n+m)
p = pow(2,x+1,mod)-2
print p*k+m-x*k

import math

i = raw_input().split()
n, m, k = int(i[0]), int(i[1]), int(i[2])

mod = 100000009
min_of_double = max(0, m - (n - n % k) / k * (k - 1) - n % k)
#min_of_double = abs(min(0, n - m - m / k))

output = (math.pow(2, min_of_double + 1) - 2) * k + m - min_of_double * k
print output % mod

N , M , K = map(int, raw_input().split() )
a = N - M
Mod = 1000000009 ;

def calc( n ):
    n += 1
    res = 0 ; add = 2 ;
    while( n ):
        if n&1 :
            res = ( res + add )
            if res >= Mod :
                res -= Mod
        add = ( add * add ) % Mod ;
        n >>= 1 ;
    return res ;

if ( N<=a*K+K-1 ):
    ans = M ;
else:
    ans = ( calc( N / K - a ) + M - ( N / K - a ) * K ) % Mod
print ans

import sys, math
def rs():
    return sys.stdin.readline().strip()
def ri():
    return int(sys.stdin.readline().strip())
def ras():
    return list(sys.stdin.readline().strip())
def rai():
    return map(int,sys.stdin.readline().strip().split())

def solve():
 n,m,k = rai()

 MAX = 1000000009
 t = n - m

 count = 0

 if m < k:
     return m

 count = m / (k - 1)

 if count*(k-1) == m:
     count -= 1

 if count <= t:
     return m

 r = (k - 1) * t

 v = m - r

 r  = r % MAX

 o = v / k

 ost = v - o*k

 rr = 2 ** (o + 1) % MAX + ost

 return (r + rr) % MAX

print solve()

import math

i = raw_input().split()
n, m, k = int(i[0]), int(i[1]), int(i[2])

mod = 100000009
min_of_double = max(0, m - (n - n % k) / k * (k - 1) - n % k)
#min_of_double = abs(min(0, n - m - m / k))

output = (math.pow(2, min_of_double + 1) - 2) * k + m - min_of_double * k
print int(output % mod)

def inp(n):
    if n == 1:
        return map(int, stdin.readline().split())
    elif n == 2:
        return map(float, stdin.readline().split())
    else:
        return map(str, stdin.readline().split())

def sum_range(n):
    return (n * (n + 1)) // 2

def round1(x):
    if (x - int(x) >= .5):
        return ceil(x)
    else:
        return floor(x)

def mult(x, y):
    return ((x % num) * (y % num)) % num

from sys import stdin
from math import *

n, m, k = inp(1)
ans, num = floor(n / k) * (k - 1) + (n % k), 1000000009

if ans >= m:
    print(m % num)
else:
    extra = (m - ans) % num
    ans += (mult(k * 2, 2 ** extra - 1) - mult(k - 1, extra)) % num
    print(ans)

n,m,k=map(int,input().split())

def ff(t):

    res=0

    while t>0:

        res+=2**t
        t-=1

    return res

if k*(n-m+1)>n:

    print(m)

else:

    minsc=(k-1)*(n-m+1)
    tem1=n-(k*(n-m+1)-1)
    tem2=m-(k-1)*(n-m+1)
    n=tem1
    m=tem2

    t=int(n/k)
    minsc+=n%k

    minsc+=ff(t)*k

    print(minsc)

n, m, k = map(int, raw_input().split())

wrongNum = n - m
intervalNum = n / k

if wrongNum >= intervalNum :
    score = m
else :
    prefixSum = 2*k * (2 ** (intervalNum - wrongNum) - 1)
    suffixSum = (m - ((intervalNum-wrongNum) * k)) * (k-1)
    score = (prefixSum + suffixSum) % (10 ** 9 + 9)

print score

n, m, k = map(int, input().split())

d = max(0, n // k - (n - m))

if d > 0:
  res = pow(k, d + 1, 1000000009) + m - k * d
else:
  res = m

print(res)

R = lambda: map(int, input().split())

n, m, k = R()
rem = n % k
zeros = n // k
fulls = max(0, m - zeros * (k - 1) - rem)
zeros -= fulls
acc = 2 * ((1<<fulls) - 1) * k % (10**9 + 9)
print((acc + zeros * (k - 1) + rem) % (10**9 + 9))

n,m,k = map(int,input().split())

chunks = n//k

freespots = chunks*(k-1) + n%k

if m <= freespots:
    print(m)
else:
    doubles = m-freespots

    dchunks = doubles
    chunks -= dchunks

    total=0
    while dchunks>0:
        total = (total+k)*2
        dchunks -=1

    total += n%k + chunks*(k-1)

    print(total)

import sys
from math import gcd,sqrt,ceil,log2
from collections import defaultdict,Counter,deque
from bisect import bisect_left,bisect_right
import math
sys.setrecursionlimit(2*10**5+10)
import heapq
from itertools import permutations

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# import sys
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_sum(bit,i):
    s = 0

    i+=1
    while i>0:
        s+=bit[i]
        i-=i&(-i)

    return s

def update(bit,n,i,v):
    i+=1

    while i<=n:
        bit[i]+=v
        i+=i&(-i)

def modInverse(b,m):
    g = math.gcd(b, m)
    if (g != 1):
        return -1
    else:
        return pow(b, m - 2, m)

def primeFactors(n):

    sa = set()
    sa.add(n)
    while n % 2 == 0:
        sa.add(2)
        n = n // 2

    for i in range(3,int(math.sqrt(n))+1,2):

        while n % i== 0:
            sa.add(i)
            n = n // i

    # sa.add(n)
    return sa

def seive(n):

    pri = [True]*(n+1)
    p = 2
    while p*p<=n:

        if pri[p] == True:

            for i in range(p*p,n+1,p):
                pri[i] = False

        p+=1

    return pri

def check_prim(n):

    if n<0:
        return False
    for i in range(2,int(sqrt(n))+1):
        if n%i == 0:
            return False

    return True

def getZarr(string, z):
    n = len(string)

    # [L,R] make a window which matches
    # with prefix of s
    l, r, k = 0, 0, 0
    for i in range(1, n):

        # if i>R nothing matches so we will calculate.
        # Z[i] using naive way.
        if i > r:
            l, r = i, i

            # R-L = 0 in starting, so it will start
            # checking from 0'th index. For example,
            # for "ababab" and i = 1, the value of R
            # remains 0 and Z[i] becomes 0. For string
            # "aaaaaa" and i = 1, Z[i] and R become 5
            while r < n and string[r - l] == string[r]:
                r += 1
            z[i] = r - l
            r -= 1
        else:

            # k = i-L so k corresponds to number which
            # matches in [L,R] interval.
            k = i - l

            # if Z[k] is less than remaining interval
            # then Z[i] will be equal to Z[k].
            # For example, str = "ababab", i = 3, R = 5
            # and L = 2
            if z[k] < r - i + 1:
                z[i] = z[k]

                # For example str = "aaaaaa" and i = 2,
            # R is 5, L is 0
            else:

                # else start from R and check manually
                l = i
                while r < n and string[r - l] == string[r]:
                    r += 1
                z[i] = r - l
                r -= 1

def search(text, pattern):

    # Create concatenated string "P$T"
    concat = pattern + "$" + text
    l = len(concat)

    z = [0] * l
    getZarr(concat, z)

    ha = []
    for i in range(l):

        if z[i] == len(pattern):
            ha.append(i - len(pattern) - 1)

    return ha

# n,k = map(int,input().split())
# l = list(map(int,input().split()))

#
# n = int(input())
# l = list(map(int,input().split()))
#
# hash = defaultdict(list)
# la = []
#
# for i in range(n):
#     la.append([l[i],i+1])
#
# la.sort(key = lambda x: (x[0],-x[1]))
# ans = []
# r = n
# flag = 0
# lo = []
# ha = [i for i in range(n,0,-1)]
# yo = []
# for a,b in la:
#
#    if a == 1:
#        ans.append([r,b])
#        # hash[(1,1)].append([b,r])
#        lo.append((r,b))
#        ha.pop(0)
#        yo.append([r,b])
#        r-=1
#
#    elif a == 2:
#        # print(yo,lo)
#        # print(hash[1,1])
#        if lo == []:
#            flag = 1
#            break
#        c,d = lo.pop(0)
#        yo.pop(0)
#        if b>=d:
#            flag = 1
#            break
#        ans.append([c,b])
#        yo.append([c,b])
#
#
#
#    elif a == 3:
#
#            if yo == []:
#                flag = 1
#                break
#            c,d = yo.pop(0)
#            if b>=d:
#                flag = 1
#                break
#            if ha == []:
#                flag = 1
#                break
#
#            ka = ha.pop(0)
#
#            ans.append([ka,b])
#            ans.append([ka,d])
#            yo.append([ka,b])
#
# if flag:
#     print(-1)
# else:
#     print(len(ans))
#     for a,b in ans:
#         print(a,b)
def mergeIntervals(arr):

    # Sorting based on the increasing order
    # of the start intervals
    arr.sort(key = lambda x: x[0])

    # array to hold the merged intervals
    m = []
    s = -10000
    max = -100000
    for i in range(len(arr)):
        a = arr[i]
        if a[0] > max:
            if i != 0:
                m.append([s,max])
            max = a[1]
            s = a[0]
        else:
            if a[1] >= max:
                max = a[1]

    #'max' value gives the last point of
    # that particular interval
    # 's' gives the starting point of that interval
    # 'm' array contains the list of all merged intervals

    if max != -100000 and [s, max] not in m:
        m.append([s, max])
    return m
class SortedList:
    def __init__(self, iterable=[], _load=200):
        """Initialize sorted list instance."""
        values = sorted(iterable)
        self._len = _len = len(values)
        self._load = _load
        self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
        self._list_lens = [len(_list) for _list in _lists]
        self._mins = [_list[0] for _list in _lists]
        self._fen_tree = []
        self._rebuild = True

    def _fen_build(self):
        """Build a fenwick tree instance."""
        self._fen_tree[:] = self._list_lens
        _fen_tree = self._fen_tree
        for i in range(len(_fen_tree)):
            if i | i + 1 < len(_fen_tree):
                _fen_tree[i | i + 1] += _fen_tree[i]
        self._rebuild = False

    def _fen_update(self, index, value):
        """Update `fen_tree[index] += value`."""
        if not self._rebuild:
            _fen_tree = self._fen_tree
            while index < len(_fen_tree):
                _fen_tree[index] += value
                index |= index + 1

    def _fen_query(self, end):
        """Return `sum(_fen_tree[:end])`."""
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        x = 0
        while end:
            x += _fen_tree[end - 1]
            end &= end - 1
        return x

    def _fen_findkth(self, k):
        """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
        _list_lens = self._list_lens
        if k < _list_lens[0]:
            return 0, k
        if k >= self._len - _list_lens[-1]:
            return len(_list_lens) - 1, k + _list_lens[-1] - self._len
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        idx = -1
        for d in reversed(range(len(_fen_tree).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                idx = right_idx
                k -= _fen_tree[idx]
        return idx + 1, k

    def _delete(self, pos, idx):
        """Delete value at the given `(pos, idx)`."""
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len -= 1
        self._fen_update(pos, -1)
        del _lists[pos][idx]
        _list_lens[pos] -= 1

        if _list_lens[pos]:
            _mins[pos] = _lists[pos][0]
        else:
            del _lists[pos]
            del _list_lens[pos]
            del _mins[pos]
            self._rebuild = True

    def _loc_left(self, value):
        """Return an index pair that corresponds to the first position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        lo, pos = -1, len(_lists) - 1
        while lo + 1 < pos:
            mi = (lo + pos) >> 1
            if value <= _mins[mi]:
                pos = mi
            else:
                lo = mi

        if pos and value <= _lists[pos - 1][-1]:
            pos -= 1

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value <= _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def _loc_right(self, value):
        """Return an index pair that corresponds to the last position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        pos, hi = 0, len(_lists)
        while pos + 1 < hi:
            mi = (pos + hi) >> 1
            if value < _mins[mi]:
                hi = mi
            else:
                pos = mi

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value < _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def add(self, value):
        """Add `value` to sorted list."""
        _load = self._load
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len += 1
        if _lists:
            pos, idx = self._loc_right(value)
            self._fen_update(pos, 1)
            _list = _lists[pos]
            _list.insert(idx, value)
            _list_lens[pos] += 1
            _mins[pos] = _list[0]
            if _load + _load < len(_list):
                _lists.insert(pos + 1, _list[_load:])
                _list_lens.insert(pos + 1, len(_list) - _load)
                _mins.insert(pos + 1, _list[_load])
                _list_lens[pos] = _load
                del _list[_load:]
                self._rebuild = True
        else:
            _lists.append([value])
            _mins.append(value)
            _list_lens.append(1)
            self._rebuild = True

    def discard(self, value):
        """Remove `value` from sorted list if it is a member."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_right(value)
            if idx and _lists[pos][idx - 1] == value:
                self._delete(pos, idx - 1)

    def remove(self, value):
        """Remove `value` from sorted list; `value` must be a member."""
        _len = self._len
        self.discard(value)
        if _len == self._len:
            raise ValueError('{0!r} not in list'.format(value))

    def pop(self, index=-1):
        """Remove and return value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        value = self._lists[pos][idx]
        self._delete(pos, idx)
        return value

    def bisect_left(self, value):
        """Return the first index to insert `value` in the sorted list."""
        pos, idx = self._loc_left(value)
        return self._fen_query(pos) + idx

    def bisect_right(self, value):
        """Return the last index to insert `value` in the sorted list."""
        pos, idx = self._loc_right(value)
        return self._fen_query(pos) + idx

    def count(self, value):
        """Return number of occurrences of `value` in the sorted list."""
        return self.bisect_right(value) - self.bisect_left(value)

    def __len__(self):
        """Return the size of the sorted list."""
        return self._len

    def __getitem__(self, index):
        """Lookup value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        return self._lists[pos][idx]

    def __delitem__(self, index):
        """Remove value at `index` from sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        self._delete(pos, idx)

    def __contains__(self, value):
        """Return true if `value` is an element of the sorted list."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_left(value)
            return idx < len(_lists[pos]) and _lists[pos][idx] == value
        return False

    def __iter__(self):
        """Return an iterator over the sorted list."""
        return (value for _list in self._lists for value in _list)

    def __reversed__(self):
        """Return a reverse iterator over the sorted list."""
        return (value for _list in reversed(self._lists) for value in reversed(_list))

    def __repr__(self):
        """Return string representation of sorted list."""
        return 'SortedList({0})'.format(list(self))

def ncr(n, r, p):

    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p

def sol(n):

    seti = set()
    for i in range(1,int(sqrt(n))+1):
        if n%i == 0:
            seti.add(n//i)
            seti.add(i)

    return seti

mod = 10**9 + 7
n,m,k = map(int,input().split())
w = n-m
z = (k-1)*min(n//k,n-m)

w-=min(n//k,n-m)

ha = n-(k*min(n//k,n-m)) - w

k1 = 4*((ha)//k) + (ha)%k
print((z+k1)%mod)

def check(c):
    os=m-(c*q);k=n-m;t=os//(q-1)
    if(os%(q-1)):t=t+1
    if(t-1<=k and k>0):return 1
    else:return 0
n,m,q=map(int,input().split())
l=0;r=m//q;p=0;o=0;MOD=1000000009
while(r-l>1):
    c=(l+r)//2
    if(check(c)):r=c
    else:l=c
if(check(l)):p=l
else:p=r
o=q*p*pow(2,p,MOD);m=m-q*p
print((o+m)%MOD)

from sys import stdin,stdout,setrecursionlimit,maxint,exit
#setrecursionlimit(2*10**5)
def listInput():
 return map(long,stdin.readline().split())
def printBS(li):
 for i in xrange(len(li)-1):
  stdout.write("%d "%li[i])
 stdout.write("%d\n"%li[-1])
def sin():
 return stdin.readline().rstrip()
MOD=10**9+7
from math import log
n,m,k=listInput()
x=int(log(n,k))
if m<=n-x:
 print m
 exit(0)
e=m-n+x
ans=0
for i in xrange(1,e+1):
 ans+=k
 ans=(ans*2)%MOD
 m-=k
print (ans+m)%MOD

def inp(n):
    if n == 1:
        return map(int, stdin.readline().split())
    elif n == 2:
        return map(float, stdin.readline().split())
    else:
        return map(str, stdin.readline().split())

def sum_range(n):
    return (n * (n + 1)) // 2

def round1(x):
    if (x - int(x) >= .5):
        return ceil(x)
    else:
        return floor(x)

from sys import stdin
from math import *

n, m, k = inp(1)
ans = round1(n / k) * (k - 1)

if ans >= m:
    print(m)
else:
    extra = m - ans
    ans += (k * 2) * extra - (k - 1) *extra
    print(ans)

# -*- coding: cp1251 -*-
import sys
import itertools
def calc(cnt, k):
    ydv = cnt/k
    ostat = cnt % k
    #ydv
    #1 - 2*k, 2 - 6*k, 3 - 14*k, 30*k
    q = 2
    #b1 = k<<1
    b1 = k*2
    res = b1 * (1<<(ydv)-1)
    return res + ostat

def calc___________(cnt, k):
    res = 0
    acc = 0
    for i in xrange(cnt):
        res += 1
        acc += 1
        if acc == k:
            acc = 0
            res *= 2

    return res

def solve(n, m, k):
    ans_plus = m
    ans_minus = n-m
    fails_cnt = n/k
    if fails_cnt <= ans_minus:
        #print "!"
        return m
    else:
        #++++++++++++ ____ .+++.+++.+++|
        ans_plus -= ans_minus * (k - 1)
        return calc(ans_plus, k) + (m - ans_plus)

    return
    return 0
n, m, k = map(int, sys.stdin.readline().split())

print str(solve(n, m, k) % (10**9+9))

#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+9
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
# vsInput()

n,m,k=value()

sections=n//(k)
minScore=n%(k)+sections*(k-1)

covered=max(m-minScore,0)
# print(covered)

score= ((k * 2*(covered%M)*((covered+1)%M))%M)//2
# print(score)

score=(score+(m-covered*k))%M

print(score)

def pow(a, n, mod):
    if n == 1:
        return a
    if n%2 == 0:
        return pow(a, n/2, mod)**2 % mod
    else:
        return a*pow(a, n/2, mod)**2 % mod

n, m, k = map(int, raw_input().split())
mod = 10**9 + 9

l = n%k
t = n/k - (n-m)
if t <= 0:
    print m
else:
    print k*(pow(2, (t+1), mod) - 2) + (m-k*t)

MOD = int(1e9+7)

def fast_power(x, y):
    res = 1
    while y > 0:
        if y % 2 == 1:
            res = res * x%MOD
        x = x * x % MOD
        y //= 2
    return res

n, m, k = map(int, input().split())
x = max(0, m - n // k * (k - 1) - n % k)
z = (m - x * k) % MOD
res = fast_power(2, x+1)
res = (res - 2) % MOD * k % MOD
res = (res + z) % MOD
print(res)

line = raw_input()
data = [int(i) for i in line.split()]
n,m,k = data

def power(g_base,a,p_mod):
  x=1
  bits = "{0:b}".format(a)
  for i, bit in enumerate(bits):
    if bit=='1': x = (((x**2)*g_base)%p_mod)
    elif bit=='0': x = ((x**2)%p_mod)
  return x%p_mod

import time
t = time.clock()
limit = n - (n/k)
if m <= limit :   print m % 1000000009
else:
    score = 0
    totry = max(0, m - (n - n % k) / k * (k-1) - n % k)
    i = 0
    m -=(totry*k)
    score = k*(((1-power(2,(totry+1),1000000009))/(1-2))-1) % 1000000009
    score += m
    print score
#print time.clock()-t

"""
def exp-by-squaring(x,n)
     if n<0:  return exp-by-squaring(1/x,-n);
     else if n=0:  return 1;
     else if n=1:  return x;
     else if n%2 == 0 then return exp-by-squaring(x*x, n/2);
     else :return x * exp-by-squaring(x*x, (n-1)/2).
"""
"""
line = input()
data = [int(i) for i in line.split()]
n,m,k = data

limit = n - int(n/k)
if m <= limit :   print (m % 1000000009 )
else:
    score = 0
    totry = m - limit
    for i in range(totry):
        score += k
        score *= 2
        m -=k
    score += m
    print (score % 1000000009 )
 """

import math
def get_res(n, m, k):
    D = 1000000009
    p = max(0, m-(n-m)*(k-1))
    result = (4*(pow(2,p/k, D)-1) + p%k + (n-m)*(k-1)) % D
    return result

#N = int(raw_input())
n, m, k= [int(s) for s in raw_input().split(" ")]
result = get_res(n, m, k)
print "{}".format(result)

n,m,k = map(int,raw_input().split())
t = m/k
mod = 1000000009
if t > n-m :
	ans =  (((n-m))*k)%mod + ((((2**(t-(n-m) + 1))%mod - 2)%mod)*k)%mod
else:
	ans = m
print ans

n , m , k = (raw_input().split())

n = int(n)
m = int(m)
k = int(k)

M = 1000000009

rem = n-m
rem+=1

if((k-1)*rem >= m):
	print m
else:
	by = (rem-1)*(k-1)
	m-=by

	quo = m/k
	quo*=2*k
	quo+=m%k

	quo+=by
	quo%=M

	print quo

from collections import defaultdict
mod = int(1e9 + 9)
def is_good(n, a, b):
	while n:
		digit = n%10
		if digit != a and digit != b:
			return False
		n = n//10

	return True

if __name__ == '__main__':
	n, m, k = map(int, input().split())
	m -= n%k
	score = n%k
	n -= n%k

	sets = n/k

	used = sets*(k-1)

	if used >= m:
		print(m+score)
		exit()

	else:
		filled = m - used
		score += int(((2*(2**filled)-2)%mod * k)%mod)
		score += int(sets - filled)

	print(score%mod)

def inp(n):
    if n == 1:
        return map(int, stdin.readline().split())
    elif n == 2:
        return map(float, stdin.readline().split())
    else:
        return map(str, stdin.readline().split())

def sum_range(n):
    return (n * (n + 1)) // 2

def round1(x):
    if (x - int(x) >= .5):
        return ceil(x)
    else:
        return floor(x)

from sys import stdin
from math import *

n, m, k = inp(1)
ans = round1(n / k) * (k - 1)

if ans >= m:
    print(m % (10 ** 9 + 9))
else:
    extra = m - ans
    ans += ((k * 2) * ((2 ** extra) - 1)) - ((k - 1) * extra)
    print(ans % (10 ** 9 + 9))

MOD = 10**9+9

def _pow(a,b):
    v = a; ret = 1
    for i in range(30):
        if (b>>i)&1 > 0:
            ret = ret*v%MOD
        v = v*v%MOD
    return ret

N,M,K = map(int,raw_input().split())
s = 0; e = N/K
while s <= e:
    m = (s+e)>>1
    probs = K*m; space = N-probs
    probs += space/K*(K-1)+space%K
    if probs >= M:
        e = m-1; t = m
    else:
        s = m+1
ans = (_pow(2,t+1)-2+MOD)*K%MOD
ans += M-K*t
print ans

from sys import stdin
import fractions

def line():
    return stdin.readline().split()
def read_int():
    return int(line()[0])
def read_ints():
    return [int(x) for x in line()]
def memo(fn):
    table = {}
    def memoized(*args):
        if args not in table:
            table[args] = fn(*args)
        else:
            print "Hit! %s" % (args,)
        return table[args]
    return memoized

def solve(n, m, k):
    if (n - m)*k >= n:
        return n

    skips = (n - m)
    n -= skips*k
    doubles, last = n / k, n % k

    score = 2*k*(pow(2, doubles, 1000000009) - 1)
    score += (k - 1) * skips
    score += last
    score = score % 1000000009

    return score

n, m, k = read_ints()
print solve(n, m, k)

N , M , K = map(int, raw_input().split() )
a = N - M
Mod = 1000000009 ;

if ( N<=a*K+K-1 ):
    ans = M ;
else:
    ans = ( ( N / K - a ) * 2 * K % Mod + a * (K - 1) % Mod +  N - N/K*K ) % Mod ;
print ans

n,m,k = map(int,raw_input().split())
y = min(n - m,m);
x = m - y;
#print x,y;
num = x/k

mod = 10**9 + 7;
ans = (pow(2,num+1,mod) - 2)*k + x%k + y;
ans = (ans%mod + mod)%mod;
print ans;

import sys
input=sys.stdin.readline
import bisect
from math import floor
def bo(i):
    return ord(i)-ord('a')
n,m,k=map(int,input().split())
mod=10**9+9
p=int(floor(m-((n+1)*(k-1))//k))
#print(n/k-n+m,p)
print((k*(pow(2,max(0,p+1),mod))-2*k+m-p*k+mod)%mod )

n,m,k = map(int,raw_input().split())
y = min(n - m,m);
x = m - y;
num = x/k

mod = 10**9 + 9;
ans = (pow(2,num+1,mod) - 2)*k + x%k + y;
ans = (ans%mod + mod)%mod;
print ans;

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

def main():
    n, m, k = [ int(x) for x in input().split() ]
    mod = 1000000009

    positions = n / k
    availablePositions = int(
        int(positions)*(k - 1) + (positions - int(positions)) / (1/k)
    )

    if availablePositions >= m:
        points = m
    else:
        positionsLeft = m - availablePositions

        points = (
            pow(2, positionsLeft, mod)*k + 2*k*(pow(2, positionsLeft - 1, mod) - 1)
            + (m - k * positionsLeft)
        ) % mod

    print(points)

BUFFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

input = lambda: sys.stdin.readline().rstrip("\r\n")

def print(*args, **kwargs):
    sep = kwargs.pop("sep", " ")
    file = kwargs.pop("file", sys.stdout)

    atStart = True
    for x in args:
        if not atStart:
            file.write(sep)
        file.write(str(x))
        atStart = False
    file.write(kwargs.pop("end", "\n"))

    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

main()

n,m,k=map(int,input().split())
mod=10**9+7
x=n-m
if x>=n//2:
    print(m)
else:
    y=n-k*x
    a=y//k
    b=y%k
    ans=pow(k,2,mod)*(pow(k,a,mod)-1)*pow(k-1,mod-2,mod)
    ans%=mod
    ans+=x+b
    print(ans)

import sys

inputs = sys.stdin.readline().split()
n = int(inputs[0])
m = int(inputs[1])
k = int(inputs[2])

w = n - m

if k*w + (k-1) >= n:
    print m
else:
    no_double = n - k*w
    result = 0
    cycle = no_double/k
    print "cycle is " + str(cycle)
    remainder = no_double%k
    print "remainder is " + str(remainder)
    for i in xrange(cycle):
        result = (result + k) * 2 % (10**9+9)
    result = (result + remainder + w*(k-1)) % (10**9+9)
    print result

i = raw_input().split()
n, m, k = int(i[0]), int(i[1]), int(i[2])

mod = 100000009
min_of_double = abs(min(0, n - m - m / k))

output = m
bonus = 0

for i in range(0, min_of_double):
    bonus = bonus + k * (i + 1)

print output + bonus

# -*- coding: cp1251 -*-
import sys
import itertools
def calc(cnt, k):
    ydv = cnt/k
    ostat = cnt % k
    #ydv
    #1 - 2*k, 2 - 6*k, 3 - 14*k, 30*k
    q = 2
    b1 = k<<1
    res = b1 * (1<<(ydv)-1)
    return res + ostat

def calc___________(cnt, k):
    res = 0
    acc = 0
    for i in xrange(cnt):
        res += 1
        acc += 1
        if acc == k:
            acc = 0
            res *= 2

    return res

def solve(n, m, k):
    ans_plus = m
    ans_minus = n-m
    fails_cnt = n/k
    if fails_cnt <= ans_minus:
        #print "!"
        return m
    else:
        #++++++++++++ ____ .+++.+++.+++|
        ans_plus -= ans_minus * (k - 1)
        return calc(ans_plus, k) + (m - ans_plus)

    return
    return 0
n, m, k = map(int, sys.stdin.readline().split())

print str(solve(n, m, k) % (10**9+9))

def pow(a, n, mod):
    if n == 1:
        return a
    if n%2 == 0:
        return pow(a, n/2, mod)**2 % mod
    else:
        return a*pow(a, n/2, mod)**2 % mod

n, m, k = map(int, raw_input().split())
mod = 10**9 + 9

l = n%k
t = n/k - (n-m)
if t <= 0:
    print m
else:
    print k*(pow(2, (t+1), mod) - 2) + (m-k*t)

import sys

MOD = 1000000009

def rep_square(x, y):
    if y == 1:
        return x
    base = rep_square(x, y/2)
    if y % 2 == 1:
        return (base * base * x) % MOD
    return (base * base) % MOD

n_questions, n_corrects, n_k = (int(x) for x in sys.stdin.readline().split())
if n_corrects == 0:
    print(0)
    sys.exit(0)

n_gaps = n_questions-n_corrects
score = min(n_gaps, n_corrects) * (n_k-1)
n_consec_left = n_corrects - score
if n_consec_left > 0:
    score += (n_consec_left % n_k) + n_k * (rep_square(2, n_consec_left/n_k+1) - 2)
print(score % MOD)

R = lambda: map(int, input().split())

n, m, k = R()
rem = n % k
zeros = n // k
fulls = max(0, m - zeros * (k - 1) - rem)
zeros -= fulls
acc = 2 * ((1<<fulls) - 1) * k % (10**9 + 9)
print((acc + zeros * (k - 1) + rem) % (10**9 + 9))

MOD = 1000000009
def p2(e):
    if e == 0:
        return 1
    elif e % 2 == 1:
        return 2 * p2(e - 1) % MOD
    else:
        return p2(e // 2) ** 2 % MOD

n, m, k = map(int, input().split())
x = (m - min(n - m, n // (k - 1))) // k
print((2 * k * (p2(x) - 1) + m - x * k) % MOD)

from collections import defaultdict
mod = int(1000000009)
def is_good(n, a, b):
	while n:
		digit = n%10
		if digit != a and digit != b:
			return False
		n = n//10

	return True

if __name__ == '__main__':
	n, m, k = map(int, input().split())
	m -= n%k
	score = n%k
	n -= n%k

	sets = n//k

	used = sets*(k-1)

	if used >= m:
		print(m+score)
		exit()

	else:
		filled = m - used
		print(score, filled)
		score += int(((2*(2**filled)-2) * k))
		score += int(sets - filled)

	print(score%mod)

import os
import sys
from io import BytesIO, IOBase
import math

def main():
    pass

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

import os
import sys
from io import BytesIO, IOBase

def main():
    pass

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

n,m,k=map(int,input().split())
p=n//k
mws=(k-1)*p+n%k
mod=1000000009
#print(mws)
if(m<=mws):
    print(m)
else:
    con=m-mws
    #print(con,mws)
    acon=(4*(pow(2,con,mod)-1))%mod
    m-=(k*con)
    ans=(acon+m)%mod
    print(ans)

MOD=1000000009;
def solve(a,n):
    ans=1;
    p=a;
    while(n>0):
        if(n%2==1): ans*=p;
        n/=2;
        ans%=MOD;
        p=(p*p)%MOD;
    return ans;
n,m,k=map(int,input().split());
p=n-m+1;
if((k-1)*p>=m):
    print(m);
else:
    v=m-(p-1)*(k-1);
    ans=(p-1)*(k-1);
    t=v//k;
    ans=(ans+k*(solve(2,t)-1)*2%MOD+MOD+v%k)%MOD;
    print(ans);

line = raw_input()
data = [int(i) for i in line.split()]
n,m,k = data

def power(g_base,a,p_mod):
  x=1
  bits = "{0:b}".format(a)
  for i, bit in enumerate(bits):
    if bit=='1': x = (((x**2)*g_base)%p_mod)
    elif bit=='0': x = ((x**2)%p_mod)
  return x%p_mod

import time
t = time.clock()
limit = n - (n/k)
if m <= limit :   print m % 1000000009
else:
    score = 0
    totry = m - limit
    i = 0
    m -=(totry*k)
    score = k*(((1-pow(2,(totry+1),1000000009))/(1-2))-1) % 1000000009
    score += m
    print score
#print time.clock()-t

"""
def exp-by-squaring(x,n)
     if n<0:  return exp-by-squaring(1/x,-n);
     else if n=0:  return 1;
     else if n=1:  return x;
     else if n%2 == 0 then return exp-by-squaring(x*x, n/2);
     else :return x * exp-by-squaring(x*x, (n-1)/2).
"""
"""
line = input()
data = [int(i) for i in line.split()]
n,m,k = data

limit = n - int(n/k)
if m <= limit :   print (m % 1000000009 )
else:
    score = 0
    totry = m - limit
    for i in range(totry):
        score += k
        score *= 2
        m -=k
    score += m
    print (score % 1000000009 )
 """

import sys

mod = 1000000009

def my_pow(n):
	if n == 0:
		return 1
	if n % 2:
		return (2 * my_pow(n - 1)) % mod
	div = my_pow(n / 2)
	return (div * div) % mod

n, m, k = map(int, sys.stdin.readline().strip().split())
chunk = n / k
r = m - (chunk * (k - 1) + n % k)
p = max(r, 0)

sol = 0
if (p):
	sol += (k * my_pow(p + 1)) % mod
	sol -= 2 * k
	sol = (sol + mod) % mod
	m -= k * p

print sol + m

def check(c):
    os=m-(c*q);k=n-m;t=os//(q-1)
    if(os%(q-1)):t=t+1
    if(t-1<=k):return 1
    else:return 0
n,m,q=map(int,input().split())
l=0;r=m//q;p=0;o=0;MOD=1000000009
while(r-l>1):
    c=(l+r)//2
    if(check(c)):l=c
    else:r=c
if(check(l)):p=l
else:p=r
for i in range(p):
    o=(o+q)*2;m=m-q;
print(o+m)

n, m, k = map(int, input().split())

d = max(0, n // k - (n - m))

if d > 0:
  res = pow(k, d + 1, 1000000009) + m - k * d
else:
  res = m

print(res)

num,m,k=map(int,input().split())
i=1
j=num
while(i<=j):
    mid=(i+j)//2
    if (mid+((num-mid)//2)>=m):
        MM=mid
        j=mid-1
    else:
       i=mid+1
#print(MM)
M=10**9+9
p=MM//k

ans=(pow(2,p+1,M)-2)*k
ans+=MM%k
ans+=m-MM
print(ans)

import math
def get_res(n, m, k):
    D = 1000000009
    p = max(0, m-(n-m)*(k-1))
    result = (4*(pow(2,p/k, D)-1) + p%k + (n-m)*(k-1)) % D
    return result

#N = int(raw_input())
n, m, k= [int(s) for s in raw_input().split(" ")]
result = get_res(n, m, k)
print "{}".format(result)

n, m, k = map(int, raw_input().split())
a = 1000000009

udv = m - n + n / k
if udv <= 0:
    print m
else:
    x = (pow(2, udv + 1, a) - 2) * k
    print x + m - udv * k

import math
if __name__=="__main__":
    n,m,k = map(int, raw_input().split())
    md = m+0.
    maxA = 10**9+9

    if  (math.ceil(md/(k-1))-1)*k+ (m-(math.ceil(md/(k-1))-1)*(k-1)) <= n:
        print m%maxA
    else:
        p1=math.floor((n+0.)/k)
        extra=int(m-p1*(k-1)-(n-p1*k))
        #print n,extra, p1
        res=pow(2,extra+1,maxA)
        res=(res*k+maxA-2*k)%maxA
        print res

N , M , K = map(int, raw_input().split() )
a = N - M
Mod = 1000000009 ;

def calc( n ):
    n += 1
    res = 1 ; add = 2 ;
    while( n ):
        if n&1 :
            res = ( res * add ) % Mod ;
        add = ( add * add ) % Mod ;
        n >>= 1 ;
    return res - 1 ;

if ( N<=a*K+K-1 ):
    ans = M ;
else:
    ans = ( calc( N / K - a ) * K % Mod  + M - ( N / K - a ) * K ) % Mod
print ans