title: Minimize Sum Product Two Arrays Permutations Allowed
signature: minimize_sum_product_two_arrays_permutations_allowed <- function(a, b, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, b, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, b, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(31L, 85L), list(18L, 33L), 1L, 
          558L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(22L, -6L, 84L, 70L, 84L, 6L, 28L, -74L, -14L, 68L, 22L, 90L, -10L), list(2L, -48L, -36L, -4L, -22L, -98L, -74L, -92L, -72L, -4L, 48L, -32L, 94L), 6L, 
          -8900L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), list(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 14L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(12L, 33L, 93L, 2L, 83L, 9L, 61L, 84L, 9L, 69L, 2L), list(85L, 92L, 92L, 1L, 54L, 31L, 69L, 4L, 39L, 81L, 52L), 7L, 
          20524L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-92L, -88L, -84L, -78L, -78L, -76L, -66L, -54L, -52L, -48L, -46L, -44L, -40L, -34L, -32L, -24L, -20L, -14L, -6L, -4L, 2L, 6L, 10L, 10L, 22L, 26L, 32L, 36L, 36L, 40L, 46L, 48L, 56L, 58L, 64L, 76L, 80L, 80L, 80L, 84L, 84L, 84L, 92L), list(-98L, -90L, -82L, -80L, -76L, -66L, -62L, -62L, -62L, -50L, -50L, -50L, -32L, -30L, -14L, -12L, 4L, 6L, 12L, 14L, 16L, 30L, 30L, 30L, 32L, 34L, 40L, 42L, 50L, 52L, 56L, 58L, 60L, 62L, 62L, 64L, 66L, 68L, 78L, 82L, 86L, 90L, 94L), 26L, 
          -14428L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L), list(0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), 32L, 
          8L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(4L, 6L, 6L, 20L, 22L, 23L, 26L, 39L, 40L, 47L, 50L, 68L, 68L, 70L, 73L, 77L, 80L, 82L, 85L), list(2L, 3L, 15L, 21L, 22L, 26L, 35L, 37L, 37L, 38L, 57L, 59L, 62L, 63L, 64L, 76L, 81L, 85L, 91L), 17L, 
          19298L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(78L, 60L, -8L, 46L, -12L), list(-72L, -80L, -30L, 16L, -38L), 2L, 
          -10560L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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), list(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), 17L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(60L, 66L, 84L, 99L, 85L, 89L, 28L, 97L, 85L, 71L, 53L, 93L, 23L, 9L, 45L, 26L, 49L, 95L, 64L, 33L, 70L, 34L, 10L, 1L, 68L, 39L, 53L, 12L), list(37L, 33L, 33L, 77L, 78L, 34L, 28L, 1L, 63L, 15L, 51L, 50L, 90L, 22L, 71L, 23L, 68L, 55L, 2L, 22L, 31L, 54L, 76L, 36L, 2L, 27L, 96L, 89L), 15L, 
          44563L
      )))
  
  }
  
  main()
source_py: def minimize_sum_product_two_arrays_permutations_allowed(A, B, n):
      sorted(A)
      sorted(B)
      result = 0
      for i in range(n):
          result += (A[i] * B[((n - i) - 1)])
      return result
source_cpp: int minimize_sum_product_two_arrays_permutations_allowed(vector<int> A, vector<int> B, int n) {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int result = 0;
    for ( int i = 0;
    i < n;
    i ++ ) result += ( A [ i ] * B [ n - i - 1 ] );
    return result;
  }