precompute prefix and suffix lcm's and gcd's | Python
\n"""\nPrecompute the prefix and suffix lcm\'s and gcd\'s.\n"""\n\nfrom math import gcd, lcm\nclass Solution:\n    def maxScore(self, A: List[int]) -> int:\n   
```\n"""\nPrecompute the prefix and suffix lcm\'s and gcd\'s.\n"""\n\nfrom math import gcd, lcm\nclass Solution:\n    def maxScore(self, A: List[int]) -> int:\n        n = len(A)\n        \n        if n == 1:\n            return A[0] ** 2\n        \n        gcd_left = [1] * n\n        gcd_right = [1] * n\n        lcm_left = [1] * n\n        lcm_right = [1] * n\n        \n        gcd_left[0] = A[0]\n        lcm_left[0] = A[0]\n        gcd_right[n-1] = A[n-1]\n        lcm_right[n-1] = A[n-1]\n        \n        for i in range(1, n):\n            gcd_left[i] = gcd(gcd_left[i-1], A[i])\n            lcm_left[i] = lcm(lcm_left[i-1], A[i])\n            \n        for i in range(n-2, -1, -1):\n            gcd_right[i] = gcd(A[i], gcd_right[i+1])\n            lcm_right[i] = lcm(A[i], lcm_right[i+1])\n            \n        \n        # print(f"{gcd_left=}")\n        # print(f"{lcm_left=}")\n        # print(f"{gcd_right=}")\n        # print(f"{lcm_right=}")\n        \n        score = gcd_left[-1] * lcm_left[-1]\n        \n        for i in range(n):\n            if i == 0:\n                factor = gcd_right[i+1]\n                multiple = lcm_right[i+1]\n                \n            elif i == n - 1:\n                factor = gcd_left[i-1]\n                multiple = lcm_left[i-1]\n                \n            else:\n                factor = gcd(gcd_left[i-1], gcd_right[i+1])\n                \n                lcm_left_to_i = lcm_left[i-1]\n                lcm_right_to_i = lcm_right[i+1]\n                \n                multiple = lcm(lcm_left_to_i, lcm_right_to_i)\n                \n                \n            score = max(score, factor * multiple)\n            \n        return score\n                \n```
['Python']