------
## 最终结论
```python
def generate_string(A, B):
    S = ""
    count_a = 0
    count_b = 0
    
    while len(S) < A + B:
        if (A > 0 and (count_a < 2 or count_b == 0)) and (B == 0 or count_a < 2):
            S += 'a'
            A -= 1
            count_a += 1
            count_b = 0
        elif (B > 0 and (count_b < 2 or count_a == 0)) and (A == 0 or count_b < 2):
            S += 'b'
            B -= 1
            count_b += 1
            count_a = 0
            
    return S
```