Please provide the code in python for this problem

You have been given an array of N coins. As per the rules the following tasks can be performed:-

• Swap adjacent coins.
• Once a pair of coins is swapped, they cannot be swapped with any other coin.

Given the initial position of coins on the board represented by array A. calculate the maximum power of array. Power of Array is: Σ A[i]*i

Find the maximum possible value of Power Of Array that can be achieved with the given array and the mentioned rules.

Note: Indexing of array A starts from 1.

Input Specification:

input1: An integer value N denoting the number of coins.
input2: An integer array A denoting the coins.

Output Specification:
Return an integer value denoting the maximum power of given array.

Example:

input1:4

input2: (2,4,5,3)

Output: 39

Explanation:

Power of array of (2, 4, 5, 3) is (21+ 42+53 +34) = 37. The only way to get maximum power of array is by swapping A[3] with A[4].
The only way to get maximum power of array is by swapping A[3] with A[4]. On doing so, the array becomes (2, 4, 3, 5) and the power of array is (21 +42+33+54) = 39.
Therefore, 39 is returned as the output.

Well, I searched for it on the internet and I found lots of different. Python script to do this.
Can you try this script to get what you are looking for.

def maxPowerOfArray(N, A):
    # Initialize the result to store the maximum power
    max_power = 0

    # Iterate through the array
    for i in range(N - 1):
        # Find the maximum element in the remaining unprocessed subarray
        max_element = max(A[i:])
        
        # Find the index of the maximum element
        max_index = A.index(max_element)
        
        # Swap the maximum element with its adjacent element
        A[i], A[max_index] = A[max_index], A[i]
        
        # Update the maximum power
        max_power += A[i] * i

    # Calculate the power for the last element
    max_power += A[N - 1] * (N - 1)

    return max_power

# Example usage:
N = 4
A = [2, 4, 5, 3]
result = maxPowerOfArray(N, A)
print(result)  # Output: 39

Thanks