Help in December Circuits[Hackerearth]

Hello everyone,

Can someone help me how to approach this problem?

Thanks in advance

find number of inversions of an array by making 0 or 1 swaps

  1. count total inversions
  2. then choose all pairs of indices such that i<j and a[i]>a[j]
  3. if you swap them, inversion count=old-1-2*(number of indices k in (i,j) such that a[j]<a[k]<a[i])
  4. find the minimum value over all pairs, that’s your answer

hard(very) version

help me in mine question too.