Just Brute Force in 29 lines
\n# Code\npython3 []\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        result = 0\n        cc = collections.Counter()\n        for nu
\n# Code\n```python3 []\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        result = 0\n        cc = collections.Counter()\n        for num in nums:\n            result += cc[num]\n\n            # change\n            num_str = str(num)\n            num_str = (7 - len(num_str)) * \'0\' + num_str\n\n            s = set()\n            s.add(num)\n            for i1, j1 in itertools.combinations(range(len(num_str)), 2):\n                for i2, j2 in itertools.combinations(range(len(num_str)), 2):\n                    tmp = list(num_str)\n                    tmp[i1], tmp[j1] = tmp[j1], tmp[i1]\n                    new_num = int(\'\'.join(tmp))\n                    if new_num not in s and new_num in cc:\n                        result += cc[new_num]\n                        s.add(new_num)\n                    \n                    tmp[i2], tmp[j2] = tmp[j2], tmp[i2]\n                    new_num = int(\'\'.join(tmp))\n                    if new_num not in s and new_num in cc:\n                        result += cc[new_num]\n                        s.add(new_num)\n            cc[num] += 1\n        return result\n```
['Python3']