#include int isquasiperiodic(long long w) { long long tt=0, m=0; for (int l=1;; l++) { m = (m<<1)+1; long long t = w & m; if (t!=tt) { // t starts with a "1" if (t==w) { return 0; } long long r = w; int g=l; for (;g-- && r>=t;) { r >>= 1; if ((r & m)==t) { if (r==t) { return 1; } else { g = l; } } } tt = t; } } } int a(int n) { int v = 0; for (long long w=1ll<<(n-1); w<(1ll<