5986: 测验

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:15 通过:5

题目描述

        Manao正在参加一个测验。测验由n个连续的问题组成。正确回答一题会给玩家一分。游戏还有一个连续正确答案的计数器。当玩家正确回答问题时,这个计数器上的数字增加了1。如果玩家回答的问题不正确,计数器将被重置,即计数器上的数字将减少到0。如果在回答后计数器达到数字k,则重置,玩家的分数将增加一倍。请注意,在这种情况下,首先将1分添加到玩家的分数中,然后总分将翻倍。在游戏开始时,玩家的分数和连续正确答案的计数器都设置为零。
        Manao记得他正确回答了m个问题。但他不记得问题出现的顺序。他正试图弄清楚他的最低分数是多少。帮助他,并在除以1000000009(1e9 + 9)后计算相应数字的其余部分。
Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.
Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109+9).
Input
The single line contains three space-separated integers n, m and k (2≤kn≤109;0≤mn).
Output
Print a single integer − the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109+9).
Examples
Input
5 3 2
Output
3
Input
5 4 2
Output
6
Note
Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.
Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.
Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000mod1000000009, even though 2000000020mod1000000009 is a smaller number.

输入格式

只有一行,包含三个空格分隔的整数 nm 和 k (2≤kn≤109;0≤mn).

输出格式

树池Manao在测试中的最小可能分数对109+9取模的结果。

样例
输入
5 3 2
输出
3
输入
5 4 2
输出
6



输入样例 复制

5 3 2

输出样例 复制

3

数据范围与提示

样例1:Manao回答了5个问题中的3个,他的分数将在每两个连续正确答案后翻倍。如果Manao答对了第一、三和五题,他将获得3分。
样例2:想在Manao回答了4个问题。当唯一错误的答案是问题4的,他将取得可能的最小分数。
还需注意,你需要最小化的是分数而不是分数对1000000009取模后的结果。例如,如果Manao有可能取得2000000000或2000000020分,答案应该是2000000000模1000000009,尽管2000000020模1000000009是个更小的数字。