This is ultimately a n^3 for-loop. However, somehow I feel it's more natural/readable to write it as:

```
for mask in cookies:
    for c1 in cookies:
        for c2 in cookies:
            ...
```

Also is there some shortcut that you can take if c1 == c2? It probably won't affect running time all that much.