Count pairs ( i , j ) from arrays arr [ ] & brr [ ] such that arr [ i ] | Function to count the pairs such that given condition is satisfied ; Stores the sum of element at each corresponding index ; Find the sum of each index of both array ; Stores frequency of each element present in sumArr ; Initialize number of pairs ; Add possible vaid pairs ; Return Number of Pairs ; Given array arr [ ] and brr [ ] ; Size of given array ; Function calling
def CountPairs ( a , b , n ) : NEW_LINE INDENT C = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT C [ i ] = a [ i ] + b [ i ] NEW_LINE DEDENT freqCount = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if C [ i ] in freqCount . keys ( ) : NEW_LINE INDENT freqCount [ C [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT freqCount [ C [ i ] ] = 1 NEW_LINE DEDENT DEDENT NoOfPairs = 0 NEW_LINE for x in freqCount : NEW_LINE INDENT y = freqCount [ x ] NEW_LINE NoOfPairs = ( NoOfPairs + y * ( y - 1 ) // 2 ) NEW_LINE DEDENT print ( NoOfPairs ) NEW_LINE DEDENT arr = [ 1 , 4 , 20 , 3 , 10 , 5 ] NEW_LINE brr = [ 9 , 6 , 1 , 7 , 11 , 6 ] NEW_LINE N = len ( arr ) NEW_LINE CountPairs ( arr , brr , N ) NEW_LINE