Skill Tree
Time limit2sMemory limit512 MB
For each triangular region of a weighted infinite triangle grid, compute the total cost of all cells in the region modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Prefix sum, Number theory
- Solved
- No attempts yet
Problem
A game that Hyukjung plays added a sixth job advancement. Its skill tree is an equilateral triangular grid that continues downward without end.
Row of the grid holds cells, and the -th cell from the left in that row is written . The cell below and to the left of is , and the cell below and to the right is .
Learning the skill at the top vertex costs won. If the skill in some cell costs won, the cell below and to the left costs won and the cell below and to the right costs won.
The skill tree has special triangles. The special triangle written as the three numbers , , takes cell as its top vertex and covers rows. That is, for each with , the cells from through belong to that triangle. Every time you learn all the skills inside one special triangle, your total damage doubles.
Help Hyukjung and find the cost of learning every skill inside each special triangle.
Input
The first line holds and , separated by a space. ()
The second line holds the number of special triangles . ()
Each of the next lines holds three integers , , separated by spaces, describing one special triangle. (, )
Output
Print lines. On each line print the cost of learning every skill inside the corresponding special triangle, modulo , in the order the triangles are given.