let us represent stack-life of $i^{th}$ element as S(i). The $i^{th}$ element will be in stack till $(n-i)$ elements are pushed and popped. Plus one more $Y$ for the time interval between the push of $i_{th }$ element and the $i+1^{th}$ element. So,
$S(i) = Y + 2.(n-i)(Y+X) \\= Y + 2.(n-i)Z \\= Y + 2nZ -2iZ$
where $Z = Y+X$
average stack-life will, $A = \Sigma \frac{S(i)}{n}$
$nA = nY + 2.n.n.Z -2.Z.\Sigma i$
$nA = nY + 2.n.n.Z - 2.Z \frac{(n(n+1))}{2}$
$nA = nY + 2.n.n.Z - Z(n.n) - n.Z$
$A = Y + 2.n.Z - (n+1).Z$
$A = Y + (n-1).Z \\= Y +(n-1)(X+Y) \\= n(X+Y) - X$