Problem:
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1.  Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode:                 BubbleSort(C) 1 for i = 0 to C.length-1 2     for j = C.length-1 downto i+1 3         if C[j].value < C[j-1].value 4             swap C[j] and C[j-1]                 SelectionSort(C) 1 for i = 0 to C.length-1 2     mini = i 3     for j = i to C.length-1 4         if C[j].value < C[mini].value 5             mini = j 6     swap C[i] and C[mini]   Note that, indices for array elements are based on 0-origin.  For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = list(input().split())

A = []
A1 = []
A2 = []
for i in a:
    A.append(list(i))
    A1.append(list(i))
    A2.append(list(i))

# check stable or not
def is_stable(A3):
    for i in range( 1, n ):
        if int(A3[i-1][1]) == int(A3[i][1]):
            sm = i-1
            bg = i
            for j in range( n ):
                if ( A[j][0] == A3[sm][0]) & ( A[j][1] == A3[sm][1]):
                    t1 = j
                if ( A[j][0] == A3[bg][0]) & ( A[j][1] == A3[bg][1]):
                    t2 = j
            print(t1)
            print(t2)
            if t1 > t2:
                return "Not stable"
    return "Stable"


for i in range( n ):
    for j in range( n-1, i, -1 ):
        if int(A1[j][1]) < int(A1[j-1][1]):
            t = A1[j-1]
            A1[j-1] = A1[j]
            A1[j] = t

s = is_stable(A1)
print(*A1)
print(s)


# selection
for i in range( n ):
    minj = i
    for j in range( i+1, n ):
        if int(A2[j][1]) < int(A2[minj][1]):
            minj = j
    if minj != i:
        t = A2[i]
        A2[i] = A2[minj]
        A2[minj] = t

s = is_stable(A2)
print(*A2)
print(s)

Fixed, accepted submission:
import copy

N = int(input())
A = list(input().split())

def is_stable(sorted_list):
    for i in range(len(sorted_list)-1):
        if sorted_list[i][1] == sorted_list[i+1][1]:
            for j in range(len(A)):
                if A[j] == sorted_list[i]:
                    smaller_idx = j
                if A[j] == sorted_list[i+1]:
                    larger_idx = j
            if smaller_idx > larger_idx:
                return False
    return True

def print_stable_or_not(is_stable):
    if is_stable:
        print("Stable")
    else:
        print("Not stable")

def bubble_sort(A1):
    flg = True
    while flg:
        for i in range(N):
            flg = False
            for j in range(N-1, i, -1):
                if int(A1[j-1][1]) > int(A1[j][1]):
                    A1[j-1], A1[j] = A1[j], A1[j-1]
                    flg = True
    print(" ".join(A1))
    print_stable_or_not(is_stable(A1))

def insertion_sort(A2):
    for i in range(N-1):
        min_idx = i
        for j in range(i+1, N):
            if int(A2[min_idx][1]) > int(A2[j][1]):
                min_idx = j
        if min_idx != i:
            A2[i], A2[min_idx] = A2[min_idx], A2[i]
    print(" ".join(A2))
    print_stable_or_not(is_stable(A2))

if __name__ == '__main__':
    A1 = copy.deepcopy(A)
    A2 = copy.deepcopy(A)
    bubble_sort(A1)
    insertion_sort(A2)