human
Count distinct median possible for an Array using given ranges of elements | Function to count the number of distinct medians of an array where each array elements are given by a range.
Loop to store the starting and end range in the array.
Condition to check if the length of the array is odd.
Driver Code.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to count distinct median possible for an Array using given ranges of elements and the other steps required.
 def solve ( n , vec ) :
	a = [ ]
	b = [ ]
	for pr in vec :
		a . append ( pr [ 0 ] )
		b . append ( pr [ 1 ] )
	a . sort ( )
	b . sort ( )
	if ( ( n & 1 ) ) :
		left = a [ n // 2 ]
		right = b [ n // 2 ]
		ans = right - left + 1
	else :
		left = ( a [ n // 2 ] + a [ n // 2 - 1 ] )
		right = ( b [ n // 2 ] + b [ n // 2 - 1 ] )
		ans = right - left + 1
	print ( ans )
if __name__ == " _ _ main _ _ " :
	N = 3
	vec = [ ( 100 , 100 ) , ( 10 , 10000 ) , ( 1 , 1000000000 ) ]
	solve ( N , vec )