fork download
  1. # your code goes here
  2. t=int(input())
  3. for i in range (t):
  4. a=int(input())
  5. l=list(map(int,input().split()))
  6. c=0
  7. for m in range(a-1):
  8. for n in range(a-1-m):
  9. if(l[n]>l[n+1]):
  10. l[n],l[n+1]=l[n+1],l[n]
  11. c=c+1
  12. print(c)
Success #stdin #stdout 0.02s 9304KB
stdin
4
8
176 -272 -272 -45 269 -327 -945 176 
2
-274 161
7
274 204 -161 481 -606 -767 -351
2
154 -109
stdout
15
0
16
1