def count_inversion(seq):
i = 1
s = 0
while i < len(seq):
j = i - 1
while seq[i] < seq[j]:
s += 1
i += 1
if i == len(seq):
return s
i += 1
return s
def test():
seq_0 = (1, 2, 5, 3, 4, 7, 6)
seq_1 = (0, 1, 2, 3, 4)
seq_2 = list(reversed(range(10)))
assert count_inversion(seq_0) == 3
assert count_inversion(seq_1) == 0
assert count_inversion(seq_2) == 9
print('ok')
test()
ZGVmIGNvdW50X2ludmVyc2lvbihzZXEpOgogICAgaSA9IDEKICAgIHMgPSAwCgogICAgd2hpbGUgaSA8IGxlbihzZXEpOgogICAgICAgIGogPSBpIC0gMQogICAgICAgIHdoaWxlIHNlcVtpXSA8IHNlcVtqXToKICAgICAgICAgICAgcyArPSAxCiAgICAgICAgICAgIGkgKz0gMQogICAgICAgICAgICBpZiBpID09IGxlbihzZXEpOgogICAgICAgICAgICAgICAgcmV0dXJuIHMKICAgICAgICBpICs9IDEKCiAgICByZXR1cm4gcwoKCmRlZiB0ZXN0KCk6CiAgICBzZXFfMCA9ICgxLCAyLCA1LCAzLCA0LCA3LCA2KQogICAgc2VxXzEgPSAoMCwgMSwgMiwgMywgNCkKICAgIHNlcV8yID0gbGlzdChyZXZlcnNlZChyYW5nZSgxMCkpKQogICAgYXNzZXJ0IGNvdW50X2ludmVyc2lvbihzZXFfMCkgPT0gMwogICAgYXNzZXJ0IGNvdW50X2ludmVyc2lvbihzZXFfMSkgPT0gMAogICAgYXNzZXJ0IGNvdW50X2ludmVyc2lvbihzZXFfMikgPT0gOQogICAgcHJpbnQoJ29rJykKCgp0ZXN0KCkK