title: Minimum Operations Make Gcd Array Multiple K
signature: minimum_operations_make_gcd_array_multiple_k <- function(a, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(3L, 7L, 27L, 32L, 36L, 37L, 44L, 48L, 50L, 64L, 86L), 5L, 10L, 
          19L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-22L, 6L, -20L, 60L, -74L, 98L, 52L, -22L), 5L, 4L, 
          130L
      )))
  
      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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 23L, 29L, 
          661L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(77L, 11L, 51L, 11L, 84L, 79L, 43L, 12L, 14L, 50L, 15L, 6L, 85L, 32L, 74L, 49L, 7L, 2L, 58L), 9L, 17L, 
          43L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-90L, -66L, -64L, -58L, -46L, -44L, -32L, -30L, -30L, -22L, -18L, -14L, 12L, 12L, 18L, 34L, 44L, 60L, 70L, 70L, 74L, 76L, 86L, 98L, 98L), 12L, 22L, 
          778L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L), 36L, 31L, 
          1096L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(9L, 22L, 27L, 27L, 37L, 53L, 53L, 56L, 63L, 73L, 76L, 81L, 82L), 10L, 11L, 
          28L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-46L, 60L, 80L, 80L, 42L, -98L, 30L, -48L, 4L, -32L, -78L, 40L, 52L, 26L, 88L, 4L, 22L, 62L, 88L, -94L, 2L, 0L, 58L, 38L, 52L, -50L, -52L, 58L, -62L, 30L, -38L, -8L, -82L, -66L), 18L, 19L, 
          479L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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), 19L, 22L, 
          413L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(42L, 69L, 93L, 82L, 8L, 23L, 73L, 1L, 77L, 39L, 49L, 4L, 95L, 85L), 12L, 13L, 
          51L
      )))
  
  }
  
  main()
source_py: def minimum_operations_make_gcd_array_multiple_k(a, n, k):
      result = 0
      for i in range(n):
          if ((a[i] != 1) and (a[i] > k)):
              result = (result + min((a[i] % k), (k - (a[i] % k))))
          else:
              result = ((result + k) - a[i])
      return result
source_cpp: int minimum_operations_make_gcd_array_multiple_k(vector<int> a, int n, int k) {
    int result = 0;
    for ( int i = 0;
    i < n;
    ++ i ) {
      if ( a [ i ] != 1 && a [ i ] > k ) {
        result = result + min ( a [ i ] % k, k - a [ i ] % k );
      }
      else {
        result = result + k - a [ i ];
      }
    }
    return result;
  }