C++
\nusing LL = long long;\nLL M = 1e9+7;\nclass Solution {\n    int count0 = 0;\n    vector<pair<int, int>>arr;\npublic:\n    int countSubMultisets(vector<int>& n
```\nusing LL = long long;\nLL M = 1e9+7;\nclass Solution {\n    int count0 = 0;\n    vector<pair<int, int>>arr;\npublic:\n    int countSubMultisets(vector<int>& nums, int l, int r) {\n        unordered_map<int, int>Map;\n        for(auto x : nums){\n            if(x == 0)\n                count0++;\n            else\n                Map[x]++;\n        }\n\n        for(auto& [key, count] : Map)\n            arr.push_back({key, count}) ;\n        arr.insert(arr.begin(), {0, 0});\n        return (helper(r) - helper(l-1) + M) % M ;\n    }\n    \n    LL helper(int capability){\n        if(capability < 0 )\n            return 0 ;\n        int m = arr.size() ;\n        if(m == 1)\n            return count0 + 1;\n        vector<vector<LL>>dp(m, vector<LL>(capability+1, 0));\n        dp[0][0] = 1 ;\n        for(int i = 1; i < m; i++){\n            auto [v, c] = arr[i];     \n            for (int j=0; j<=capability; j++)\n            {                \n                dp[i][j] = (j<v?0:dp[i][j-v]) + dp[i-1][j] - (j<v*(c+1)?0:dp[i-1][j-v*(c+1)]);\n                dp[i][j] = (dp[i][j]+M) % M;\n            }\n        }\n        LL ret = 0;\n        for(int i = 0; i<= capability; i++)\n            ret = (ret + dp[m-1][i]) % M;\n        return ret * (count0 + 1) % M;\n    }\n};\n```
[]