title: Subsequences Size Three Array Whose Sum Divisible M 1
signature: def subsequences_size_three_array_whose_sum_divisible_m_1(a, n, m):
source_py: def subsequences_size_three_array_whose_sum_divisible_m_1(A, N, M):
      ans = 0
      h = ([0] * M)
      for i in range(0, N):
          A[i] = (A[i] % M)
          h[A[i]] = (h[A[i]] + 1)
      for i in range(0, M):
          for j in range(i, M):
              rem = ((M - ((i + j) % M)) % M)
              if (rem < j):
                  continue
              if ((i == j) and (rem == j)):
                  ans = (ans + (((h[i] * (h[i] - 1)) * (h[i] - 2)) / 6))
              elif (i == j):
                  ans = (ans + (((h[i] * (h[i] - 1)) * h[rem]) / 2))
              elif (i == rem):
                  ans = (ans + (((h[i] * (h[i] - 1)) * h[j]) / 2))
              elif (rem == j):
                  ans = (ans + (((h[j] * (h[j] - 1)) * h[i]) / 2))
              else:
                  ans = (ans + ((h[i] * h[j]) * h[rem]))
          return ans
source_cpp: int subsequences_size_three_array_whose_sum_divisible_m_1(vector<int> A, int N, int M) {
    int ans = 0;
    int h [ M ] = {
      0 };
      for ( int i = 0;
      i < N;
      i ++ ) {
        A [ i ] = A [ i ] % M;
        h [ A [ i ] ] ++;
      }
      for ( int i = 0;
      i < M;
      i ++ ) {
        for ( int j = i;
        j < M;
        j ++ ) {
          int rem = ( M - ( i + j ) % M ) % M;
          if ( rem < j ) continue;
          if ( i == j && rem == j ) ans += h [ i ] * ( h [ i ] - 1 ) * ( h [ i ] - 2 ) / 6;
          else if ( i == j ) ans += h [ i ] * ( h [ i ] - 1 ) * h [ rem ] / 2;
          else if ( i == rem ) ans += h [ i ] * ( h [ i ] - 1 ) * h [ j ] / 2;
          else if ( rem == j ) ans += h [ j ] * ( h [ j ] - 1 ) * h [ i ] / 2;
          else ans = ans + h [ i ] * h [ j ] * h [ rem ];
        }
      }
      return ans;
    }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return abs(actual - expected) < 1e-06
  
  def driver(a, n, m, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              a, n, m),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([6, 7, 13, 16, 19, 20, 0, 4, 7, 10, 15, 17, 0, 2, 8, 12, 13, 14, 0, 0, 0, 2, 2, 2, 4, 8, 10, 73, 76, 78, 87, 90, 91, 99], 27, 21, 75.0)
      print(f"TEST-0...{result}")
  
      result = driver([7, 13, 19, 15, 14, 11, 19, 4, 1, 18, 7, 5, 15, 9, 5, 11, 6, 18, 5, 19, 9, 7, 9, 19, 9, 12, 20, 12, 2, 66, 94, 12, 10, 4, 40, -72, 20, -2, -90, -90], 29, 21, 0.0)
      print(f"TEST-1...{result}")
  
      result = driver([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], 29, 43, 1140.0)
      print(f"TEST-2...{result}")
  
      result = driver([1, 2, 3, 37, 91], 3, 4, 0.0)
      print(f"TEST-3...{result}")
  
      result = driver([8, 6, 10, 10, 4, 2, 10, 2, 2, 10, 0, 8, 10, 86, 88], 13, 12, 17.0)
      print(f"TEST-4...{result}")
  
      result = driver([1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1], 11, 15, 56.0)
      print(f"TEST-5...{result}")
  
      result = driver([1, 2, 0, 2, 3, 0, 1, 58, 78], 7, 4, 6.0)
      print(f"TEST-6...{result}")
  
      result = driver([0, 2, 2, 12, 4, 8, 8, 6, 10, 12, 10, 4, 4, -2, -4], 13, 14, 12.0)
      print(f"TEST-7...{result}")
  
      result = driver([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], 37, 34, 286.0)
      print(f"TEST-8...{result}")
  
      result = driver([27, 1, 31, 14, 20, 8, 23, 12, 15, 0, 15, 26, 3, 8, 3, 26, 15, 31, 97, 90, 1, 69, 77, 20, 68, 11, 2, 92, 50, 8, 23, 83, 76, 6, 32, 43, 92], 18, 35, 6.0)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: subsequences_size_three_array_whose_sum_divisible_m_1
question_info.test_list: [{"idx": 0, "outputs": 75.0, "inputs": {"a": [6, 7, 13, 16, 19, 20, 0, 4, 7, 10, 15, 17, 0, 2, 8, 12, 13, 14, 0, 0, 0, 2, 2, 2, 4, 8, 10, 73, 76, 78, 87, 90, 91, 99], "n": 27, "m": 21}}, {"idx": 1, "outputs": 0.0, "inputs": {"a": [7, 13, 19, 15, 14, 11, 19, 4, 1, 18, 7, 5, 15, 9, 5, 11, 6, 18, 5, 19, 9, 7, 9, 19, 9, 12, 20, 12, 2, 66, 94, 12, 10, 4, 40, -72, 20, -2, -90, -90], "n": 29, "m": 21}}, {"idx": 2, "outputs": 1140.0, "inputs": {"a": [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], "n": 29, "m": 43}}, {"idx": 3, "outputs": 0.0, "inputs": {"a": [1, 2, 3, 37, 91], "n": 3, "m": 4}}, {"idx": 4, "outputs": 17.0, "inputs": {"a": [8, 6, 10, 10, 4, 2, 10, 2, 2, 10, 0, 8, 10, 86, 88], "n": 13, "m": 12}}, {"idx": 5, "outputs": 56.0, "inputs": {"a": [1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1], "n": 11, "m": 15}}, {"idx": 6, "outputs": 6.0, "inputs": {"a": [1, 2, 0, 2, 3, 0, 1, 58, 78], "n": 7, "m": 4}}, {"idx": 7, "outputs": 12.0, "inputs": {"a": [0, 2, 2, 12, 4, 8, 8, 6, 10, 12, 10, 4, 4, -2, -4], "n": 13, "m": 14}}, {"idx": 8, "outputs": 286.0, "inputs": {"a": [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], "n": 37, "m": 34}}, {"idx": 9, "outputs": 6.0, "inputs": {"a": [27, 1, 31, 14, 20, 8, 23, 12, 15, 0, 15, 26, 3, 8, 3, 26, 15, 31, 97, 90, 1, 69, 77, 20, 68, 11, 2, 92, 50, 8, 23, 83, 76, 6, 32, 43, 92], "n": 18, "m": 35}}]
question_info.entry_cls_name: Solution