Problem link

My Submissions here

My logic-

Use Array to store how many buildings of a particular height exist.

Use formula n*(n-1) to calculate all possible pairs.

Eg-

Let there be 5 buildings of height one. I had already defined an array “height[1000001]={0}” to store number of buildings of a particular height. So, it will store 5 for 1.

Now, say our array is like- 1 1 1 1 1

I can pair 1 at I=0 with 1 at I=1,2,3,4. Similarly I can pair 1 at I=1 with 1 at 1=0,2,3,4.

So I derive the formula- Number of Pairs = n(n-1) (via mathematical induction)

But its giving me WA. Can someone help?