Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
def selectionSort(n, A):
    cnt = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if A[minj][1] > A[j][1]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    return A


def bubbleSort(n, A):
    flag = True
    cnt = 0
    while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if A[j - 1][1] > A[j][1]:
                A[j - 1], A[j] = A[j], A[j - 1]
                cnt += 1
                flag = True
    return A


def stableSort(input, output):
    n = len(input)
    for i in range(n):
        for j in range(i + 1, n):
            for a in range(n):
                for b in range(a + 1, n):
                    if input[i][1] == input[j][1] and input[i] == output[b] and input[j] == output[a]:
                        return print("Stable")
    return print("Not stable")


if __name__ == '__main__':
    n = int(input())
    R = list(map(str, input().split()))
    C = R[:]
    SR = selectionSort(n, R)
    BR = bubbleSort(n, C)
    print(*BR)
    stableSort(R,BR)
    print(*SR)
    stableSort(R,SR)

# Example run
# Input:
-1
AW?(&
# Output:
AW?(&
Not stable
AW?(&
Not stable
def main():
    N = int(input())
    CARD = tuple(input().split())

    sort_ = []
    for i in range(1, 10):
        for s in CARD:
            if str(i) in s:
                sort_.append(s)

    sort_ = tuple(sort_)
    bsort = tuple(bubbleSort(list(CARD), N))
    ssort = tuple(selectionSort(list(CARD), N))

    for s in (bsort, ssort):
        print(*s, sep=' ')
        if s == sort_:
            print('Stable')
        else:
            print('Not stable')

def bubbleSort(c, n):
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c

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

main()

# Example run
# Input:
-5310
-16
# Output:
-16
Not stable
-16
Not stable
def makedic(array):
    dic = {str(i): '' for i in range(10)}
    for v in array:
        dic[v[1]] += v[0]
    return dic


def main():
    n = int(input())
    origin = [v for v in input().split()]
    dic_origin = makedic(origin)

    a = origin[:]
    for i in range(n - 1):
        last = n - i - 1
        for j in range(last):
            if int(a[j][1]) > int(a[j + 1][1]):
                a[j], a[j + 1] = a[j + 1], a[j]

    print(' '.join(a))
    print('Stable' if makedic(a) == dic_origin else 'Not Stable')

    b = origin[:]
    for i in range(n):
        m = i
        for j in range(i + 1, n):
            if int(b[j][1]) < int(b[m][1]):
                m = j

        if not m == i:
            b[m], b[i] = b[i], b[m]

    print(' '.join(b))
    print('Stable' if makedic(b) == dic_origin else 'Not stable')


if __name__ == '__main__':
    main()








# Example run
# Input:
-3
24
# Output:
24
Stable
24
Stable
def bubble_sort(a, n):
    for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j]['value'] < a[j - 1]['value']:
                tmp = a[j]
                a[j] = a[j - 1]
                a[j - 1] = tmp


def selection_sort(a, n):
    is_stable = True

    for i in range(n):
        minj = i
        samei = n
        for j in range(i, n, 1):
            if a[j]['value'] == a[i]['value']:
                samei = j
            if a[j]['value'] < a[minj]['value']:
                minj = j
                if samei < minj:
                    is_stable = False
        tmp = a[i]
        a[i] = a[minj]
        a[minj] = tmp

    return is_stable

def print_list_split_whitespace(a):
    for x in a[:-1]:
        print(x['design'] + str(x['value']), end=' ')
    print(a[-1]['design'] + str(a[-1]['value']))


n = int(input())

a = input().split()
for i in range(n):
    s = a[i]
    a[i] = {'design': s[0], 'value': int(s[1])}
b = a.copy()
c = a.copy()

bubble_sort(a, n)
print_list_split_whitespace(a)

print("Stable")

is_stable = selection_sort(b, n)
print_list_split_whitespace(b)

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


# Example run
# Input:
1
e8YVK$.
# Output:
e8
Stable
e8
Stable
def BubbleSort(C,N):
    for i in range(N):
        for j in reversed(range(i+1,N)):
            if C[j][1] < C[j-1][1]:
                sw = C[j]
                C[j] = C[j-1]
                C[j-1] = sw
    print(" ".join(C))

def SelectionSort(C,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if C[j][1] < C[minj][1]:
                minj = j
        sw = C[i]
        C[i] = C[minj]
        C[minj] = sw
    print(" ".join(C))

n = int(input())
cardlistB = [x for x in input().split()]
cardlistS = []

for c in cardlistB:
    cardlistS.append(c)

BubbleSort(cardlistB,n)

print("Stable")

SelectionSort(cardlistS,n)

if cardlistB == cardlistS:
    print("Stable")
else:
    print("Not stable")


# Example run
# Input:
-507526654
YQocc[TJS
# Output:
YQocc[TJS
Stable
YQocc[TJS
Stable
import copy

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

bubble = copy.copy(a)
for i in range(n):
    for j in reversed(range(i+1,n)):
        if bubble[j][1] < bubble[j-1][1]:
            bubble[j],bubble[j-1] = bubble[j-1],bubble[j]

insertion = copy.copy(a)
for i in range(n):
    minj = i
    for j in range(i,n):
        if insertion[j][1] < insertion[minj][1]:
            minj = j
    insertion[i],insertion[minj] = insertion[minj],insertion[i]

print(' '.join(bubble))
print('Stable')
print(' '.join(insertion))
if tuple(bubble) != tuple(insertion):
    print('Not stable')
else:
    print('Stable')


# Example run
# Input:
-13840614
Ju.
# Output:
Ju.
Stable
Ju.
Stable
def selection(l):
	N = len(l)

	for i in range(N):
		minj = i

		for j in range(i, N):
			if int(l[j][1]) < int(l[minj][1]):
				minj = j
		if i == minj:
			continue
		else:
			l[i], l[minj] = l[minj], l[i]

	return l


def bubble(l):
	N = len(l)
	flag = 1

	while flag:
		flag = 0
		for j in range(N - 1, 1 - 1, -1):
			if int(l[j][1]) < int(l[j - 1][1]):
				l[j], l[j + 1] = l[j + 1], l[j]
				flag = 0

	return l


def output(lists):
	count = 0
	leng = len(l)
	for i in l:
		count += 1
		if count < leng:
			print(i, end =' ')
		else:
			print(i)




if __name__ == '__main__':
	n = int(input())
	l = input().split()

	l_1 = bubble(l[:])
	l_2 = selection(l[:])
	output(l_1)
	print("Stable")
	output(l_2)
	if l_1 == l_2:
		print("Stable")
	else:
		print("Not stable")



# Example run
# Input:
1969909
-112
# Output:
-112
Stable
-112
Stable
import copy

def printData(data) :
    for i, value in enumerate(data) :
        if i > 0 :
            print(" ", end = "")
        print(value[0] + str(value[1]), end = "")
    print()
    
def isStable(data1, data2) :
    for v1, v2 in zip(data1, data2) :
        if v1[0] != v2[0] :
            return "Not stable"
    return "Stable"

def bubbleSort(data, N) :
    flag = 1
    for i in range(N) :
        if not flag :
            break
        flag = 0
        for j in reversed(range(i + 1, N)) :
            if data[j][1] < data[j - 1][1] :
                buf = data[j]
                data[j] = data[j - 1]
                data[j - 1] = buf
                flag = 1
    printData(data)
    print("Stable")
    
def selectionSort(data, N) :
    for i in range(N) :
        minIdx = i
        for j in range(i + 1, N) :
            if data[j][1] < data[minIdx][1] :
                minIdx = j
        if minIdx != i :
            buf = data[minIdx]
            data[minIdx] = data[i]
            data[i] = buf
    printData(data)


N = int(input())
data = [list(value) for value in input().split()]
for value in data :
    value[1] = int(value[1])
    
copy_data1 = copy.deepcopy(data)
bubbleSort(copy_data1, N)
copy_data2 = copy.deepcopy(data)
selectionSort(copy_data2, N)
print(isStable(copy_data1, copy_data2))




# Example run
# Input:
-84
-199220713
# Output:
-1
Stable
-1
Stable
N = int(input())
A = list(input().split(" "))

class Card:
    def __init__(self,suit,num):
        self.suit = suit
        self.value = int(num)
        self.id = suit+num
        
    

B_bubble = [Card(a[0],a[1])for a in A]
B_selection = [b for b in B_bubble]

B_id = [b.id for b in B_bubble]

def BubbleSort(C,N):
    for i in range(N):
        for j in range(N-1,i,-1):
            if C[j].value < C[j-1].value:
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
        #print([b.id for b in C])
    return C
    
def SelectionSort(C, N):
    for i in range(N):
      minj = i
      for j in range(i,N):
        if C[j].value < C[minj].value:
          minj = j
      tmp = C[i]
      C[i] = C[minj]
      C[minj] = tmp
      #print([b.id for b in C])
    return C

def stable_check(B_id,C_id):
    tmp = C_id[0]
    for i in range(1,len(C_id)):
        c = C_id[i]
        if c[1]!=tmp[1]:
            tmp = c
            continue
        if B_id.index(tmp)>B_id.index(c):
            return "Not stable" 
        tmp = c
    return "Stable"
    

C_bubble =  [b.id for b in BubbleSort(B_bubble,N)]
print(" ".join(C_bubble))
#C_bubble_id = [b.id for b in C_bubble]
print(stable_check(B_id,C_bubble))

C_selection =  [b.id for b in SelectionSort(B_selection,N)]
print(" ".join(C_selection))
#C_selection_id = [b.id for b in C_selection]
print(stable_check(B_id,C_selection))




# Example run
# Input:
-8951
11
# Output:
11
Stable
11
Stable
def bubbleSort(c,n):
    for i in range(n):
        for j in range(i+1,n)[::-1]:
            if int(c[j-1][1]) > int(c[j][1]): c[j],c[j-1] = c[j-1],c[j]
    return

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

def isStable(inp,outp,n):
    for i in range(n):
        for j in range(i+1,n):
            for k in range(n):
                for l in range(k+1,n):
                    if all((inp[i][1] == inp[j][1],inp[i] == outp[l],inp[j] == outp[k])): return False
    return True

if __name__ == "__main__":
    n = int(input())
    lst = [i for i in input().split()]
    a = lst[:]
    b = lst[:]
    bubbleSort(a,n)
    print(" ".join(a))
    print("Stable" if isStable(lst,a,n) else "Not stable")
    selectionsSort(b,n)
    print(" ".join(b))
    print("Stable" if isStable(lst,b,n) else "Not stable")


# Example run
# Input:
-1
hd](
# Output:
hd](
Stable
hd](
Stable
#coding:utf-8
#1_2_C

def BubbleSort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards

def SelectionSort(cards, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if cards[minj][1] > cards[j][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
    return cards

n = int(input())
cardsR = input().split()
cardsS = cardsR[:]

print(BubbleSort(cardsR, n))
print("Stable")
print(SelectionSort(cardsS, n))
print("Stable" if cardsR == cardsS else "Not stable")

# Example run
# Input:
-17
t%Q
# Output:
['t%Q']
Stable
['t%Q']
Stable
import copy
def BubbleSort(C, N) :
    for i in range(N-1) :
        for j in range(N-1, i, -1) :
            if C[j][1] < C[j-1][1] :
                C[j], C[j-1] = C[j-1], C[j]
    return(C)

def SelectionSort(C, N) :
    for i in range(N) :
        minj = i
        for j in range(i, N) :
            if C[j][1] < C[minj][1] :
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return(C)

def Stable(A, B, N) :
    for i in range(N) :
        for j in range(i+1, N) :
            for a in range(N) :
                for b in range(a+1, N) :
                    if A[i][1] == A[j][1] and A[i] == B[b] and A[j] == B[a] :
                        return "false"
    return "true"

N = int(input())
OrgC = list(map(str, input().split()))
BubC = copy.copy(OrgC)
SelC = copy.copy(OrgC)
print(" ".join(BubbleSort(BubC, N)))
if Stable(OrgC, BubC, N) == "false" :
    print("Not stable")
else :
    print("Stable")

print(" ".join(SelectionSort(SelC, N)))
if Stable(OrgC, SelC, N) == "false" :
    print("Not stable")
else :
    print("Stable")




# Example run
# Input:
-117864
i97lD
# Output:
i97lD
Stable
i97lD
Stable
N = int(input())
C1 = input().split()
C2 = [i for i in C1]


def cVal(s):
    return int(s[1])


def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if cVal(C[j]) < cVal(C[j - 1]):
                C[j], C[j - 1] = C[j - 1], C[j]


def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if cVal(C[j]) < cVal(C[minj]):
                minj = j
        C[i], C[minj] = C[minj], C[i]


def isStable(C1, C2):
    for i1, i2 in zip(C1, C2):
        if i1 != i2:
            return False
    return True

BubbleSort(C1, N)
print(' '.join(C1))
print('Stable')

SelectionSort(C2, N)
print(' '.join(C2))
ans = 'Stable' if isStable(C1, C2) else 'Not stable'
print(ans)


# Example run
# Input:
-213
\a&K8&(#
# Output:
\a&K8&(#
Stable
\a&K8&(#
Stable
N = int(input())
buble_A = list(map(str,input().split()))
selection_A=list(buble_A)
number=str(''.join(buble_A))
number=list(number[1::2])
number=[int(x) for x in number]
num_B=list(number)
num_S=list(number)

#バブルソート
flg=1
while flg:
    flg=0
    for i in range(N-1,0,-1):
        if num_B[i]<num_B[i-1]:
            num_B[i],num_B[i-1]=num_B[i-1],num_B[i]
            buble_A[i],buble_A[i-1]=buble_A[i-1],buble_A[i]
            flg=1

#選択ソート
for i in range(N-1):
    minj=i
    for j in range(i,N):
        if num_S[j]<num_S[minj]:
            minj=j
    if minj != i:
        num_S[i],num_S[minj]=num_S[minj],num_S[i]
        selection_A[i],selection_A[minj]=selection_A[minj],selection_A[i]

[print(buble_A[x],end=' ') for x in range(N-1)];print(buble_A[N-1]);print('Stable')

[print(selection_A[x],end=' ') for x in range(N-1)];print(selection_A[N-1]); print('Stable') if buble_A == selection_A else print('Not stable')



# Example run
# Input:
0
33729406
# Output:
33729406
Stable
33729406
Stable
n=int(input())
r=input().split()

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

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

l=list(r)
a=BubbleSort(l, n)
print(*a)
print('Stable')
l=list(r)
b=SelectionSort(l, n)
print(*b)
if a==b:
    print('Stable')
else:
    print('Not stable')


# Example run
# Input:
-136
s,NJmmu.E
# Output:
s,NJmmu.E
Stable
s,NJmmu.E
Stable
# ALDS1_2_C: Stable Sort
N = int(input())
A = input().split()

#N = 5
#A = "H4 C9 S4 D2 C3".split()

#N = 2
#A = "S1 H1".split()

def insertionSort(A, N):
    #print(" ".join(map(str, A)))
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and int(A[j][1]) > int(v[1]):
            A[j+1] = A[j]
            j = j - 1
        A[j+1] = v
    #print(" ".join(map(str, A)))
    return " ".join(map(str, A))
    
stablesort = insertionSort(A.copy(), N)

def bubbleSort(A, N):
    flag = True
    i = 0
    while(flag):
        flag = False
        for j in reversed(range(1, N)):
            if int(A[j][1]) < int(A[j-1][1]):                
                A[j], A[j-1] = A[j-1], A[j]
                flag = True
                i += 1
                #print(A)
    print(" ".join(map(str, A)))
    #print(i)
    return " ".join(map(str, A))
    
bubble = bubbleSort(A.copy(), N)
if bubble == stablesort:
    print("Stable")
else:
    print("Not stable")

def selectionSort(A, N):
    e = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            e += 1
            #print(A)
    print(" ".join(map(str, A)))
    #print(e)
    return " ".join(map(str, A))
    
selection = selectionSort(A.copy(), N)
if selection == stablesort:
    print("Stable")
else:
    print("Not stable")



# Example run
# Input:
-2239572
>l'~vkX
# Output:
>l'~vkX
Stable
>l'~vkX
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:
0
-x4d
# Output:
-x4d
Stable
-x4d
Stable
#! /usr/bin/python
# -*- coding: utf-8 -*-
# ALDS1_2_C: Stable Sort

import copy

def BubbleSort(A, N):
    minj = 0
    tmp = 0
    flag = 1

    for i in range(1, N):
        for j in reversed(range(i, N)):
            if A[j][1] < A[j-1][1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
    # while flag:
    #     flag = 0    #数値の転倒があることを表すflagを定義
    #     for i in range(1, N):
    #         j = N - i   #末尾から見ていくための変数jを定義
    #         if A[j][1] < A[j-1][1]:   #転倒があるとき
    #             tmp = A[j]  #この行から下の2行目までで、転倒のある部分を入れ替える
    #             A[j] = A[j-1]
    #             A[j-1] = tmp
    #             flag = 1    #転倒があったことを表すflagを立てる。1度入れ替えたところで他にも入れ替えの必要がある要素がある可能性はあるので、そのためのフラグ。
    return A

def SelectionSort(A, N):
    minj = 0
    tmp = 0
    flag = 1
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j][1] < A[minj][1]:  #一番小さい要素よりも小さいものを記憶する
                minj = j
        tmp = A[i]  #一番小さい要素とi番目の要素を入れ替え
        A[i] = A[minj]
        A[minj] = tmp
        
    return A

def isStable(list1, list2, N):
    for i in range(0, N):
        if list1[i][0] != list2[i][0]:
            print("Not stable")
            return 0
    print("Stable")
    return 0

if __name__ == "__main__":
    N=int(input()) # 数列の長さ
    A=list(input().split()) # 空白を区切文字として配列に格納
    L1 = copy.deepcopy(A)
    L2 = copy.deepcopy(A)
    # print(id(L1), id(L2))
    A1 = BubbleSort(L1, N)
    A2 = SelectionSort(L2, N)
    print(*A1)
    print("Stable")
    print(*A2)
    isStable(A1, A2, N)
    
    


# Example run
# Input:
-195933
-jl[<}:
# Output:
-jl[<}:
Stable
-jl[<}:
Stable
n = int(input())
*A, = input().split()
B = A[:]
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(*A)
print("Stable")

for i in range(n):
    mj = i
    for j in range(i, n):
        if B[j][1] < B[mj][1]:
            mj = j
    B[i], B[mj] = B[mj], B[i]
print(*B)
if A == B:
    print("Stable")
else:
    print("Not stable")


# Example run
# Input:
-1140169349
/TI
# Output:
/TI
Stable
/TI
Stable
import copy


def BubbleSort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C


def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C


n = int(input())
c = input().split()
b = BubbleSort(copy.deepcopy(c), n)
print(" ".join(b))
print("Stable")
s = SelectionSort(copy.deepcopy(c), n)
print(" ".join(s))
if b == s:
    print("Stable")
else:
    print("Not stable")




# Example run
# Input:
-30
dI*Lez,sS
# Output:
dI*Lez,sS
Stable
dI*Lez,sS
Stable
#coding:utf-8
from copy import deepcopy

n = int(input())
A = list(input().split())
B = deepcopy(A)


def BubbleSort(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]


def SelectionSort(A,N):
    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]
        
                
BubbleSort(A,n)
SelectionSort(B,n)
A = " ".join([data for data in A])
B = " ".join([data for data in B])

print(A)
print("Stable")

print(B)
if A == B:
    print("Stable")
else:
    print("Not stable")



# Example run
# Input:
-8056
=^6jj+C
# Output:
=^6jj+C
Stable
=^6jj+C
Stable
#coding:UTF-8
def BS(N,A):
    for i in range(N):
        for j in reversed(range(i+1,N)):
            if int(A[j][1:])<int(A[j-1][1:]):
                swap=A[j]
                A[j]=A[j-1]
                A[j-1]=swap
    return A

def SS(N,A):
    for i in range(N):
        minj=i
        for j in range(i,N):
            if int(A[j][1:]) < int(A[minj][1:]):
                minj=j
        
        swap=A[i]
        A[i]=A[minj]
        A[minj]=swap
    return A

def Stable(A1,A2):
    ans="Stable"
    for i in range(len(A1)):
        if A1[i][1:]==A2[i][1:] and A1[i][:1]!=A2[i][:1]:
            ans="Not stable"
    return ans

def SS2(N,A,B):
    print(A,B)
    A1=BS(N,A)
    print(" ".join(A1))
    print("Stable")
    A2=SS(N,B)
    print(" ".join(A2))
    print(Stable(A1,A2))

if __name__=="__main__":
    N=int(input())
    a=input()
    A=a.split(" ")
    B=a.split(" ")
    SS2(N,A,B)

# Example run
# Input:
-14611
YVxv>z%!
# Output:
['YVxv>z%!'] ['YVxv>z%!']
YVxv>z%!
Stable
YVxv>z%!
Stable
import copy


def bubble(_v):
    v = copy.copy(_v)
    n = len(v)
    for i in range(n):
        for j in range(n-1, i, -1):
            if v[j][1] < v[j-1][1]:
                v[j], v[j-1] = v[j-1], v[j]
    return v


def selection(_v):
    v = copy.copy(_v)
    n = len(v)
    for i in range(n):
        mi = i
        for j in range(i, n):
            if v[j][1] < v[mi][1]:
                mi = j
        v[i], v[mi] = v[mi], v[i]
    return v


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

b = bubble(v)
s = selection(v)
print(" ".join(b))
print("Stable")
print(" ".join(s))
print("Stable" if b == s else "Not stable")



# Example run
# Input:
1822393017
CpNZdu
# Output:
CpNZdu
Stable
CpNZdu
Stable
def bubble_sort(A):
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -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):
    n = len(A)
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A

n = int(input())
A = input().split()
B = bubble_sort(A)
C = selection_sort(A)
print(' '.join(B))
print('Stable')
print(' '.join(C))
if B == C:
    print('Stable')
else:
    print('Not stable')



# Example run
# Input:
-110923
13499019
# Output:
13499019
Stable
13499019
Stable
def bubble_sort(card_list):
    cards = [i for i in card_list]
    list_length = len(cards)

    for i in range(list_length):
        for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
    return cards

def selection_sort(card_list):
    cards = [i for i in card_list]

    list_length = len(cards)

    for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
        cards[i],cards[min_element] = cards[min_element],cards[i]
    return cards

n = int(input())
cards = input().split()
bubble_cards = bubble_sort(cards)
selection_cards = selection_sort(cards)

print(' '.join(bubble_cards))
print('Stable')
print(' '.join(selection_cards))
if bubble_cards == selection_cards:
    print('Stable')
else:
    print('Not stable')


# Example run
# Input:
10823
^h0
# Output:
^h0
Stable
^h0
Stable