Clean Python
The idea is the outer-loop is always going to be the middle element. a, b, searches left of the middle, c and d searches the right of the middle. \n\nresult += 
The idea is the outer-loop is *always* going to be the middle element. `a`, `b`, searches *left* of the middle, `c` and `d` searches the *right* of the middle. \n\n`result += a*d + b*c` is just some math. I\'m pretty terrible at math.\n\nOriginal solution: @rmoskalenko\n\n```python\ndef numTeams(rating):\n\n    result = 0\n\n    for idx, middle in enumerate(rating):\n        a = sum(left < middle for jdx, left in enumerate(rating[:idx]))\n        b = sum(left > middle for jdx, left in enumerate(rating[:idx]))           \n        c = sum(right < middle for jdx, right in enumerate(rating[idx+1:]))\n        d = sum(middle < right for jdx, right in enumerate(rating[idx+1:]))\n        result += a*d + b*c\n\n    return result\n```
['Python', 'Python3']