C++ || EASY CLEAN CODE || MULTISET
\n\n# Code\n\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& a) {\n        int s=0;\n        for(int i=0;i<a.size();i++)\n        {\n      
\n\n# Code\n```\nclass Solution {\npublic:\n    int sumImbalanceNumbers(vector<int>& a) {\n        int s=0;\n        for(int i=0;i<a.size();i++)\n        {\n            multiset<int> p;\n            int c=0;\n            for(int j=i;j<a.size();j++)\n            {\n                p.insert(a[j]);\n                auto it=p.find(a[j]);\n                auto x=std::next(it,1);\n                auto y=std::prev(it,1);\n\n                if(x!=p.end() && *x==a[j])\n                {\n                    s+=c;continue;\n                }\n                if(y!=p.end() && *y==a[j])\n                {\n                    s+=c;continue;\n                }\n                if(x!=p.end() && y!=p.end() && *x-*y>1) c--;\n\n                if(x!=p.end() && *x-a[j]>1)\n                 c++;\n                if(y!=p.end() && a[j]-*y>1)\n                 c++;\n\\\n                s+=c;\n            }\n        }\n    return s;\n    }\n};\n```
['C++']