javascript bitmask 116ms
\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 
```\nconst bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };\n\nconst maximumGood = (g) => {\n    let n = g.length, res = Number.MIN_SAFE_INTEGER;\n    outer:\n    for(let i = 0; i < 1 << n; i++) {\n        for (let j = 0; j < n; j++) {\n            for (let k = 0; k < n; k++) {\n                if (g[j][k] == 2) continue;\n                if (i & (1 << j)) {\n                    if (i & (1 << k)) {\n                       if (g[j][k] == 0) continue outer;\n                    } else {\n                        if (g[j][k] == 1) continue outer;\n                    }\n                }\n            }\n        }\n        res = Math.max(res, bitCount(i));\n    }\n    return res;\n};\n```\nmodified version\n```\nconst maximumGood = (g) => {\n    let n = g.length, res = Number.MIN_SAFE_INTEGER;\n    for (let i = 0; i < 1 << n; i++) {\n        let ok = true, cnt = 0;\n        for (let j = 0; j < n; j++) {\n            if (i & (1 << j)) {\n                cnt++;\n                for (let k = 0; k < n; k++) {\n                    if (g[j][k] == 2) continue;\n                    if (i & (1 << k)) {\n                        if (g[j][k] == 0) ok = false;\n                    } else {\n                        if (g[j][k] == 1) ok = false;\n                    }\n                    // if (!ok) break;   // add will speed up, not add is also correct\n                }\n            }\n            // if (!ok) break;\n        }\n        if (ok) res = Math.max(res, cnt);\n    }\n    return res;\n};\n```
['Bitmask', 'JavaScript']