Congruence condition relating number of subgroups in maximal subgroups and number of subgroups in the whole group

Statement
Suppose $$G$$ is a group of prime power order. Suppose $$\mathcal{S}$$ is a collection of subgroups of $$G$$. For any subgroup $$H$$ of $$G$$, denote by $$n(H)$$ the number of subgroups of $$H$$ that are in $$\mathcal{S}$$. Then, if $$G \notin \mathcal{S}$$, we have:

$$n(G) \equiv \sum_{M \max G} n(M) \pmod p$$

If $$G \in \mathcal{S}$$, we have:

$$n(G) \equiv 1 + \sum_{M \max G} n(M) \pmod p$$.

Similar facts

 * Congruence condition relating number of normal subgroups containing minimal normal subgroups and number of normal subgroups in the whole group
 * Congruence condition on number of subgroups of given prime power order

Facts used

 * 1) uses::Equivalence of definitions of maximal subgroup of group of prime power order (specifically, nilpotent implies every maximal subgroup is normal, and prime power order implies nilpotent, so all maximal subgroups are normal in groups of prime power order).
 * 2) uses::Fourth isomorphism theorem
 * 3) uses::Formula for number of maximal subgroups of group of prime power order

Proof
Note that the $$G \in \mathcal{S}$$ case follows directly from the $$G \notin \mathcal{S}$$ case, so we restrict attention to the $$G \notin \mathcal{S}$$ case.

Given: $$G$$ is a group of prime power order. $$\mathcal{S}$$ is a collection of subgroups of $$G$$. For any subgroup $$H$$ of $$G$$, denote by $$n(H)$$ the number of subgroups of $$H$$ that are in $$\mathcal{S}$$. $$G \notin \mathcal{S}$$

To prove: $$n(G) \equiv \sum_{M \max G} n(M) \pmod p$$, where the summation is over maximal subgroups of $$G$$. Note that $$n(G) = |\mathcal{S}|$$.

Proof: