title: Subsequences Size Three Array Whose Sum Divisible M
signature: int subsequencesSizeThreeArrayWhoseSumDivisibleM(vector<int> a, int n, int m) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> a, int n, int m, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(a, n, m), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({14, 35, 56, 70, 88}, 3, 4, 0); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-50, -92, 16, -68, -36}, 3, 4, 0); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 1, 1, 1}, 4, 5, 1); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({76, 43, 22, 41, 49, 99, 25, 40, 3, 45, 60, 16, 83, 62, 26, 93, 64, 73, 72, 53, 6, 32, 35, 67, 17}, 14, 21, 19); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-90, -86, -86, -66, -50, -48, -44, -42, -42, -38, -24, -22, -20, -18, -8, 8, 24, 28, 34, 48, 60, 62, 66, 68, 74, 76, 80, 82, 88}, 24, 20, 207); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0}, 24, 30, 120); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({4, 5, 8, 9, 10, 12, 13, 16, 17, 18, 21, 21, 25, 27, 28, 30, 36, 36, 54, 55, 56, 57, 60, 62, 67, 67, 68, 71, 72, 72, 73, 73, 77, 77, 83, 86, 86, 86, 87, 89, 92, 92, 96, 97, 97, 98}, 24, 23, 85); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-64, 52, -32, 38, 8, -62, -56, 20, 72, -12, 32, 44}, 6, 6, 2); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({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}, 12, 15, 220); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({77, 68, 45, 6, 27, 19, 29, 95, 21, 2, 39, 48, 72, 67, 49, 45, 1, 16, 56, 78, 25, 22, 27, 40, 31, 34, 26, 35, 12}, 25, 25, 92); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def subsequences_size_three_array_whose_sum_divisible_m(A, N, M):
      sum = 0
      ans = 0
      for i in range(0, N):
          for j in range((i + 1), N):
              for k in range((j + 1), N):
                  sum = ((A[i] + A[j]) + A[k])
                  if ((sum % M) == 0):
                      ans = (ans + 1)
      return ans
source_cpp: int subsequences_size_three_array_whose_sum_divisible_m(vector<int> A, int N, int M) {
    int sum = 0;
    int ans = 0;
    for ( int i = 0;
    i < N;
    i ++ ) {
      for ( int j = i + 1;
      j < N;
      j ++ ) {
        for ( int k = j + 1;
        k < N;
        k ++ ) {
          sum = A [ i ] + A [ j ] + A [ k ];
          if ( sum % M == 0 ) ans ++;
        }
      }
    }
    return ans;
  }