#include <bits/stdc++.h>
using namespace std;
const long long md = 1LL * 1e9 + 9LL;
struct mat {
  long long x[2][2];
  mat operator*(mat other) const {
    mat ret;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        ret.x[i][j] = 0LL;
        for (int k = 0; k < 2; k++) {
          ret.x[i][j] = (ret.x[i][j] + x[i][k] * other.x[k][j]) % md;
        }
      }
    }
    return ret;
  }
};
long long n, m, k;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  if ((k - 1) * (n - m + 1) >= m) {
    cout << m << '\n';
    return 0;
  }
  long long res = (k - 1) * (n - m);
  m = m - res;
  int p = m / k;
  res = (res + (m - (p * k))) % md;
  mat t, lg;
  t.x[0][0] = t.x[1][1] = 1LL;
  t.x[0][1] = t.x[1][0] = 0LL;
  lg.x[0][0] = 2LL;
  lg.x[0][1] = 2LL * k;
  lg.x[1][0] = 0LL;
  lg.x[1][1] = 1LL;
  while (p) {
    if (p & 1) {
      t = t * lg;
    }
    lg = lg * lg;
    p /= 2;
  }
  res = (res + t.x[0][1]) % md;
  cout << res << '\n';
  return 0;
}
