a.
The answer is 22n−1−21(n2n).
A subset T of S is called a bad subset if in T the number of odd elements is greater than the number of even elements. A subset of S is neither good nor bad if it has exactly k odd elements and k even elements for some k=0,1,…,n. Since there are n odd elements and n even elements in S, the number of subsets which are neither good nor bad is
k=0∑n(kn)2=(n2n)
by Vandermonde's identity.
Now, by symmetry, the number of good subsets is the same as the number of bad subsets. As there are 22n subsets of S in total, the total number of good subsets is
21[22n−(n2n)]=22n−1−21(n2n).
b.
The answer is 22n−2(2n2+n)−n2(n2n−1).
We first count the number N1 of good subsets containing a particular even number. Suppose such a good subset contains i more even numbers and j odd numbers. Then we need i≥j. As there are n−1 even numbers remaining and n odd numbers in total, we have
N1=i=0∑n−1j=0∑i(in−1)(jn)=i=0∑n−1k=n−i∑n(in−1)(kn)=i+k≥n∑(in−1)(kn)
by using the change of variable k=n−j. Note that this is equal to the sum of coefficients of all xm with m≥n in (1+x)n−1(1+x)n=(1+x)2n−1. Thus, we obtain
N1=m=n∑2n−1(m2n−1)=21m=0∑2n−1(m2n−1)=22n−2.
Similarly, we count the number N2 of good subsets containing a particular odd number. Suppose such a good subset contains i≥2 even numbers and j more odd numbers. Then we need i≥j+2. This implies
N2=i=2∑nj=0∑i−2(in)(jn−1)=i=2∑nk=n+1−i∑n−1(in)(kn−1)=i+k≥n+1∑(in)(kn−1)=m=n+1∑2n−1(m2n−1)=21(m=0∑2n−1(m2n−1)−(n−12n−1)−(n2n−1))=22n−2−(n2n−1).
Now, the sum of all the elements in all the good subsets of S is
N1(2+4+⋯+2n)+N2(1+3+⋯+(2n−1))=22n−2⋅n(n+1)+[22n−2−(n2n−1)]⋅n2=22n−2(2n2+n)−n2(n2n−1).