Problem #381
Folding Game
Imagine on your table, you have a paper in the shape of an isosceles right triangle ABC, where AB are the endpoints of the hypotenuse. An operation is defined by the following folds. You join A to C and B to C forming a square. You then join the two diagonally opposite vertices of the newly formed square (previously, the midpoints of AC and BC respectively), creating a smaller right angled triangle.
If you unfold the paper completely after one operation, you may notice that the crease made is inwards. We define this as a valley. Multiple operations may also lead to the formation of an outwards crease, which is defined as a mountain.
Let M be the total length of all mountains and V be the total length of all valleys after 319587138362 such operations. Consider the simple reduced fraction \frac{p}{q} to be the ratio of M and V.
Return 3\cdot p\ +\ 2\cdot q\ modulo 1,000,000,007.