Combination of pair Indexes.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        nums.sort(  reverse = True)\n\n        def generate_almost_equals( intNum, k = 2):\n            setEquals = {intNum}\n            strNum = str(   intNum)\n            pairIndexes =       list(itertools.combinations(    range(len(strNum)), 2))\n\n            for numPairs in range( 1, k+1):\n                for indexPair in itertools.combinations(    pairIndexes, numPairs):    \n                    s = strNum\n                    for i, j in indexPair:\n                        s = s[:i] + s[j] + s[i+1:j] + s[i] + s[j+1:]\n                    setEquals.add(  int(    s, 10))\n            return setEquals\n        \n        prevSeenNumbers = collections.Counter()\n        totalAlmostEquals = 0\n\n        for num in nums:\n            totalAlmostEquals += prevSeenNumbers[num]\n            prevSeenNumbers +=  collections.Counter(    generate_almost_equals( num))\n            \n        return totalAlmostEquals\n```
['Python3']