title: Subset Sum Divisible M
signature: subsetSumDivisibleM :: [Integer] -> Integer -> Integer -> Bool
  subsetSumDivisibleM arr n m = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Bool -> Bool -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: [Integer] -> Integer -> Integer -> Bool -> String
  driver arr n m expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME arr n m) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver ([2, 5, 7, 12, 13, 13, 15, 18, 20, 21, 22, 26, 27, 41, 41, 50, 53, 57, 58, 58, 61, 62, 62, 64, 70, 75, 78, 79, 81, 81, 81, 83, 86, 91, 93, 95, 97, 99, 99]) (36) (35) (True) )
  
      printf "TEST-1...%s\n" (driver ([8, 16, 62, -24, 14, -4, 2, 50, -64, -76, 78, 66, -64, 18]) (12) (11) (True) )
  
      printf "TEST-2...%s\n" (driver ([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, 1, 1]) (32) (27) (True) )
  
      printf "TEST-3...%s\n" (driver ([50, 20, 79, 42, 85, 24, 20, 76, 36, 88, 40, 5, 24, 85, 7, 19, 43, 51, 94, 13, 53, 93, 92, 43, 97, 38, 80, 48, 52, 47, 77, 56, 41, 80, 32, 34, 77, 14, 70, 3]) (29) (27) (True) )
  
      printf "TEST-4...%s\n" (driver ([-96, -94, -72, -58, -48, -36, -28, -26, -10, -10, -8, -8, -6, 2, 14, 30, 30, 54, 58, 60, 64, 68, 78, 84, 96, 98]) (16) (18) (True) )
  
      printf "TEST-5...%s\n" (driver ([1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0]) (7) (8) (True) )
  
      printf "TEST-6...%s\n" (driver ([2, 7, 8, 15, 18, 23, 24, 25, 27, 35, 40, 42, 43, 46, 48, 50, 53, 64, 66, 69, 70, 71, 72, 77, 78, 80, 81, 81, 81, 82, 82, 82, 84, 87, 97, 98]) (23) (32) (True) )
  
      printf "TEST-7...%s\n" (driver ([46, 54, 24, -10]) (3) (3) (True) )
  
      printf "TEST-8...%s\n" (driver ([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]) (21) (34) (True) )
  
      printf "TEST-9...%s\n" (driver ([39, 21, 38, 6, 38, 44, 96, 1, 16, 1, 28, 4, 55, 8]) (12) (11) (True) )
  
source_py: def subset_sum_divisible_m(arr, n, m):
      if (n > m):
          return True
      DP = [False for i in range(m)]
      for i in range(n):
          if DP[0]:
              return True
          temp = [False for i in range(m)]
          for j in range(m):
              if (DP[j] == True):
                  if (DP[((j + arr[i]) % m)] == False):
                      temp[((j + arr[i]) % m)] = True
          for j in range(m):
              if temp[j]:
                  DP[j] = True
          DP[(arr[i] % m)] = True
      return DP[0]
source_cpp: bool subset_sum_divisible_m(vector<int> arr, int n, int m) {
    if ( n > m ) return true;
    bool DP [ m ];
    memset ( DP, false, m );
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( DP [ 0 ] ) return true;
      bool temp [ m ];
      memset ( temp, false, m );
      for ( int j = 0;
      j < m;
      j ++ ) {
        if ( DP [ j ] == true ) {
          if ( DP [ ( j + arr [ i ] ) % m ] == false ) temp [ ( j + arr [ i ] ) % m ] = true;
        }
      }
      for ( int j = 0;
      j < m;
      j ++ ) if ( temp [ j ] ) DP [ j ] = true;
      DP [ arr [ i ] % m ] = true;
    }
    return DP [ 0 ];
  }