Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hints: AND-array

$f(a)_1$ is the sum of all $a_i$. For $k \ge 2$, $f(a)_k$ sums $\operatorname{AND}$ over all $k$-subsets of positions. If you think bit by bit, what simple inequality relates $\operatorname{AND}$ of many numbers to their individual bits?
Answer to Hint 1: Bitwise AND only clears bits; it never sets a bit unless every chosen number has that bit. So contributions are nested: the top-level structure is often easier to recover from large $k$ downward.

Answer to Hint 2: Try $n=3$. Write $f_1, f_2, f_3$ in terms of $a_1,a_2,a_3$. How many times does a single $a_i$ appear in $f_1$ versus in $f_2$ and $f_3$?

For general $n$, how does the binomial coefficient $\binom{n}{k}$ enter if you imagine expanding sums of ANDs by inclusion–exclusion on which subset size you peel off first?

Answer to Hint 3: There is a triangular relationship: the quantities $b_1, \ldots, b_n$ (given modulo $10^9+7$) determine $a$ uniquely if you process from $k=n$ down to $1$. At step $k$, if $b_k \neq 0$, interpret $b_k$ as a homogeneous contribution shared by the first $k$ entries of $a$, then subtract its induced effect from all lower $b_q$ using $\binom{k}{q}$.

This is Möbius/inclusion style inversion on the subset-AND sums.

Answer to Hint 4: Algorithm sketch (mod $10^9+7$): initialize $a \leftarrow 0$. For $i$ from $n$ down to $1$, if $b_i \neq 0$, add $b_i$ to each of $a_1, \ldots, a_i$ (conceptually), then for all $q \le i$ update $b_q \leftarrow b_q - \binom{i}{q} b_i$.

Precompute factorials and inverse factorials modulo the prime for binomial coefficients.

Answer to Hint 5: All arithmetic stays in modular field; the statement guarantees a valid integer $a$ exists. The backward elimination recovers it without guessing bits explicitly.