When a person is on an escalator, he can move in either one of the two ways.
If they are moving with the escalator, there will be fewer steps to climb than the total (Same direction= less steps)
If they are moving against the escalator, there will be more steps to climb than the total (Opposite directions = more steps)
Let us suppose that an escalator has a total of L stairs , and it churns out E stairs/second(moves at this speed). We consider a person who can climb P stairs/second.
When the person is moving on the escalator, he will move certain steps on his own, while the escalator moves.
Let us assume he climbs D stairs on his own. The time taken to do this would be $$\frac{D}{P}$$ seconds. In this time, the escalator will churn out $$\frac{D}{P}\times E$$ stairs.
So, the total number of steps when the person is
(A) Moving With the Escalator = steps climbed oneself + steps produced by escalator OR $$L=D+\frac{D}{P}\times E$$
(B) Moving Against the Escalator = steps climbed oneself – steps produced by escalator OR $$L=D-\frac{D}{P}\times E$$