Find the density of the median of the three variables? (P exam) 

*Three random variables $X_1,X_2,$ and $X_3$ have density $3x^{2}$ for $0<x<1$. If the variables are i.i.d, find the density of the median of the three variables.

Can someone give a dumbed down explanation because I can't understand the solution to this problem.
I think we want the median of $X_1,X_2$ and $X_3$
This is the solution that I don't understand:
\begin{align}
P(\text{med} \le x) = P(\text{at least }2 \le x)&=P(\text{exactly }2\le x)+P(\text{all }3\le x)
\\&=3(x^{3})^{2}(1-x^{3})+(x^{3})^{3} 
\\&= 3x^{6}−2x^{9}
\end{align}
$$\frac{dF}{dx}=18x^{5}-18x^{8}$$
Use this solution or don't. I just want to understand how to solve this problem.
 A: Let $M$ be the median of $X_1, X_2, X_3$.  Let $x$ be some fixed number between $0$ and $1$.  Then consider the event that $M \le x$; that is, the median is at most $x$.  This can happen if all three of $X_1, X_2, X_3$ are less than or equal to $x$ (so the median must also be less than or equal to $x$); or, if exactly two of $X_1, X_2, X_3$ are less than or equal to $x$.
Alternatively, observe that if only one of $X_1, X_2, X_3$ is less than or equal to $x$, then the other two are greater than $x$, hence the median $M$ is also greater than $x$.  And if none of $X_1, X_2, X_3$ is less than or equal to $x$, then obviously $M > x$.
So $$\Pr[M \le x] = \Pr[\text{exactly 2 of } X_1, X_2, X_3 \le x] + \Pr[\text{all } X_1, X_2, X_3 \le x]$$ because these events are disjoint.
Next, consider how we can compute these probabilities.  The second term is easy:  if all three of the $X_1, X_2, X_3$ are at most $x$, and each $X_i$ is iid, then $$\Pr[\text{all } X_1, X_2, X_3 \le x] \overset{\text{ind}}{=} \Pr[X_1 \le x]\Pr[X_2 \le x]\Pr[X_3 \le x].$$  And we are told that the density is $3x^2$, so $$\Pr[X_1 \le x] = \Pr[X_2 \le x] = \Pr[X_3 \le x] = \int_{t=0}^x 3t^2 \, dt = x^3.$$
For the first probability, there are $3$ ways that exactly two of the $X_i$s can be at most $x$:  either $X_1, X_2$, or $X_2, X_3$, or $X_3, X_1$, are the two that are at most $x$ and the third is greater than $x$.  But since the $X_i$ are iid, we see that $$\Pr[\text{exactly 2 of } X_1, X_2, X_3 \le x] = 3 \Pr[X_1 \le x]\Pr[X_2 \le x]\Pr[X_3 > x].$$  Of course, technically we should have written as an intermediate step
$$\begin{align}
\Pr[\text{exactly 2 of } X_1, X_2, X_3 \le x] 
&= \Pr[X_1 \le x]\Pr[X_2 \le x]\Pr[X_3 > x] \\
&\quad + \Pr[X_2 \le x]\Pr[X_3 \le x]\Pr[X_1 > x] \\
&\quad + \Pr[X_3 \le x]\Pr[X_1 \le x]\Pr[X_2 > x].
\end{align}$$
And the fact that the $X_i$ are iid lets us simplify this.  So this part of the probability is
$$\Pr[\text{exactly 2 of } X_1, X_2, X_3 \le x] = 3(x^3)(x^3)(1 - x^3).$$
Now put all of this together:
$$\Pr[M \le x] = 3x^6(1-x^3) + (x^3)(x^3)(x^3) = 3x^6 - 2x^9.$$  Then the density is $$f_M(x) = \frac{d}{dx}\left[3x^6 - 2x^9\right] = 18x^5 - 18 x^8.$$
I realize this answer is quite long, but you requested a complete explanation.  Normally, much of this reasoning would be omitted.
