vector<int> grayCode(int n) {

if (n == 0) return vector<int>(1, 0);

vector<int> res(1 << n, 0);

res[1] = 1;

int t = 2;

for (int i = 2; i <= n; ++i){

for (int j = 0; j < t; ++j)

res[t + j] = *(res.rend() - t + j) | t;

t = t << 1;

}

return res;

}