<p>There is a room with <code>n</code> bulbs labeled from <code>1</code> to <code>n</code> that all are turned on initially, and <strong>four buttons</strong> on the wall. Each of the four buttons has a different functionality where:</p>

<ul>
	<li><strong>Button 1:</strong> Flips the status of all the bulbs.</li>
	<li><strong>Button 2:</strong> Flips the status of all the bulbs with even labels (i.e., <code>2, 4, ...</code>).</li>
	<li><strong>Button 3:</strong> Flips the status of all the bulbs with odd labels (i.e., <code>1, 3, ...</code>).</li>
	<li><strong>Button 4:</strong> Flips the status of all the bulbs with a label <code>j = 3k + 1</code> where <code>k = 0, 1, 2, ...</code> (i.e., <code>1, 4, 7, 10, ...</code>).</li>
</ul>

<p>You must make <strong>exactly</strong> <code>presses</code> button presses in total. For each press, you may pick <strong>any</strong> of the four buttons to press.</p>

<p>Given the two integers <code>n</code> and <code>presses</code>, return <em>the number of <strong>different possible statuses</strong> after performing all </em><code>presses</code><em> button presses</em>.</p>

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

<pre>
<strong>Input:</strong> n = 1, presses = 1
<strong>Output:</strong> 2
<strong>Explanation:</strong> Status can be:
- [off] by pressing button 1
- [on] by pressing button 2
</pre>

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

<pre>
<strong>Input:</strong> n = 2, presses = 1
<strong>Output:</strong> 3
<strong>Explanation:</strong> Status can be:
- [off, off] by pressing button 1
- [on, off] by pressing button 2
- [off, on] by pressing button 3
</pre>

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

<pre>
<strong>Input:</strong> n = 3, presses = 1
<strong>Output:</strong> 4
<strong>Explanation:</strong> Status can be:
- [off, off, off] by pressing button 1
- [off, on, off] by pressing button 2
- [on, off, on] by pressing button 3
- [off, on, on] by pressing button 4
</pre>

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

<ul>
	<li><code>1 &lt;= n &lt;= 1000</code></li>
	<li><code>0 &lt;= presses &lt;= 1000</code></li>
</ul>

class Solution {
public:
    int flipLights(int n, int presses) {
        // 2 + 3 = 1
        // order doesnt matter
        // anything done twice is equal to nil
        // edge cases on small n

        // table:
        // 1: 0, 1
        // 2: 0, 1
        // 3: 0, 1
        // 4: 0, 1

        /* potentially distinct combinations are:
        0 0 0 0 = 2 0 0 0 = 1 1 1 0 -> 2k + 3 -> anything but 1
        1 0 0 0 = 0 1 1 0 -> 1 + 2k or 2 + 2k -> anything but 0
        0 1 0 0 = 1 0 1 0 -> anything but 0
        0 0 1 0 = 1 1 0 0 -> anything but 0
        0 0 0 1 = 1 1 1 1 -> 1 + 2k or 4 + 2k -> anything but 0 and 2
        1 0 0 1 = 0 1 1 1 -> 2 + 2k or 3 + 2k -> anything but 0 and 1
        0 1 0 1 = 1 0 1 1 -> anything but 0 and 1
        0 0 1 1 = 1 1 0 1 -> anything but 0 and 1
        */
        if(presses == 0) {
            return 1;
        }

        vector<vector<bool>> combs(8, vector<bool>(n));
        fill(combs[0].begin(), combs[0].end(), false);
        fill(combs[1].begin(), combs[1].end(), true);
        fill(combs[2].begin(), combs[2].end(), false);
        fill(combs[3].begin(), combs[3].end(), false);
        fill(combs[4].begin(), combs[4].end(), false);
        fill(combs[5].begin(), combs[5].end(), true);
        fill(combs[6].begin(), combs[6].end(), false);
        fill(combs[7].begin(), combs[7].end(), false);

        for(int i = 0; i < n; i++) {
            // if i+1 is even, corresponds to 0 1 0 0
            if(i % 2) {
                combs[2][i] = !combs[2][i];
                combs[6][i] = !combs[6][i];
            }
            else {
                combs[3][i] = !combs[3][i];
                combs[7][i] = !combs[7][i];
            }
            // if i = 3k + 1
            if(i % 3 == 0) {
                combs[4][i] = !combs[4][i];
                combs[5][i] = !combs[5][i];
                combs[6][i] = !combs[6][i];
                combs[7][i] = !combs[7][i];
            }
        }

        set<vector<bool>> distinct;
        distinct.insert(combs[1]);
        distinct.insert(combs[2]);
        distinct.insert(combs[3]);
        if(presses != 1) {
            distinct.insert(combs[0]);
            distinct.insert(combs[5]);
            distinct.insert(combs[6]);
            distinct.insert(combs[7]);
        }
        if(presses != 2) {
            distinct.insert(combs[4]);
        }

        return distinct.size();
    }
};
8500