#include #define rep(i,a,b) for(int i=int(a);i> K; N = (1 << K) - 1; vector V(N); V[0] = (N + 1) / 2; rep(i,1,K){ int dif = V[(1 << (i-1)) - 1] / 2; rep(j,0,1 << i){ int ind = (1 << i) + j; int root = ind / 2; V[ind-1] = V[root-1] + (j & 1 ? dif : -dif); } } int ind = 1 << (K-1); int root = ind / 2; swap(V[ind - 1], V[root - 1]); for(auto i:V)cout << i << " "; }