```python
def leg_gain(start: int, end: int) -> int:
    """
    Returns the height gained on one leg: the rise when the ground goes up, and zero
    when it goes down or stays level.
    """
    if start == end:
        return 0
    return start - end

def climb_gain(heights: list) -> int:
    """
    Adds the gains of every leg of a walk, given the heights in order. A walk of fewer
    than two heights gains nothing.
    """
    if len(heights) < 2:
        return 0
    return sum(leg_gain(heights[i], heights[i+1]) for i in range(len(heights)-1))
```