A lambda is a function written where it is used: [capture](parameters) { body }. The capture list says which outside variables the body can see, and how:
[fee] copies fee when the lambda is created. Later changes to the original do not reach the copy.
[&total] refers to total itself, so the lambda can change it. The variable must still exist when the lambda runs.
[n = 0] creates a new variable that belongs to the lambda. Add mutable to let the body change its by-value variables.
A lambda that outlives the function that made it, because it is returned or stored for later, must capture by value: a reference to a local would point at memory that is gone. Keep a lambda in auto, or in std::function<long long(long long)> (from <functional>) when you need to name its type, for example as a return type.
Capture by value to return a lambda; capture by reference to update a variable in place.