#include <bits/stdc++.h>
using namespace std;
int main() {
  int t1 = 1;
  long long mod = 1000000009;
  while (t1-- > 0) {
    long long n, m, k;
    cin >> n >> m >> k;
    long long noDob = (n / k) * (k - 1);
    if (n % k != 0) {
      noDob += (n % k);
    }
    if (noDob >= m) {
      cout << m << endl;
    } else {
      long long total = m - noDob;
      long long sum = k;
      long long matrix[2][2];
      matrix[0][0] = 2;
      matrix[0][1] = 2 * k;
      matrix[1][0] = 0;
      matrix[1][1] = 1;
      long long b1 = total - 1;
      bool flag = true;
      long long res[2][2];
      if (total == 1) res[0][0] = 1;
      res[0][1] = 0;
      long long mul[2][2];
      while (b1 > 0) {
        if (b1 % 2) {
          if (flag) {
            flag = false;
            res[0][0] = matrix[0][0];
            res[0][1] = matrix[0][1];
            res[1][0] = matrix[1][0];
            res[1][1] = matrix[1][1];
          } else {
            for (int i = 0; i < 2; i++) {
              for (int j = 0; j < 2; j++) {
                mul[i][j] = 0;
                for (int k = 0; k < 2; k++) {
                  mul[i][j] += res[i][k] * matrix[k][j];
                }
                mul[i][j] %= mod;
              }
            }
            for (int i = 0; i < 2; i++)
              for (int j = 0; j < 2; j++) res[i][j] = mul[i][j];
          }
        }
        for (int i = 0; i < 2; i++) {
          for (int j = 0; j < 2; j++) {
            mul[i][j] = 0;
            for (int k = 0; k < 2; k++) {
              mul[i][j] += matrix[i][k] * matrix[k][j];
            }
            mul[i][j] %= mod;
          }
        }
        for (int i = 0; i < 2; i++)
          for (int j = 0; j < 2; j++) matrix[i][j] = mul[i][j];
        b1 /= 2;
      }
      sum = (res[0][0] * 2 * k + res[0][1] + noDob - total * (k - 1)) % mod;
      cout << sum << endl;
    }
  }
}
