Submit | All submissions | Best solutions | Back to list |
ANTJOUR - The Journey of the Ant |
The Journey of the Ant
Time Limit 1 second/test case
Description
You will be given two positive integers m and n. Consider all latice points (the points with integral coordinates) inside (including the edges) a rectangle formed by connecting points (0, 0), (n, 0), (n, m), and (0, m). There's a wad of sugar on each of those (m+1)(n+1) points. A lost ant begins his journey to get back home from point (0, 0). He is an ant, and ants love sugar very much, so he decides to take some of the wads home. Because of some unexplainable reason, if he was on (a, b), then he can only move to (a+1, b), (a+1, b+1), or (a, b-1). Of course the ant is not allowed to get out of the rectangle (or he will get lost, again). He knows that his house is at the other end of the rectangle i.e. (n, m). For example, let n = 3 and m = 2. There are 5 different ways for the ant to get home, as shown in the figure below:
Now your task is to find the number of ways for the ant to get home. Since the value can be very large, so output its remainder when divided by 1000000009 (109 + 9).
Input Format
n and m in a single line, separated by a single space.
Output Format
A line contains the number of such ways.
Input Sample 1
3 2
Output Sample 1
5
Input Sample 2
10 8
Output Sample 2
176
Note
- For 26.67% test cases: 1 ≤ n, m ≤ 1000.
- For 40% test cases: 1000 ≤ max(n,m); 1 ≤ n, m ≤ 1000000; and n×m ≤ 1000000.
- For other 33.33% test cases: 1 ≤ m ≤ 25 and 1000000 < n ≤ 1000000000000000000.
Added by: | Ahmad Zaky |
Date: | 2011-09-16 |
Time limit: | 0.200s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Ahmad Zaky, 2011 |