Language: C++

import sys

# Rotate selected partial list and return the full list
def reorder(list, index, newIndex):
    tmp = list
    ind = -1
    if index > newIndex:
        tmp.insert(newIndex, list[index])
        tmp.pop(index + 1)
    if index < newIndex:
        tmp.insert(newIndex + 1, list[index])
        tmp.pop(index)

    # print(2,tmp)
    return tmp


# Calculate the distance a element from its original position
def distance(element, set):
    return element - set.index(element) - 1


# Calculate the cheapest way to make a rotation
## to rotate a list of k elements to the right once
## is the same as to rotate k-1 times to the left
def add_cost(bef, aft):
    global A
    global B

    max_rot = abs(aft-bef)

    if bef > aft:
        if B > max_rot * A:
            return max_rot * A
        else:
            return B
    else:
        if A > max_rot * B:
            return max_rot * B
        else:
            return A


# Get input and assign the proper variables
input = [int(i) for i in sys.stdin.readline().split("\n")[0].split(" ")]

N = input[0]
A = input[1]
B = input[2]

lst = [int(i) for i in sys.stdin.readline().split("\n")[0].split(" ")]

# Sorted list for comparison
reordered = [i for i in range(1, N+1)]

## moved is a list of numbers that were rotated
moved = []
cost = 0


# Repeat until the original list is sorted
while not lst == reordered:

    dist = 0
    dest = 5001
    dist_tmp = 0
    indexCur = -1
    indexNew = -1

    # Select the element that is the furthest
    for i in lst:
        if i not in moved:
            dist_tmp = abs(distance(i, lst))
            if dist_tmp > dist:
                indexCur = lst.index(i)
                dist = dist_tmp

    # Find where to put the selected element
    if not dist == 1:
        for k in lst:
            if not k == lst[indexCur]:
                dist_tmp = abs(distance(k, lst))
                if dist_tmp < dest:
                    indexNew = lst.index(k)
                    dest = dist_tmp
                    continue
                if dist_tmp == dest:
                    if k < lst[indexCur]:
                        indexNew = lst.index(k)
                        continue

    # Final Stage
    # There are only 0s and 1s left
    else:
        try:
            if distance(lst[indexCur + 1],lst) == -1:
                indexNew = indexCur + 1
        # Already moved the element with the highest distance [5,2,3,1,4]
        except:
            if distance(lst[indexCur - 1], lst) == 1:
                indexNew = indexCur - 1

    # Move element and count Cost
    moved.append(lst[indexCur])
    if not indexNew == -1 and not indexCur == indexNew:
        # print(lst[indexCur], indexNew, add_cost(indexCur, indexNew))
        lst = reorder(lst, indexCur, indexNew)
        # print(lst)
        cost += add_cost(indexCur, indexNew)

print(cost)

Compiler output:
a.cc:3:3: error: invalid preprocessing directive #Rotate
    3 | # Rotate selected partial list and return the full list
      |   ^~~~~~
a.cc:14:7: error: invalid preprocessing directive #print
   14 |     # print(2,tmp)
      |       ^~~~~
a.cc:18:3: error: invalid preprocessing directive #Calculate
   18 | # Calculate the distance a element from its original position
      |   ^~~~~~~~~
a.cc:23:3: error: invalid preprocessing directive #Calculate
   23 | # Calculate the cheapest way to make a rotation
      |   ^~~~~~~~~
a.cc:24:1: error: stray '##' in program
   24 | ## to rotate a list of k elements to the right once
      | ^~
a.cc:25:1: error: stray '##' in program
   25 | ## is the same as to rotate k-1 times to the left
      | ^~
a.cc:44:3: error: invalid preprocessing directive #Get
   44 | # Get input and assign the proper variables
      |   ^~~
a.cc:53:3: error: invalid preprocessing directive #Sorted
   53 | # Sorted list for comparison
      |   ^~~~~~
a.cc:56:1: error: stray '##' in program
   56 | ## moved is a list of numbers that were rotated
      | ^~
a.cc:61:3: error: invalid preprocessing directive #Repeat
   61 | # Repeat until the original list is sorted
      |   ^~~~~~
a.cc:70:7: error: invalid preprocessing directive #Select
   70 |     # Select the element that is the furthest
      |       ^~~~~~
a.cc:78:7: error: invalid preprocessing directive #Find
   78 |     # Find where to put the selected element
      |       ^~~~
a.cc:92:7: error: invalid preprocessing directive #Final
   92 |     # Final Stage
      |       ^~~~~
a.cc:93:7: error: invalid preprocessing directive #There
   93 |     # There are only 0s and 1s left
      |       ^~~~~
a.cc:98:11: error: invalid preprocessing directive #Already
   98 |         # Already moved the element with the highest distance [5,2,3,1,4]
      |           ^~~~~~~
a.cc:103:7: error: invalid preprocessing directive #Move
  103 |     # Move element and count Cost
      |       ^~~~
a.cc:106:11: error: invalid preprocessing directive #print
  106 |         # print(lst[indexCur], indexNew, add_cost(indexCur, indexNew))
      |           ^~~~~
a.cc:108:11: error: invalid preprocessing directive #print
  108 |         # print(lst)
      |           ^~~~~
a.cc:1:1: error: 'import' does not name a type
    1 | import sys
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'