title: Minimum Cost Connect Weighted Nodes Represented Array
signature: minimum_cost_connect_weighted_nodes_represented_array <- function(a, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(3L, 8L, 14L, 15L, 17L, 17L, 19L, 21L, 22L, 23L, 29L, 32L, 36L, 37L, 43L, 45L, 46L, 47L, 47L, 53L, 57L, 57L, 70L, 71L, 72L, 76L, 81L, 82L, 90L, 95L, 96L, 98L, 99L), 32L, 
          4548L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(94L, -18L, 50L, 94L, -74L, -50L, -44L, -92L, -58L, 14L, -66L, -78L), 10L, 
          -736L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 24L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(15L, 18L, 64L, 28L), 2L, 
          270L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -88L, -88L, -84L, -82L, -78L, -78L, -60L, -58L, -56L, -54L, -52L, -48L, -44L, -28L, -26L, -14L, -12L, 6L, 10L, 10L, 14L, 14L, 50L, 52L, 54L, 60L, 62L, 62L, 64L, 66L, 70L, 72L, 72L, 78L, 80L, 84L), 31L, 
          40896L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L), 6L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 10L, 14L, 14L, 15L, 16L, 18L, 20L, 21L, 30L, 31L, 33L, 35L, 39L, 46L, 48L, 59L, 59L, 61L, 77L, 78L, 79L, 81L, 83L, 85L, 92L, 97L, 97L, 99L), 23L, 
          2652L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(4L, -32L, 68L, -48L, 54L, 24L, 78L, 98L, -70L, 44L, -82L, -92L, -16L, -92L, -70L, 52L, -58L, -62L, -58L, 32L, 14L, -4L, 80L, -78L, -26L, -24L, -8L), 18L, 
          9936L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 35L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(82L, 74L, 53L, 91L, 81L, 88L, 42L, 62L, 38L, 43L, 29L, 60L, 43L, 44L, 19L, 28L, 20L, 1L, 5L, 94L, 18L, 77L, 52L, 38L, 55L, 1L, 10L, 29L, 34L, 91L, 64L, 80L, 81L, 39L, 4L, 47L, 30L, 62L, 58L, 66L, 73L, 52L, 62L, 9L, 36L, 49L), 38L, 
          1808L
      )))
  
  }
  
  main()
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 );
  }