human
Count pairs ( i , j ) from an array such that i < j and arr [ j ] | Function to count the number of pairs ( i , j ) such that i < j and arr [ i ] - arr [ j ] = X * ( j - i ).
Stores the count of all such pairs that satisfies the condition ..
Stores count of distinct values of arr [ i ] - x * i.
Iterate over the Map.
Increase count of pairs.
Print the count of such pairs.
Driver Code"
Solution in Python:
 ... Can you provide a code to count pairs ( i , j ) from an array such that i < j and arr [ j ] and the other steps required?
assistant
#Here is code to count pairs ( i , j ) from an array such that i < j and arr [ j ] and the other steps required.
 def countPairs ( arr , n , x ) :
	count = 0
	mp = { }
	for i in range ( n ) :
		if ( ( arr [ i ] - x * i ) in mp ) :
			mp [ arr [ i ] - x * i ] += 1
		else :
			mp [ arr [ i ] - x * i ] = 1
	for key , value in mp . items ( ) :
		n = value
		count += ( n * ( n - 1 ) ) // 2
	print ( count )
if __name__ == ' _ _ main _ _ ' :
	n = 6
	x = 3
	arr = [ 5 , 4 , 8 , 11 , 13 , 16 ]
	countPairs ( arr , n , x )