------
## 最终结论
```python
def bag_of_tokens_score(tokens, P):
    tokens.sort()
    left, right = 0, len(tokens) - 1
    points = 0
    max_points = 0
    
    while left <= right:
        if P >= tokens[left]:
            P -= tokens[left]
            points += 1
            max_points = max(max_points, points)
            left += 1
        elif points > 0:
            P += tokens[right]
            points -= 1
            right -= 1
        else:
            break
    
    return max_points

# Example usage:
print(bag_of_tokens_score([100], 50)) # Output: 0
print(bag_of_tokens_score([100,200], 150)) # Output: 1
print(bag_of_tokens_score([100,200,300,400], 200)) # Output: 2
```