<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:
    def flipLights(self, n: int, presses: int) -> int:
        if presses == 0:
            return 1
        init = 0
        hs = set()
        final = set()
        hs.add((init,0))
        mask1 = 0
        for i in range(0, n):
            mask1 += 1 << i
        mask2 = 0
        for i in range(1, n, 2):
            mask2 += 1 << i
        mask3 = 0
        for i in range(0, n, 2):
            mask3 += 1 << i
        mask4 = 0
        for i in range(0, n, 3):
            mask4 += 1 << i
        self.mask1 = mask1
        self.mask2 = mask2
        self.mask3 = mask3
        self.mask4 = mask4
        def dfs(cur, p):
            if p == presses:
                return
            
            # b1
            b1 = cur
            b1 ^= self.mask1
            if (b1, p) not in hs:
                hs.add((b1, p))
                dfs(b1, p+1)
            # b2
            b2 = cur
            b2 ^= self.mask2
            if (b2, p) not in hs:
                hs.add((b2, p))
                dfs(b2, p+1)
            # b3
            b3 = cur
            b3 ^= self.mask3
            if (b3, p) not in hs:
                hs.add((b3, p))
                dfs(b3, p+1)
            # b4
            b4 = cur
            b4 ^= self.mask4
            if (b4, p) not in hs:
                hs.add((b4, p))
                dfs(b4, p+1)

            if p + 1 == presses:
                final.add(b1)
                final.add(b2)
                final.add(b3)
                final.add(b4)
        dfs(init, 0)
        print(final)
        return len(final)


29100