Long time no see

0

0 votes
Medium
Problem

There are N houses on a street, indexed from 1 to N. In the ith house lives a person with socializing value Ai. On the ith day, person living in the ith house hosts a party at his house and invite all the people living in jth house such that j < i and Aj > Ai. You have to print total distance traveled by all the people on the ith day. Distance between house i and j is equal to |i - j|.

INPUT:
First line contains N.
Next line contains N space separated integers, ith value denoting socializing value of the person living in the ith house.

OUTPUT:
Print N space separated integers, ith value denoting total distance traveled by all the people on the ith day.

Constraints:
1 <= N <= 105
1 <= Ai <= 109

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?