TRIP-problem

Could somebody please explain me the trip editorial.How to calculate the number of ways?

//