human
Subsequences of size three in an array whose sum is divisible by m | Python program to find count of subsequences of size three divisible by M ..
Storing frequencies of all remainders when divided by M ..
including i and j in the sum rem calculate the remainder required to make the sum divisible by M.
if the required number is less than j , we skip as we have already calculated for that value before . As j here starts with i and rem is less than j ..
if satisfies the first case ..
if satisfies the second case.
if satisfies the third case.
Driver code"
Solution in Python:

=====
What is a code to subsequences of size three in an array whose sum is divisible by m and the other steps required?
assistant
#Here is code to subsequences of size three in an array whose sum is divisible by m and the other steps required.
 def countSubSeq ( 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
M = 3 ;
A = [ 1 , 2 , 4 , 3 ]
N = len ( A )
print ( countSubSeq ( A , N , M ) )