Let us divide this problem into two parts:
1) Sam rides up the mountain.
2) Sam rides down the mountain.
1.
Since speed is distance over time, as:

Therefore, distance would be:

Where s = distance,
v = speed,
t = time.
In the problem, Sam's speed while riding up is v = 6 miles/hour = (6 * 1609.34 / 60) = 160.934 meters/second(in SI Units). Plug this value in the above equation, you would get:

--- (A)
2.
As Sam rides down the mountain, the speed given is:

Convert it in SI units; the speed would be in SI unit:
v = 54
miles/hour = (54 * 1609.34 / 60) = 1448.406 meters/second(in SI Units). Plug this value in the distance equation, you would get:

Since the

, therefore,

=> 
Now the condition is that the whole trip, up and down, takes 40 minutes(2400seconds), it means:

Plug in the value of

in the above equation, you would get:

Therefore,


meters (in relation to seconds)

meters (in relation to hours)
Now the last step is to convert meters into miles, you would get:

So the answer is
3.6miles.