/* -*- coding: utf-8 -*- * * 1694.cc: No.1694 ZerOne - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 60; const int BN = 16; const int BBITS = 1 << BN; const int BMSK = BBITS - 1; /* typedef */ typedef long long ll; typedef queue ql; typedef set sl; /* global variables */ char s[MAX_N + 4]; int bnums[BBITS]; ll msks[MAX_N + 1]; sl as; /* subroutines */ inline ll getbits(ll bits, int i, int l) { return (bits >> i) & msks[l]; } inline int cntbits(ll bits) { return bnums[bits & BMSK] + bnums[(bits >> BN) & BMSK] + bnums[(bits >> (BN * 2)) & BMSK] + bnums[(bits >> (BN * 3)) & BMSK]; } /* main */ int main() { bnums[0] = 0; for (int bits = 1, msb = 1; bits < BBITS; bits++) { if ((msb << 1) <= bits) msb <<= 1; bnums[bits] = bnums[bits ^ msb] + 1; } scanf("%s", s); int n = strlen(s), hn = n / 2; ll st = 0; for (int i = 0; i < n; i++) { int si = s[i] - '0'; msks[i + 1] = ((1LL << (i + 1)) - 1); st |= ((ll)si << i); } //printf("n=%d, st=0x%llx\n", n, st); as.insert(st); ql q; q.push(st); while (! q.empty()) { ll u = q.front(); q.pop(); for (int l = 1; l <= hn; l++) for (int i = 0; i + 2 * l <= n; i++) { ll bitsi = getbits(u, i, l); int ci = cntbits(bitsi); for (int j = i + l; j + l <= n; j++) { ll bitsj = getbits(u, j, l); int cj = cntbits(bitsj); if (bitsi != bitsj && ci == cj) { ll v = (u & ~(msks[l] << i) & ~(msks[l] << j)) | (bitsi << j) | (bitsj << i); //printf("u=0x%llx, l=%d i=%d,0x%llx,%d j=%d,0x%llx,%d -> v=0x%llx\n", //u, l, i, bitsi, ci, j, bitsj, cj, v); if (! as.count(v)) { as.insert(v); q.push(v); } } } } } printf("%lu\n", as.size()); //for (auto u: as) printf(" 0x%llx\n", u); return 0; }