import sequtils,bitops template `max=`*(x,y) = x = max(x,y) proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} var S = newSeq[int]() while true: let k = getchar_unlocked() if k < '0': break S &= k.ord - '0'.ord var dp = newSeqWith(1 shl S.len,-1) proc bitDP(s:int,popcnt:int) : int = if dp[s] >= 0 : return dp[s] if popcnt + 3 > S.len : return 0 for a in (not s).countTrailingZeroBits()..