#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
long long power(long long a, long long b) {
  if (b == 0) {
    return 1;
  }
  if (b & 1) {
    return (a * power(a, b - 1)) % 1000000009LL;
  }
  long long ret = power(a, b >> 1);
  return (ret * ret) % 1000000009LL;
}
int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  long long lo = 0;
  long long hi = 1 << 30;
  while (lo < hi) {
    long long mi = (lo + hi + 1) / 2;
    if (mi * k <= n && mi * (k - 1) <= m && (n - mi * k >= m - mi * (k - 1))) {
      lo = mi;
    } else {
      hi = mi - 1;
    }
  }
  long long cnt = lo;
  n -= cnt * k;
  m -= cnt * (k - 1);
  long long ans = 0;
  if (m >= k - 1) {
    int two = n / k;
    ans = ((power(2, two + 1) - 2 + 1000000009LL) * k) % 1000000009LL;
    ans += n % k + cnt * (k - 1);
  } else {
    ans = m + cnt * (k - 1);
  }
  ans %= 1000000009LL;
  cout << ans << endl;
  return 0;
}
