Multiply Permutations
We count permutations of each word, and multiply those permutatons.\n\nThe number of permutations with repetitions is a factorial of word lenght, divided by fac
We count permutations of each word, and multiply those permutatons.\n\nThe number of permutations with repetitions is a factorial of word lenght, divided by factorial of count of each character.\n\n**Python 3**\nPython developers are in luck due to `factorial` and large integer support.\n\n```python\nclass Solution:\n    def countAnagrams(self, s: str) -> int:\n        res = 1\n        for w in s.split(" "):\n            cnt, prem = Counter(w), factorial(len(w))\n            for rep in cnt.values():\n                prem = prem // factorial(rep)\n            res = res * prem % 1000000007\n        return res\n```\n**C++**\nNeed to pre-compute factorials and inverse modulos (to simulate divisions).\n\n```cpp\nint fact[100001] = {1, 1}, inv_fact[100001] = {1, 1}, mod = 1000000007;\nclass Solution {\npublic: \nint countAnagrams(string s) {\n    if (fact[2] == 0) {\n        vector<int> inv(100001, 1);\n        for (long long i = 2; i < sizeof(fact) / sizeof(fact[0]); ++i) {\n            fact[i] = i * fact[i - 1] % mod;\n            inv[i] = mod - mod / i * inv[mod % i] % mod;\n            inv_fact[i] = 1LL * inv_fact[i - 1] * inv[i] % mod;            \n        }\n    }\n    int res = 1;\n    for (int i = 0, j = 0; i <= s.size(); ++i)\n        if (i == s.size() || s[i] == \' \') {\n            long long cnt[26] = {}, prem = fact[i - j];\n            for (int k = j; k < i; ++k)\n                ++cnt[s[k] - \'a\'];\n            for (int rep : cnt)\n                prem = prem * inv_fact[rep] % mod;\n            res = res * prem % mod;\n            j = i + 1;\n        }\n    return res;\n}\n};\n```
['C', 'Python']