Help me understand the logic please