БАРА БАРА
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```\n#include <iostream>\n#include <vector>\n#include <set>\n\nusing namespace std;\n\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& nums) {\n        int n = nums.size();\n        int totalDisbalance = 0;\n\n        // \u041F\u0440\u043E\u0445\u043E\u0434\u0438\u043C \u043F\u043E \u0432\u0441\u0435\u043C \u0432\u043E\u0437\u043C\u043E\u0436\u043D\u044B\u043C \u043D\u0430\u0447\u0430\u043B\u044C\u043D\u044B\u043C \u0442\u043E\u0447\u043A\u0430\u043C \u043F\u043E\u0434\u043C\u0430\u0441\u0441\u0438\u0432\u043E\u0432\n        for (int i = 0; i < n; ++i) {\n            set<int> seen;\n            int currentDisbalance = 0;\n            \n            // \u0421\u0442\u0440\u043E\u0438\u043C \u043F\u043E\u0434\u043C\u0430\u0441\u0441\u0438\u0432\u044B, \u043D\u0430\u0447\u0438\u043D\u0430\u044F \u0441 \u0442\u043E\u0447\u043A\u0438 i\n            for (int j = i; j < n; ++j) {\n                int num = nums[j];\n\n                // \u0412\u0441\u0442\u0430\u0432\u043B\u044F\u0435\u043C \u0442\u0435\u043A\u0443\u0449\u0438\u0439 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 \u0432 \u043C\u043D\u043E\u0436\u0435\u0441\u0442\u0432\u043E\n                seen.insert(num);\n\n                // \u041E\u0431\u043D\u043E\u0432\u043B\u044F\u0435\u043C \u0442\u0435\u043A\u0443\u0449\u0435\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u0438\u0441\u0431\u0430\u043B\u0430\u043D\u0441\u0430\n                currentDisbalance = calculateDisbalance(seen);\n\n                // \u0414\u043E\u0431\u0430\u0432\u043B\u044F\u0435\u043C \u0442\u0435\u043A\u0443\u0449\u0435\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u0438\u0441\u0431\u0430\u043B\u0430\u043D\u0441\u0430 \u043A \u043E\u0431\u0449\u0435\u0439 \u0441\u0443\u043C\u043C\u0435\n                totalDisbalance += currentDisbalance;\n            }\n        }\n\n        return totalDisbalance;\n    }\n\nprivate:\n    int calculateDisbalance(const set<int>& seen) {\n        int disbalance = 0;\n        auto it = seen.begin();\n        int prev = *it;\n\n        // \u041F\u0440\u043E\u0445\u043E\u0434\u0438\u043C \u043F\u043E \u043C\u043D\u043E\u0436\u0435\u0441\u0442\u0432\u0443 \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u043C \u043A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E \u043D\u0430\u0440\u0443\u0448\u0435\u043D\u0438\u0439\n        for (++it; it != seen.end(); ++it) {\n            if (*it - prev > 1) {\n                ++disbalance;\n            }\n            prev = *it;\n        }\n        return disbalance;\n    }\n};\n\n```
['C++']