#NEWLINE# def minTotalDistance( self , grid ) : #NEWLINE# #INDENT# '\n        :type grid: List[List[int]]\n        :rtype: int\n        ' #NEWLINE# x = [ i for ( i , row ) in enumerate ( grid ) for v in row if ( v == 1 ) ] #NEWLINE# y = [ j for row in grid for ( j , v ) in enumerate ( row ) if ( v == 1 ) ] #NEWLINE# mid_x = self . findKthLargest ( x , ( ( len ( x ) / 2 ) + 1 ) ) #NEWLINE# mid_y = self . findKthLargest ( y , ( ( len ( y ) / 2 ) + 1 ) ) #NEWLINE# return sum ( [ ( abs ( ( mid_x - i ) ) + abs ( ( mid_y - j ) ) ) for ( i , row ) in enumerate ( grid ) for ( j , v ) in enumerate ( row ) if ( v == 1 ) ] )