Let's study Neil numbers Congratulations to Neil for hitting 100k rep! As a tribute, we are going to study 'Neil numbers'.

Neil's user ID is 17602 and there's something special about the binary representation of this number:

$$17602_{10}=1\color{blue}{000}1\color{blue}{00}11\color{blue}{0000}1\color{blue}{0}_2$$

$$\begin{array}{c|c}
1&amp;\color{blue}{000}&amp;1&amp;\color{blue}{00}&amp;11&amp;\color{blue}{0000}&amp;1&amp;\color{blue}{0}\\
\hline
&amp;3&amp;&amp;2&amp;&amp;4&amp;&amp;1
\end{array}$$

There's exactly one group of consecutive zeros of length 1, one group of length 2, one group of length 3 and one group of length 4.

This is an order-4 Neil number.

More generally:


  An order-\$n\$ Neil number is a positive integer whose binary
  representation contains exactly \$n\$ groups of consecutive zeros and
  for which there's exactly one group of consecutive zeros of length
  \$k\$ for each \$0&lt;k\le n\$, with \$n&gt;0\$.


Clarifications:


Leading zeros are obviously ignored.
Groups of consecutive zeros are indivisible (e.g. 000 is a group of length 3 and cannot be seen as a group of length 1 followed by a group of length 2, or the other way around).


Examples

Order-1 Neil numbers are A030130 (except 0, which is not a Neil number as per our definition).

The first few order-2 Neil numbers are:

18, 20, 37, 38, 41, 44, 50, 52, 75, 77, 78, 83, 89, 92, 101, 102, 105, 108, 114, ...


Your task

Given a positive integer as input, return \$n\ge 1\$ if this is an order-\$n\$ Neil number or another consistent and non-ambiguous value (0, -1, false, "foo", etc.) if this is not a Neil number at all.

This is code-golf.

Test cases

Using 0 for non-Neil numbers:

Input   Output
1       0
2       1
8       0
72      0
84      0
163     0
420     0
495     1
600     3
999     0
1001    2
4095    0
8466    4
16382   1
17602   4
532770  5


Or as lists:

Input : 1, 2, 8, 72, 84, 163, 420, 495, 600, 999, 1001, 4095, 8466, 16382, 17602, 532770
Output: 0, 1, 0, 0, 0, 0, 0, 1, 3, 0, 2, 0, 4, 1, 4, 5


Brownie points if your user ID is a Neil number. :-)
Charcoal, 21 bytes

≔Φ⪪⍘Ｎ²1ιθＩ×Ｌθ⬤θ№θ×0⊕κ


Try it online! Link is to verbose version of code. Outputs 0 for irrelevant numbers. Happens to output 1 for 0 as per the OEIS sequence. Explanation:

≔Φ⪪⍘Ｎ²1ιθ


Convert the input to binary, split on 1s, and remove empty elements.

Ｉ×Ｌθ⬤θ№θ×0⊕κ


Check that the array contains all lengths of 0s and output its length if it does or 0 if it does not.