------
## 最终结论
```python
from collections import Counter

def balancedString(s: str) -> int:
    n = len(s)
    count = Counter(s)
    target = n // 4
    min_len = n
    left = 0

    for right in range(n):
        count[s[right]] -= 1
        
        while left < n and all(count[char] <= target for char in 'QWER'):
            min_len = min(min_len, right - left + 1)
            count[s[left]] += 1
            left += 1

    return min_len
```