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 the first operation, you may notice that the creases made are inwards. We define these creases as valleys. Multiple operations may also lead to the formation of some outwards creases, which are defined as mountains.
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.