human
Calculate cost of visiting all array elements in increasing order | Function to calculate total cost of visiting array elements in increasing order.
Stores the pair of element and their positions.
Traverse the array arr [ ].
Push the pair { arr [ i ] , i } in v.
Sort the vector in ascending order ..
Stores the total cost.
Stores the index of last element visited.
Traverse the vector v.
Increment ans.
Assign.
Return ans.
Driver Code"
Solution in Python:

What is a code to calculate cost of visiting all array elements in increasing order and the other steps required?
assistant
#Here is code to calculate cost of visiting all array elements in increasing order and the other steps required.
 def calculateDistance ( arr , N ) :
	v = [ ]
	for i in range ( N ) :
		v . append ( [ arr [ i ] , i ] )
	v . sort ( )
	ans = 0
	last = 0
	for j in v :
		ans += abs ( j [ 1 ] - last )
		last = j [ 1 ]
	return ans
if __name__ == " _ _ main _ _ " :
	arr = [ 4 , 3 , 2 , 5 , 1 ]
	N = len ( arr )
	print ( calculateDistance ( arr , N ) )