Getting TLE in Insertion Sort Advanced Analysis(Hackerrank)

I was solving Insertion Sort Advanced Analysis. I tried two methods, 1st one is using Binary Indexed Tree and 2nd one is using Ordered Set but getting TLE in both the cases. Can anyone optimise one of this solution.