scala solution
scala []\nobject Solution {\n  import scala.util.chaining._\n  def maxScore(nums: Array[Int]): Long = {\n    def reducer(a:(BigInt,BigInt),b:(BigInt,BigInt)) =\
```scala []\nobject Solution {\n  import scala.util.chaining._\n  def maxScore(nums: Array[Int]): Long = {\n    def reducer(a:(BigInt,BigInt),b:(BigInt,BigInt)) =\n      (a._1 gcd b._1, (a._2 / (a._2 gcd b._2)) * b._2)\n    val pfx = nums.sorted.map(BigInt(_)).map(a => (a,a))\n      .pipe{l => l.tail.scanLeft(l.head)(reducer)}\n    val sfx = nums.sorted.reverse.map(BigInt(_)).map(a => (a,a))\n      .pipe{l => l.tail.scanLeft(l.head)(reducer)}.reverse\n    ((1 until (nums.length-1)).map(i => reducer(pfx(i-1),sfx(i+1))) ++ \n      sfx.take(2) :+ pfx.last).map{case (a,b) => a*b}.max.toLong\n  }\n}\n```
['Array', 'Prefix Sum', 'Scala']