Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp
#??????????????????
#??????????????????????°???????????????£?????´???????????´?????¨??\?????????????????????????????????????????´????????????
#??????????????????????????????????°????????????????????????´???????????????????????????????????????????????¨??????

def bubble_sort(origin_list):
    list_length = len(origin_list)
    target_list = [i for i in origin_list]#??°????????????????????????
    flag = True
    change_count = 0
    top_index = 1
    while flag:
        flag = False
        for i in range(top_index, list_length)[::-1]:
            if target_list[i][1] < target_list[i - 1][1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
        top_index += 1       
    return target_list

def selection_sort(origin_list):
    list_length = len(origin_list)
    target_list = [i for i in origin_list]#??°????????????????????????
    change_count = 0
    for i in range(list_length):
        min_index = i
        for j in range(i, list_length):
            if target_list[j][1] < target_list[min_index][1]:
                min_index = j
        else:
            if not i == min_index:
                tmp = target_list[i]
                target_list[i] = target_list[min_index]
                target_list[min_index] = tmp
                change_count += 1
    return target_list

def check_stable(origin_list, target_list):
    for i, origin_v in enumerate(origin_list):
        for origin_v2 in origin_list[i+1:]:
            if origin_v[1] == origin_v2[1]:
                for j, target_v in enumerate(target_list):
                    for target_v2 in target_list[j+1:]:
                        if origin_v == target_v2 and origin_v2 == target_v:
                            return False
    return True

def stable_sort(target_list):
    print(*bubble_sort(target_list))
    print(check_stable(target_list, bubble_sort(target_list)))
    print(*selection_sort(target_list))
    print(check_stable(target_list, selection_sort(target_list)))
    
def main():
    n_list = int(input())
    target_list = [a for a in input().split()]
    stable_sort(target_list)
    
if __name__ == "__main__":
    main()

# Example run
# Input:
-5992
O1x'fWL]]
# Output:
O1x'fWL]]
True
O1x'fWL]]
True
# coding: utf-8
# Your code here!

def bubble_sort(A):
    for i in range(len(A)):
        flag = 1
        while flag:
            flag = 0
            for j in range(len(A)-1, i, -1):
                if A[j][1] < A[j-1][1]:
                    A[j], A[j-1] = A[j-1], A[j]
                    flag = 1
    return A

def sentaku_sort(A):
    for i in range(len(A)):
        min_n = i
        for j in range(i+1, len(A)):
            if A[j][1] < A[min_n][1]:
                min_n = j
        if min_n != i:
            A[i], A[min_n] = A[min_n], A[i]
    return A

def isStable(A, B):
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            for a in range(len(A)):
                for b in range(a+1, len(A)):
                    if A[i][1] == A[j][1] and A[i] == B[b] and A[j] == B[a]:
                        return False
    return True
    

def hyoji(A):
    for i in range(len(A)):
        if i != len(A)-1:
            print(A[i], end = ' ')
        else:
            print(A[i])


n = int(input())
A = input().split()

B = bubble_sort(A[:])
hyoji(B)
if isStable(A, B):print('Stable')
else:print('Not stable')

C = sentaku_sort(A[:])
hyoji(C)
if isStable(A, C):print('Stable')
else:print('Not stable')



# Example run
# Input:
743812855
H(J]}^?
# Output:
H(J]}^?
Stable
H(J]}^?
Stable
n = int(input())
clist = list(map(list, input().split()))

def BubbleSort(C, n):
    for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j][1] < C[j-1][1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a
def SelectionSort(C, n):
    for i in range(n):
        mini = i
        for j in range(i+1,n):
            if (C[j][1] < C[mini][1]):
                mini = j
        if(mini != i):
            a = C[i]
            C[i] = C[mini]
            C[mini] = a
## l[1]이 str 이라는것에 주의 int(l[1])을 해줘야함 --> 이거 때문에 20분 디버깅 소비
def stable(A,B):
    count = [0 for i in range(9)]
    for l in A:
        count[int(l[1]) - 1] += 1
    ilist = [] ##安定なiのリスト
    for i in range(1,10):
        if (count[i-1] > 1):
            awlist = []
            for l in A:
                if(int(l[1]) == i):
                    awlist.append(l[0])
            bwlist = []
            for l in B:
                if(int(l[1]) == i):
                    bwlist.append(l[0])
            if (awlist == bwlist):
                ilist.append(i)
            
        else:
            ilist.append(i)
    if (len(ilist) == 9):
        print('Stable',end = '')
    else:
        print('Not stable', end = '')
                  

Blist = list(clist)
BubbleSort(Blist, n)
for i in range(n):
    if (i == n-1):
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = '')
    else : 
        print('{}{}'.format(Blist[i][0],Blist[i][1]), end = ' ')
print()
stable(clist, Blist)
print()

Slist = list(clist)
SelectionSort(Slist, n)
for i in range(n):
    if(i == n-1):
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = '')
    else:
        print('{}{}'.format(Slist[i][0],Slist[i][1]), end = ' ')
print()
stable(clist, Slist)
print()


# Example run
# Input:
-1504387
31
# Output:

Stable

Stable
N = int(input())
l = [list(i) for i in input().split()]

a = l.copy()
frag = 1
i = 0
while frag:
    frag = 0
    for j in range(N-1,i,-1):
        if a[j][1] < a[j-1][1]:
            a[j], a[j-1] = a[j-1], a[j]
        frag = 1
    i += 1 
bubble_a = ["".join(a[i]) for i in range(N)]
print(" ".join(bubble_a))
print("Stable")

a = l.copy()
for i in range(N):
    minj = i
    for j in range(i,N):
        if a[j][1] < a[minj][1]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
selection_a = ["".join(a[i]) for i in range(N)]
print(" ".join(selection_a))

if bubble_a == selection_a:
    print("Stable")
else:
    print("Not stable")

# Example run
# Input:
-487
$~,2x
# Output:

Stable

Stable
class Cards:
    def __init__(self,shape,value):
        self.shape = shape
        self.value = value

n = int(input())
s = input().split(" ")
cards1 = []
for i in range(n):
    cards1.append(Cards(s[i][0],int(s[i][1])))
cards2 = list(cards1)
for i in range(n):
    for j in range(n-1,i,-1):
        if cards1[j].value < cards1[j-1].value:
            w = cards1[j]
            cards1[j] = cards1[j-1]
            cards1[j-1] = w
for i in range(n):
    if i == n-1:
        print("{0}{1}".format(cards1[i].shape,cards1[i].value))
    else:
        print("{0}{1}".format(cards1[i].shape,cards1[i].value),end=" ")
print("Stable")

for i in range(n):
    minj = i
    for j in range(i+1,n):
        if cards2[j].value < cards2[minj].value:
            minj = j
    w = cards2[i]
    cards2[i] = cards2[minj]
    cards2[minj] = w
for i in range(n):
    if i == n-1:
        print("{0}{1}".format(cards2[i].shape,cards2[i].value))
    else:
        print("{0}{1}".format(cards2[i].shape,cards2[i].value),end=" ")
for i in range(n):
    if cards1[i].shape != cards2[i].shape:
        print("Not stable")
        break
    if i == n-1:
        print("Stable")

# Example run
# Input:
-2608672
BL;sshZj
# Output:
Stable
N = int(input())
A = input().split()

def bubble_sort(A):
    for i in range(0, N):
        for j in range(i+1, N)[::-1]:
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    return A

def selection_sort(A):
    for i in range(0, N):
        min_i = i
        for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
        A[i], A[min_i] = A[min_i], A[i]
    return A

BA = bubble_sort(A[:])
SA = selection_sort(A[:])

print(' '.join([str(i) for i in BA]))
print('Stable')
print(' '.join([str(i) for i in SA]))
print('Stable' if SA == BA else 'Not stable')

# Example run
# Input:
-972
G]eR-
# Output:
G]eR-
Stable
G]eR-
Stable
#!/usr/bin/env python
# encoding: utf-8

import copy


class Solution:
    def stable_sort(self):
        # write your code here
        array_length = int(input())
        b_array = [str(x) for x in input().split()]
        s_array = copy.deepcopy(b_array)

        bubble_result = self.bubble_sort(b_array=b_array, array_length=array_length)
        selection_result = self.selection_sort(s_array=s_array, array_length=array_length)

        # check whether selection sort is stable
        if bubble_result == selection_result:
            print("Stable")
        else:
            print("Not stable")

    @staticmethod
    def selection_sort(s_array, array_length):
        # selection sort
        print('in2', s_array)
        selection_count = 0
        for i in range(array_length):
            min_j = i
            for j in range(i, array_length):
                if s_array[j][1] < s_array[min_j][1]:
                    min_j = j
            s_array[i], s_array[min_j] = s_array[min_j], s_array[i]
            if i != min_j:
                selection_count += 1

        result = " ".join(map(str, s_array))
        print(result)
        return result

    @staticmethod
    def bubble_sort(b_array, array_length):
        print('in1', b_array)
        flag, bubble_count, cursor = 1, 0, 0
        while flag:
            flag = 0
            for j in range(array_length - 1, cursor, -1):
                if b_array[j][1] < b_array[j - 1][1]:
                    b_array[j], b_array[j - 1] = b_array[j - 1], b_array[j]
                    flag = 1
                    bubble_count += 1
        cursor += 1
        result = " ".join(map(str, b_array))
        print(result)
        print("Stable")
        return result


if __name__ == '__main__':
    solution = Solution()
    solution.stable_sort()

# Example run
# Input:
-139093888
VLLU9,h&
# Output:
in1 ['VLLU9,h&']
VLLU9,h&
Stable
in2 ['VLLU9,h&']
VLLU9,h&
Stable
length = int(input())
eles = [l for l in input().split()]
is_stable = 'Stable'

import copy
_copy = copy.deepcopy(eles)

for i in range(length):
    for j in range(length-1, 0, -1):
        if _copy[j][1] < _copy[j-1][1]:
            _copy[j], _copy[j-1] = _copy[j-1], _copy[j]

print(*_copy)
print(is_stable)

__copy = copy.deepcopy(eles)

for i in range(length-1):
    _min = i
    for l in range(i, length):
        if __copy[l][1] < __copy[_min][1]:
            _min = l
    if __copy[i][1] < __copy[_min][1]:
        __copy[i], __copy[_min] = __copy[_min], __copy[i]
        is_stable = 'Not stable'

print(*__copy)
print(is_stable)

# Example run
# Input:
-227062494
/DJd,
# Output:
/DJd,
Stable
/DJd,
Stable
import copy
n = int(input())
a = input().split()
a_sr = []
a_sr_l = []
for i in range(n-1):
    if a[i][1] not in a_sr_l:
        for j in range(i+1, n):
            if a[i][1] == a[j][1]:
                if a[i][1] not in a_sr_l:
                    a_sr_l.append(a[i][1])
                if len(a_sr) == 0:
                    a_sr.append(a[i][0])
                a_sr.append(a[j][0])
a_b = copy.deepcopy(a)
a_s = copy.deepcopy(a)
# print(a)
# print(a1)
# print(a2)

# Bubble Sort
neighbor = True
while neighbor:
    neighbor = False
    for i in range(n-1, 0, -1):
        if a_b[i][1] < a_b[i-1][1]:
            a_tmp = a_b[i]
            a_b[i] = a_b[i-1]
            a_b[i-1] = a_tmp
            neighbor = True
for i in range(n-1):
    print(a_b[i], end=" ")
print(a_b[n-1])
a_b_s = []
a_b_s_l = []
for _ in a_sr_l:
    for i in range(n):
        if a_b[i][1] == _ and _ not in a_b_s_l:
            for j in range(i+1, n):
                if a_b[i][1] == a_b[j][1]:
                    if a_b[i][1] not in a_b_s_l:
                        a_b_s_l.append(a_b[i][1])
                    if len(a_b_s) == 0:
                        a_b_s.append(a_b[i][0])
                    a_b_s.append(a_b[j][0])

if a_b_s != a_sr:
    print("Not stable")
else:
    print("Stable")
# Selection Sort
# print(a_s)
for i in range(n-1):
    tmp_index = i
    for j in range(i+1, n):
        # 最小の値探索
        # print("# temp", tmp_index, "j", j)
        if a_s[j][1] < a_s[tmp_index][1]:
            tmp_index = j
    if tmp_index != i:
        # 最小と左端入れ替え
        a_tmp = a_s[i]
        a_s[i] = a_s[tmp_index]
        a_s[tmp_index] = a_tmp
for i in range(n-1):
    print(a_s[i], end=" ")
print(a_s[n-1])
a_s_s = []
a_s_s_l = []
for _ in a_sr_l:
    for i in range(n):
        if a_s[i][1] == _ and _ not in a_s_s_l:
            for j in range(i+1, n):
                if a_s[i][1] == a_s[j][1]:
                    if a_s[i][1] not in a_s_s_l:
                        a_s_s_l.append(a_s[i][1])
                    if len(a_s_s) == 0:
                        a_s_s.append(a_s[i][0])
                    a_s_s.append(a_s[j][0])
# print("a_s_s", a_s_s)
# print("a_sr", a_sr)
if a_s_s != a_sr:
    print("Not stable")
else:
    print("Stable")



# Example run
# Input:
0
"T?
# Output:
"T?
Stable
"T?
Stable
def bubble_sort(A, n):
	for i in range(n):
		for j in range(n-1, i, -1):
			if A[j][1] < A[j-1][1]:
				A[j], A[j-1] = A[j-1], A[j]

	print(' '.join(A))

def selection_sort(A, n):
	for i in range(n):
		minj = i
		for j in range(i, n):
			if A[j][1] < A[minj][1]:
				minj = j
		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	print(' '.join(A))

if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	B = A[:]

	bubble_sort(A, n)
	print('Stable')

	selection_sort(B, n)
	print('Stable' if A == B else 'Not stable')

# Example run
# Input:
-31591
4AQnh?
# Output:
4AQnh?
Stable
4AQnh?
Stable
num = int(input())
card_list = [x for x in input().split()]
origin = card_list[:]
card_list2 = origin[:]
cards = {x : int(x[1]) for x in card_list}

for i in range(num):
    for j in range(num-1, i, -1):
        if cards[card_list[j]] < cards[card_list[j-1]]:
            card_list[j], card_list[j-1] = card_list[j-1], card_list[j]
print(' '.join(card_list))
print('Stable')

for i in range(num):
    minj = i
    for j in range(i, num):
        if cards[card_list2[j]] < cards[card_list2[minj]]:
            minj = j
    card_list2[i], card_list2[minj] = card_list2[minj], card_list2[i]
print(' '.join(card_list2))

if card_list == card_list2:
    print('Stable')
else:
    print('Not stable')


# Example run
# Input:
-16371
-52564348
# Output:
-52564348
Stable
-52564348
Stable
#!/usr/bin/env python
# encoding: utf-8

import copy


class Solution:
    def stable_sort(self):
        # write your code here
        array_length = int(input())
        b_array = [str(x) for x in input().split()]
        s_array = copy.deepcopy(b_array)

        bubble_result = self.bubble_sort(b_array=b_array, array_length=array_length)
        selection_result = self.selection_sort(s_array=s_array, array_length=array_length)

        # check whether selection sort is stable
        if bubble_result == selection_result:
            print("Stable")
        else:
            print("Not Stable")

    @staticmethod
    def selection_sort(s_array, array_length):
        # selection sort
        print('in2', s_array)
        selection_count = 0
        for i in range(array_length):
            min_j = i
            for j in range(i, array_length):
                if s_array[j][1] < s_array[min_j][1]:
                    min_j = j
            s_array[i], s_array[min_j] = s_array[min_j], s_array[i]
            if i != min_j:
                selection_count += 1

        result = " ".join(map(str, s_array))
        print(result)
        return result

    @staticmethod
    def bubble_sort(b_array, array_length):
        print('in1', b_array)
        flag, bubble_count, cursor = 1, 0, 0
        while flag:
            flag = 0
            for j in range(array_length - 1, cursor, -1):
                if b_array[j][1] < b_array[j - 1][1]:
                    b_array[j], b_array[j - 1] = b_array[j - 1], b_array[j]
                    flag = 1
                    bubble_count += 1
        cursor += 1
        result = " ".join(map(str, b_array))
        print(result)
        print("Stable")
        return result


if __name__ == '__main__':
    solution = Solution()
    solution.stable_sort()

# Example run
# Input:
-274762050
BxX6cm
# Output:
in1 ['BxX6cm']
BxX6cm
Stable
in2 ['BxX6cm']
BxX6cm
Stable
def bubble_sort(array):
    n = len(array)

    while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1][1] > array[i][1]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
        if not flag:
            break
    return array

def selection_sort(array):
    n = len(array)

    for i in range(n):
        min_idx = i
        for j in range(i, n):
            if array[j][1] < array[min_idx][1]:
                min_idx = j
        if min_idx != i:
            tmp = array[i]
            array[i] = array[min_idx]
            array[min_idx] = tmp
    return array

def accum_hcsd_order(array):
    hcsd_order = {}
    for item in array:
        if item[1] in hcsd_order:
            hcsd_order[item[1]].append(item[0])
        else:
            hcsd_order[item[1]] = [item[0]]
    return hcsd_order


def check_stable(array, hcsd_order):
    tgt_hcsd_order = accum_hcsd_order(array)

    for no, hcsd in hcsd_order.items():
        if len(hcsd) == 1:
            continue
        tgt_hcsd = tgt_hcsd_order[no]
        for src, tgt in zip(hcsd, tgt_hcsd):
            if src != tgt:
                return False
    return True


def main():
    n = int(input())
    array = [(x[0], int(x[1:])) for x in input().split()]
    str_stable_or_not = {True: "Stable", False: "Not stable"}

    hcsd_order = accum_hcsd_order(array)

    # bubble_sort
    array_b = array[:]
    array_b = bubble_sort(array_b)
    print(" ".join(map(lambda x: "{}{}".format(x[0],x[1]), array_b)))
    print(str_stable_or_not[check_stable(array_b, hcsd_order)])

    # selection_sort
    array_s = array[:]
    array_s = selection_sort(array_s)
    print(" ".join(map(lambda x: "{}{}".format(x[0], x[1]), array_s)))
    print(str_stable_or_not[check_stable(array_s, hcsd_order)])

    return

main()


# Example run
# Input:
-305
-591
# Output:
-591
Stable
-591
Stable
def bubble_sort(A, n):
    A = A[:]
    flag = True
    while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if int(A[i][1:]) < int(A[i - 1][1:]):
                A[i], A[i - 1] = A[i - 1], A[i]
                flag = True
    return A


def selection_sort(A, n):
    A = A[:]
    for start in range(n):
        smallest_i = start
        smallest = A[smallest_i]
        for i in range(start, n):
            if int(A[i][1:]) < int(smallest[1:]):
                smallest_i = i
                smallest = A[smallest_i]
        A[start], A[smallest_i] = A[smallest_i], A[start]
    return A


def is_stable(ordered, original):
    for n in range(1, 10):
        f_original = filter(lambda c: int(c[1:]) == n, original)
        f_ordered = filter(lambda c: int(c[1:]) == n, ordered)
        for a, b in zip(f_ordered, f_original):
            if a != b:
                return False
    return True


n = int(input())
A = input().split()
bA = bubble_sort(A, n)
sA = selection_sort(A, n)
print(*bA, sep=" ")
print("Stable" if is_stable(bA, A) else "Not stable")
print(*sA, sep=" ")
print("Stable" if is_stable(sA, A) else "Not stable")



# Example run
# Input:
0
63
# Output:
63
Stable
63
Stable
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()


# Example run
# Input:
-52564348
-7737
# Output:
-7737
Stable
-7737
Stable
def bubble(A):
    flag = True
    n = len(A)
    i = 0
    while flag:
        flag = False
        for j in range(n-1,i,-1):
            if A[j][1] < A[j-1][1]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = True
        i += 1


def selection(A):
    n =len(A)
    for i in range(n):
        minj = i
        for j in range(i,n):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i],A[minj] = A[minj],A[i]

n = int(input())
ss = [x for x in input().split()]
ss2 = ss.copy()

bubble(ss)
for i in range(len(ss)-1):
    print(ss[i],end=" ")
print(ss[-1])
print('Stable')

selection(ss2)
for i in range(len(ss2)-1):
    print(ss2[i],end=" ")
print(ss2[-1])
if ss == ss2:
    print("Stable")
else:
    print("Not stable")


# Example run
# Input:
-1403621
c*]NA
# Output:
c*]NA
Stable
c*]NA
Stable
import copy

def bubble_sort(n, c):
  for i in range(n):
    for j in reversed(range(i + 1, n)):
      if int(c[j][1:]) < int(c[j - 1][1:]):
        c[j], c[j - 1] = c[j - 1], c[j]
  return c

def selection_sort(n, c):
  for i in range(n):
    minj = i
    for j in range(i, n):
      if int(c[j][1:]) < int(c[minj][1:]):
        minj = j
    if i != minj:
      c[i], c[minj] = c[minj], c[i]
  return c

n = int(input())
c = [i for i in input().split()]
c1 = bubble_sort(n, copy.copy(c))
c2 = selection_sort(n, copy.copy(c))

print(*c1)
print('Stable')
print(*c2)
print('Stable' if c1 == c2 else 'Not stable')



# Example run
# Input:
-8201172
V7Wg$RW
# Output:
V7Wg$RW
Stable
V7Wg$RW
Stable
STABLE = 'Stable'
UNSTABLE = 'Not stable'


def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(bubble_sorted)
  print(STABLE)

  print(select_sorted)
  print(stability)

  return 0


def order(card_sym):
  order = int(card_sym[1])
  return order


def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements


def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements


if __name__ == '__main__':
  main()

# Example run
# Input:
-1131247330
d=C>#:p
# Output:
['d=C>#:p']
Stable
['d=C>#:p']
Stable