Suppose P is a set containing n distinct elements. Let S={(x,y,z)∣x,y,z,∈,P and at least two of x,y,z are equal }.
The number of elements in S is
n(3n−2)
n2(n−2)
n3-nC3
n(5n−4)
We can choose x,y,z in n3 way out of which nP3 have distinct elements.