Using modulo inverse
Intuition\n Describe your first thoughts on how to solve this problem. \nuse permutations concept : \n- The no of ways you can arrange n letters (unique) is n!\
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nuse permutations concept : \n- The no of ways you can arrange n letters (unique) is n!\n- If n letters includes ( x1 letters of same alphabet , x2 letters of another same alphabet and so on ..) , the formula is n! / (x1! * x2! * ...)\n- Since modulo division is not distributive, instead of dividing, we need to multiply by the modulo inverse.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor each word , find the permutations possible ( as explained in intuition ) and multiply them. Modulo the result to get the answer\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```\nclass Solution:\n    def fast_pow(self,base, n, M):\n        if n == 0:\n            return 1\n        if n == 1:\n            return base\n        half_n = self.fast_pow(base, n // 2, M)\n        if n % 2 == 0:\n            return (half_n * half_n) % M\n        else:\n            return (((half_n * half_n) % M) * base) % M\n\n    def findMMI_fermat(self,n, M):\n        return self.fast_pow(n, M - 2, M)\n\n    def factorial(self,x,mod):\n        res = 1\n        while x:\n            res = (res*x)%mod\n            x-=1\n        return res\n    def solve(self,Upper,Lower,mod):\n        res = self.factorial(Upper,mod)\n        List = [self.factorial(x,mod) for x in Lower]\n        denominator = reduce(( lambda x, y: (x * y)%mod ), List) if List else 1\n        # print(Upper , res , denominator)\n        y = self.findMMI_fermat(denominator,mod);\n        return (res*y)%mod\n    def countAnagrams(self, s: str) -> int:\n        res = 1\n        for w in s.split():\n            n = len(w)\n            u = [count for count in Counter(w).values() if count>1]\n            res = (res*self.solve(n,u,1000000007))%1000000007\n            # print(res,n,u,"----------")\n        return int(res)\n```
['Python3']