INVYCNT October Lunchtime Help

This is one of my friend’s accepted solution which gives the answer of above test case as 90.
https://www.codechef.com/viewsolution/27589557
Please look into the case.

Here is my solution, i am getting wrong answer.
Please help me to know where i’m wrong?
https://www.codechef.com/viewsolution/27582475

A brute force solution will work here easily.
In this, we maintain the count of the number to the left and to the right which are greater then a[i] for each i
for lefts we will have a
left * (k-1 + k-2 + k-3 + … + 1) series
for rights we will have a
right * (k + k-1 + k-2 + k-3 + … + 1)

Solution