#
from itertools import tee, islice, groupby
def inversions(it):
a, b = tee(it)
return sum(1 for _ in islice(
groupby(x >= y for x, y in zip(a, islice(b, 1, None))), 1, None
))
print( *map(inversions, ((1, 2, 5, 3, 4, 7, 6),
(0, 1, 2, 3),
(4, 3, 2, 1, 0, 1)
)),
sep='\n'
)
Iwpmcm9tIGl0ZXJ0b29scyBpbXBvcnQgdGVlLCBpc2xpY2UsIGdyb3VwYnkKCmRlZiBpbnZlcnNpb25zKGl0KToKCWEsIGIgPSB0ZWUoaXQpCglyZXR1cm4gc3VtKDEgZm9yIF8gaW4gaXNsaWNlKAoJCWdyb3VwYnkoeCA+PSB5IGZvciB4LCB5IGluIHppcChhLCBpc2xpY2UoYiwgMSwgTm9uZSkpKSwgMSwgTm9uZQoJKSkKCnByaW50KCAqbWFwKGludmVyc2lvbnMsICgoMSwgMiwgNSwgMywgNCwgNywgNiksCgkJCQkJCSAoMCwgMSwgMiwgMyksCgkJCQkJCSAoNCwgMywgMiwgMSwgMCwgMSkKCQkJCQkJICkpLAoJCXNlcD0nXG4nCikK