human
Count quadruples ( i , j , k , l ) in an array such that i < j < k < l and arr [ i ] = arr [ k ] and arr [ j ] = arr [ l ] | Function to count total number of required tuples.
Initialize unordered map.
Find the pairs ( j , l ) such that arr [ j ] = arr [ l ] and j < l.
Elements are equal.
Update the count.
Add the frequency of arr [ l ] to val.
Update the frequency of element arr [ j ].
Return the answer.
Driver code.
Given array arr [ ].
Function call"
How can the above be solved in Python?
 Give me a code to count quadruples ( i , j , k , l ) in an array such that i < j < k < l and arr [ i ] = arr [ k ] and arr [ j ] = arr [ l ] and the other steps required?
assistant
#Here is code to count quadruples ( i , j , k , l ) in an array such that i < j < k < l and arr [ i ] = arr [ k ] and arr [ j ] = arr [ l ] and the other steps required.
 def countTuples ( arr , N ) :
	ans = 0
	val = 0
	freq = { }
	for j in range ( N - 2 ) :
		val = 0
		for l in range ( j + 1 , N ) :
			if ( arr [ j ] == arr [ l ] ) :
				ans += val
			if arr [ l ] in freq :
				val += freq [ arr [ l ] ]
		freq [ arr [ j ] ] = freq . get ( arr [ j ] , 0 ) + 1
	return ans
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 1 , 2 , 2 , 2 ]
	N = len ( arr )
	print ( countTuples ( arr , N ) )