Prefix and suffix. Simple solution O(n)
```
class Solution:
    def maxScore(self, nums: List[int]) -> int:
        if len(nums) == 1:
            return nums[0] * nums[0]
        pref_gcd = [*accumulate(nums, gcd)]
        pref_lcm = [*accumulate(nums, lcm)]

        suff_gcd = [*accumulate(reversed(nums), gcd)]
        suff_lcm = [*accumulate(reversed(nums), lcm)]

        ans = max(pref_gcd[-1] * pref_lcm[-1], pref_gcd[-2] * pref_lcm[-2], suff_gcd[-2] * suff_lcm[-2])
        for i in range(1, len(nums)-1):
            ans = max(ans, gcd(pref_gcd[i-1], suff_gcd[~i-1]) * lcm(pref_lcm[i-1], suff_lcm[~i-1]))
        return ans
```
['Python3']