human
Minimize remaining array element by repeatedly replacing pairs by half of one more than their sum | Function to print smallest element left in the array and the pairs by given operation.
Stores array elements and return the minimum element of arr [ ] in O ( 1 ).
Stores all the pairs that can be selected by the given operations.
Traverse the array arr [ ].
Traverse pq while count of elements left in pq greater than 1.
Stores top element of pq.
Pop top element of pq.
Stores top element of pq.
Pop top element of pq.
Insert ( X + Y + 1 ) / 2 in pq.
Insert the pair ( X , Y ) in pairsArr [ ].
Print element left in pq by performing the given operations.
Stores count of elements in pairsArr [ ].
Print the pairs that can be selected in given operations.
If i is the first index of pairsArr [ ].
Print pairs of pairsArr [ ].
If i is not the last index of pairsArr [ ].
If i is the last index of pairsArr [ ].
Driver Code"
How can the above be solved in Python?

Give me a code to minimize remaining array element by repeatedly replacing pairs by half of one more than their sum and the other steps required?
assistant
#Here is code to minimize remaining array element by repeatedly replacing pairs by half of one more than their sum and the other steps required.
 def smallestNumberLeftInPQ ( arr , N ) :
	pq = [ ]
	pairsArr = [ ]
	for i in range ( N ) :
		pq . append ( arr [ i ] )
	pq = sorted ( pq )
	while ( len ( pq ) > 1 ) :
		X = pq [ - 1 ]
		del pq [ - 1 ]
		Y = pq [ - 1 ]
		del pq [ - 1 ]
		pq . append ( ( X + Y + 1 ) // 2 )
		pairsArr . append ( [ X , Y ] )
		pq = sorted ( pq )
	print ( " { " , pq [ - 1 ] , " } , ▁ " , end = " " )
	sz = len ( pairsArr )
	for i in range ( sz ) :
		if ( i == 0 ) :
			print ( " { ▁ " , end = " " )
		print ( " ( " , pairsArr [ i ] [ 0 ] , " , " , pairsArr [ i ] [ 1 ] , " ) " , end = " " )
		if ( i != sz - 1 ) :
			print ( end = " , ▁ " )
		if ( i == sz - 1 ) :
			print ( end = " ▁ } " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 2 , 1 ]
	N = len ( arr )
	smallestNumberLeftInPQ ( arr , N )