DP with enumeration clean code
\nint countPairs(vector<int>& nums) {\n    const int maxDigits = size(to_string(*ranges::max_element(nums)));\n    vector<string> sNums;\n    for (const auto v 
```\nint countPairs(vector<int>& nums) {\n    const int maxDigits = size(to_string(*ranges::max_element(nums)));\n    vector<string> sNums;\n    for (const auto v : nums) {\n        const auto s = to_string(v);\n        sNums.push_back(string(maxDigits - size(s), \'0\') + s);\n    }\n\n    int ans = 0;\n    unordered_map<string, int> dp;\n    for (auto& s : sNums) {\n        const auto copy = s;\n        unordered_set<string> processed;\n        const auto updateAns = [&]() {\n            if (const auto [_, inserted] = processed.insert(s); inserted) {\n                if (const auto it = dp.find(s); it != end(dp)) {\n                    ans += it->second;\n                }\n            }\n        };\n        updateAns();\n        for (int x1 = 0; x1 < size(s); ++x1) {\n            for (int x2 = 0; x2 < x1; ++x2) {\n                swap(s[x1], s[x2]);\n                updateAns();\n                for (int y1 = 0; y1 < size(s); ++y1) {\n                    for (int y2 = 0; y2 < y1; ++y2) {\n                        swap(s[y1], s[y2]);\n                        updateAns();\n                        swap(s[y1], s[y2]);\n                    }\n                }\n                swap(s[x1], s[x2]);\n            }\n        }\n        ++dp[s];\n    }\n    return ans;\n}\n```
['C++']