Explanation:
5 people.
how many ways can they line up in general ?
5 choices for the 1st position, then no matter what we picked, 4 remaining for the second, then 3 for the 3rd, 2 for the 4th and 1 for the 5th :
5×4×3×2×1 = 5! = 120 ways.
but we have restrictions. we don't want the girls not just anywhere in the line, we want them to be at the end points of the line.
and none of the boys should ever be at one of the ends.
so, we actually have only
2×1 for the endpoints and 3×2×1 for the 3 boy positions in the middle.
in total
2×1×3×2×1 = 12
under these constrictions they have actually only 12 different ways to line up.