------
## 最终结论
```python
def maxScore(cardPoints, k):
    n = len(cardPoints)
    total = sum(cardPoints)
    
    # If k equals the length of cardPoints, return the total
    if k == n:
        return total
    
    # Calculate the minimum sum of the (n - k) cards that are not taken
    min_sum = float('inf')
    current_sum = 0
    
    # Calculate the sum of the first (n - k) cards
    for i in range(n - k):
        current_sum += cardPoints[i]
    
    min_sum = current_sum
    
    # Sliding window to find the minimum sum of (n - k) cards
    for i in range(n - k, n):
        current_sum += cardPoints[i]  # Add the next card from the right
        current_sum -= cardPoints[i - (n - k)]  # Remove the leftmost card from the window
        min_sum = min(min_sum, current_sum)
    
    return total - min_sum

# Example usage:
print(maxScore([1,2,3,4,5,6,1], 3))  # Output: 12
print(maxScore([2,2,2], 2))            # Output: 4
print(maxScore([9,7,7,9,7,7,9], 7))   # Output: 55
print(maxScore([1,1000,1], 1))         # Output: 1
print(maxScore([1,79,80,1,1,1,200,1], 3))  # Output: 202
```