title: Minimum Cost Connect Weighted Nodes Represented Array
signature: func minimumCostConnectWeightedNodesRepresentedArray(a []int, n int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(a []int, n int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(a, n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{3, 8, 14, 15, 17, 17, 19, 21, 22, 23, 29, 32, 36, 37, 43, 45, 46, 47, 47, 53, 57, 57, 70, 71, 72, 76, 81, 82, 90, 95, 96, 98, 99}, 
  	32, 4548)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{94, -18, 50, 94, -74, -50, -44, -92, -58, 14, -66, -78}, 
  	10, -736)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	24, 0)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{15, 18, 64, 28}, 
  	2, 270)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-96, -88, -88, -84, -82, -78, -78, -60, -58, -56, -54, -52, -48, -44, -28, -26, -14, -12, 6, 10, 10, 14, 14, 50, 52, 54, 60, 62, 62, 64, 66, 70, 72, 72, 78, 80, 84}, 
  	31, 40896)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{0, 1, 1, 0, 1, 1, 1, 1}, 
  	6, 0)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{3, 10, 14, 14, 15, 16, 18, 20, 21, 30, 31, 33, 35, 39, 46, 48, 59, 59, 61, 77, 78, 79, 81, 83, 85, 92, 97, 97, 99}, 
  	23, 2652)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{4, -32, 68, -48, 54, 24, 78, 98, -70, 44, -82, -92, -16, -92, -70, 52, -58, -62, -58, 32, 14, -4, 80, -78, -26, -24, -8}, 
  	18, 9936)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	35, 0)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{82, 74, 53, 91, 81, 88, 42, 62, 38, 43, 29, 60, 43, 44, 19, 28, 20, 1, 5, 94, 18, 77, 52, 38, 55, 1, 10, 29, 34, 91, 64, 80, 81, 39, 4, 47, 30, 62, 58, 66, 73, 52, 62, 9, 36, 49}, 
  	38, 1808)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def minimum_cost_connect_weighted_nodes_represented_array(a, n):
      mn = sys.maxsize
      sum = 0
      for i in range(n):
          mn = min(a[i], mn)
          sum += a[i]
      return (mn * (sum - mn))
source_cpp: int minimum_cost_connect_weighted_nodes_represented_array(vector<int> a, int n) {
    int mn = INT_MAX;
    int sum = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      mn = min ( a [ i ], mn );
      sum += a [ i ];
    }
    return mn * ( sum - mn );
  }