Since every toss is either a head or a tail, Y=n−X, where X∼Bin(n,21). Hence
E[X]=2n,Var(X)=4n,E[X2]=Var(X)+E[X]2=4n+4n2.
By linearity,
E[XY]=E[X(n−X)]=nE[X]−E[X2]=2n2−4n2+n=4n2−n.
E[XY]=4n2−n=4n(n−1)
Alternative. Let Hi and Tj be the indicators that toss i is a head and that toss j is a tail. Then
XY=i,j∑HiTj.
When i=j we have HiTi=0. When i=j the tosses are independent, so E[HiTj]=41. There are n(n−1) ordered pairs with i=j, which gives E[XY]=4n(n−1) again.
Key idea. Since E[X]E[Y]=n2/4, the answer says Cov(X,Y)=−Var(X)=−n/4. This is the price of the constraint X+Y=n.