<p>Given two integers <code>a</code> and <code>b</code>, return <strong>any</strong> string <code>s</code> such that:</p>

<ul>
	<li><code>s</code> has length <code>a + b</code> and contains exactly <code>a</code> <code>&#39;a&#39;</code> letters, and exactly <code>b</code> <code>&#39;b&#39;</code> letters,</li>
	<li>The substring <code>&#39;aaa&#39;</code> does not occur in <code>s</code>, and</li>
	<li>The substring <code>&#39;bbb&#39;</code> does not occur in <code>s</code>.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> a = 1, b = 2
<strong>Output:</strong> &quot;abb&quot;
<strong>Explanation:</strong> &quot;abb&quot;, &quot;bab&quot; and &quot;bba&quot; are all correct answers.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> a = 4, b = 1
<strong>Output:</strong> &quot;aabaa&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= a, b &lt;= 100</code></li>
	<li>It is guaranteed such an <code>s</code> exists for the given <code>a</code> and <code>b</code>.</li>
</ul>

class Solution {
public:
    string strWithout3a3b(int a, int b) {
        priority_queue<pair<int,char>>pq;
        if((a==0 and b>2)|| (b==0 and a>2)) return "";
        if(a>0) pq.push({a,'a'});
        if(b>0) pq.push({b,'b'});

        string ans="";
        while(!pq.empty()){
            pair<int,char>p1=pq.top();
            pq.pop();

            char c1=p1.second;
            int f1=p1.first;
            int length=ans.size();

            if(length>=2 and ans[length-1]==c1 and ans[length-2]==c1){
                pair<int,char> p2=pq.top();
                pq.pop();

                char c2=p2.second;
                int  f2=p2.first;
                ans+=c2;
                f2--;
                if(f2>0) pq.push({f2,c2});
                pq.push({f1,c1});

            }
            else{
                ans+=c1;
                f1--;
                if(f1>0) pq.push({f1,c1});
            }
        }

        return ans;
    }
};
8300