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):
def BubbleSort(A, N):
    flag = 1
    while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j]['value']<A[j-1]['value']:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
    return A

def SelectionSort(A, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[i]['value']<A[j]['value']:
                minj = j
        if i!=minj:
            A[i], A[minj] = A[minj], A[i]
    return A

def IsStable(answer, target):
    N = len(answer)
    for i in range(N):
        if answer[i]['value'] != target[i]['value']:
            return False
    return True

# Stable Sort
N = int(input())
A = list(
    map(lambda x: {'body': x, 'value': int(x[1])}, input().split())
)
bubble = BubbleSort(A, N)
selection = SelectionSort(A, N)
print(' '.join(map(lambda x: x['body'],bubble)))
print('Stable')
print(' '.join(map(lambda x: x['body'], selection)))
if IsStable(bubble, selection):
    print('Stable')
else:
    print('Not stable')


Fixed, accepted submission:
import time
import copy

def BubbleSort(A, N):
    flag = 1
    while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j]['value']<A[j-1]['value']:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
    return A

def SelectionSort(A, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j]['value']<A[minj]['value']:
                minj = j
        if i!=minj:
            A[i], A[minj] = A[minj], A[i]
    return A

def IsStable(answer, target):
    N = len(answer)
    for i in range(N):
        if answer[i]['body'] != target[i]['body']:
            return False
    return True

# Stable Sort
def main():
    N = int(input())
    A = list(
        map(lambda x: {'body': x, 'value': int(x[1])}, input().split())
    )
    A_sortby_bubble = copy.deepcopy(A)
    A_sortby_select = copy.deepcopy(A)
    A_sortby_bubble = BubbleSort(A_sortby_bubble, N)
    A_sortby_select = SelectionSort(A_sortby_select, N)
    print(' '.join(map(lambda x: x['body'],A_sortby_bubble)))
    print('Stable')
    print(' '.join(map(lambda x: x['body'], A_sortby_select)))
    if IsStable(A_sortby_bubble, A_sortby_select):
        print('Stable')
    else:
        print('Not stable') 
    
main()