Originally Posted by

**Soroban** Hello, jarny!

I have a rather primitive approach.

Maybe someone has a more elegant solution.

The color distribution could be 3-1-1. .(Three of one color, one each of the others.)

. . There are $\displaystyle 3$ ways this could be done: RRRBY, RBBBY, RBYYY.

Once the colors are chosen, the trains can be painted in: .$\displaystyle \binom{5}{3,1,1} = 20$ ways.

Hence, there are: $\displaystyle 3 \times 20 \,=\,60$ ways to have 3-1-1.

The color distribution could be 2-2-1. .(Two each of two colors, one of the third.)

. . There are $\displaystyle 3$ ways this could be done: RRBBY, RRBYY, RBBYY.

Once the colors are chosen, the trains can be painted in: .$\displaystyle \binom{5}{2,2,1} = 30$ ways.

Hence, there are: $\displaystyle 3 \times 30 \,=\,90$ ways to have 2-2-1.

Therefore, there are: .$\displaystyle 60 + 90\,=\,150$ ways to paint the trains.