Python/C++ Beats 100%
Code\nC++ []\nclass Solution {\npublic:\n    long long mod = 1000000007;\n\n    long long factorial(int n) {\n        if (n == 0 || n == 1) {\n            retur
# Code\n```C++ []\nclass Solution {\npublic:\n    long long mod = 1000000007;\n\n    long long factorial(int n) {\n        if (n == 0 || n == 1) {\n            return 1;\n        }\n        long long result = 1;\n        for (int num = 2; num <= n; num++) {\n            result = (result * num) % mod;\n        }\n        return result;\n    }\n\n    long long count(string s) {\n        unordered_map<char, int> h;\n        for (char i : s) {\n            h[i]++;\n        }\n        long long j = 1;\n        for (auto i : h) {\n            j = (j * factorial(i.second)) % mod;\n        }\n        return j;\n    }\n\n    long long power(long long x, long long y, long long m) {\n        if (y == 0)\n            return 1;\n        long long p = power(x, y / 2, m) % m;\n        p = (p * p) % m;\n        return (y % 2 == 0) ? p : (x * p) % m;\n    }\n\n    long long modInverse(long long a, long long m) {\n        return power(a, m - 2, m);\n    }\n\n    int countAnagrams(string s) {\n        stringstream ss(s);\n        string word;\n        vector<string> x;\n        while (ss >> word) {\n            x.push_back(word);\n        }\n        long long ans = 1;\n        for (string word : x) {\n            ans = (ans * factorial(word.size())) % mod;\n            ans = (ans * modInverse(count(word), mod)) % mod;\n        }\n        return ans % mod;\n    }\n};\n```\n```python []\nclass Solution:\n    def __init__(self):\n        self.mod = 10**9 + 7\n\n    def factorial(self, n):\n        if n == 0 or n == 1:\n            return 1\n        result = 1\n        for num in range(2, n + 1):\n            result = (result * num) % self.mod\n        return result\n\n    def count(self, s):\n        char_count = Counter(s)\n        count_factorials = 1\n        for count in char_count.values():\n            count_factorials = (count_factorials * self.factorial(count)) % self.mod\n        return count_factorials\n\n    def power(self, x, y, m):\n        if y == 0:\n            return 1\n        p = self.power(x, y // 2, m) % m\n        p = (p * p) % m\n        return p if y % 2 == 0 else (x * p) % m\n\n    def modInverse(self, a, m):\n        return self.power(a, m - 2, m)\n\n    def countAnagrams(self, s):\n        words = s.split()\n        ans = 1\n        for word in words:\n            ans = (ans * self.factorial(len(word))) % self.mod\n            ans = (ans * self.modInverse(self.count(word), self.mod)) % self.mod\n        return ans % self.mod\n\n```
['Python', 'C++', 'Python3']