Using gcd and lcm concept
\njava []\nclass Solution {\n    public long maxScore(int[] nums) {\n        if(nums.length==1)return nums[0]*nums[0];\n        long ans=f(-1,nums);\n       for
\n```java []\nclass Solution {\n    public long maxScore(int[] nums) {\n        if(nums.length==1)return nums[0]*nums[0];\n        long ans=f(-1,nums);\n       for(int i=0;i<nums.length;i++){\n          ans=Math.max(f(i,nums),ans);\n       } \n       return ans;\n    }\n    public long f(int idx,int[] nums){\n        long g,l;\n        if(idx==0){\n              g=nums[1];\n              l=nums[1];\n        }\n        else{\n             g=nums[0];\n              l=nums[0]; \n        }\n           for(int i=1;i<nums.length;i++){\n            if(idx==i)continue;\n                g=gcd(nums[i],g);\n                l=lcm(nums[i],l);\n           }\n           return g*l;\n    }\n    public long gcd(long a,long b){\n        if(b==0)return a;\n        return gcd(b,a%b);\n    }\n    public long lcm(long a,long b){\n        return (a*b)/gcd(a,b);\n    }\n}\n```
['Java']