title: Maximize Sum Consecutive Differences Circular Array
signature: pub fn maximize_sum_consecutive_differences_circular_array(arr: Vec<i32>, n: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(arr: Vec<i32>, n: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        Vec::from([8, 9, 12, 13, 17, 21, 24, 29, 37, 37, 39, 40, 41, 45, 49, 50, 53, 54, 56, 59, 60, 60, 70, 71, 72, 74, 77, 77, 78, 85, 89, 89, 90, 90, 95, 98, 98]), 34, 
        1454
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([-92, -84, -84, -84, -84, -80, -80, -80, -64, -52, -40, -32, -20, -18, -16, 0, 6, 14, 20, 26, 28, 30, 32, 32, 44, 48, 48, 52, 54, 66, 76, 78, 88, 92, 94, 96]), 24, 
        1980
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([0, 0, 0, 1, 1, 1]), 3, 
        0
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([7, 47, 53, 59, 80, 84, 96]), 5, 
        170
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-88, -80, -68, -62, -60, -60, -48, -46, -44, -38, -16, -16, 0, 0, 2, 8, 20, 36, 40, 40, 44, 54, 60, 68, 70, 82, 82, 84, 92, 94, 96]), 29, 
        2812
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 32, 
        20
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([2, 5, 10, 11, 13, 14, 15, 17, 17, 23, 23, 24, 27, 27, 28, 29, 30, 40, 42, 43, 46, 47, 51, 52, 57, 64, 65, 73, 74, 75, 76, 77, 81, 81, 82, 87, 89, 93, 95, 95, 99]), 35, 
        1542
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([-94, -92, -84, -84, -76, -72, -72, -72, -54, -48, -38, -22, -16, -12, 2, 2, 12, 20, 20, 24, 26, 26, 26, 26, 30, 38, 48, 50, 84, 86]), 21, 
        1608
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1]), 37, 
        20
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([7, 8, 27, 31, 37, 46, 46, 52, 53, 53, 56, 57, 57, 73, 73, 74, 80, 84, 97]), 13, 
        344
      ));
      
  }
source_py: def maximize_sum_consecutive_differences_circular_array(arr, n):
      sum = 0
      arr.sort()
      for i in range(0, int((n / 2))):
          sum -= (2 * arr[i])
          sum += (2 * arr[((n - i) - 1)])
      return sum
source_cpp: int maximize_sum_consecutive_differences_circular_array(vector<int> arr, int n) {
    int sum = 0;
    sort(arr.begin(), arr.end());
    for ( int i = 0;
    i < n / 2;
    i ++ ) {
      sum -= ( 2 * arr [ i ] );
      sum += ( 2 * arr [ n - i - 1 ] );
    }
    return sum;
  }