Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
from copy import deepcopy

n = int(input())
ls = list(input().split())
C1 = []
for s in ls:
    C1.append((s[0], s[1]))
C2 = deepcopy(C1)


# bubble_sort: 2d
def bubble_sort(ls):
    n = len(ls)
    for _ in range(n):
        for j in range(n-1):
            if ls[j][1] > ls[j+1][1]:
                ls[j], ls[j+1] = ls[j+1], ls[j]
    return ls


# selection_sort: 2d
def selection_sort(ls):
    n = len(ls)
    for i in range(n):
        minj = i
        for j in range(i, n):
            if ls[j][1] < ls[minj][1]:
                minj = j
        if minj != i:
            ls[i], ls[minj] = ls[minj], ls[i]
    return ls


ans1 = []
ans2 = []
for c in bubble_sort(C1):
    ans1.append(c[0]+c[1])
for c in selection_sort(C2):
    ans2.append(c[0]+c[1])
print(*ans1)
print('Stable')
print(*ans2)
if ans1 == ans2:
    print('Stable')
else:
    print('Not stable')



# Example run
# Input:
1
VyGC
# Output:
Vy
Stable
Vy
Stable
#coding: UTF-8

import copy
class Algo:
  @staticmethod
  def bubbleSort(r, c, n):
    print(r)
    print(c)
    tmp_r, tmp_c = r, c
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if tmp_c[j] < tmp_c[j-1]:
          tmp_c[j], tmp_c[j-1] = tmp_c[j-1], tmp_c[j]
          tmp_r[j], tmp_r[j-1] = tmp_r[j-1], tmp_r[j]
          flag = 1
    return tmp_r

  def selectionSort(r, c, n):
    print(r)
    print(c)
    tmp_r, tmp_c = r, c
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if tmp_c[j] < tmp_c[minj]:
          minj = j
      if tmp_c[i] != tmp_c[minj]:
        tmp_c[i], tmp_c[minj] = tmp_c[minj], tmp_c[i]
        tmp_r[j], tmp_r[minj] = tmp_r[minj], tmp_r[j]
    return tmp_r

  def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

  def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="")

n = int(input())
r = list(map(str,input().split()))
c = Algo.createIntList(r, n)
br = Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n)
ir = Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n)
Algo.printList(br, n)
print("Stable")
Algo.printList(ir, n)
if br == ir:
  print("Stable")
else:
  print("Not stable")

# Example run
# Input:
-1
hd](
# Output:
['hd](']
[]
['hd](']
[]
Stable
Stable
"""ALDS1_2_C"""

from collections import namedtuple
from copy import deepcopy

Card = namedtuple("Card", ("suit", "value"))

def bubble(cards):
    cards = deepcopy(cards)
    N = len(cards)
    for i in range(N):
        for j in range(N-1, i, -1):
            if cards[j].value < cards[j-1].value:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards


def selection(cards):
    cards = deepcopy(cards)
    N = len(cards)
    for i in range(N):
        argmin = i
        for j in range(i, N):
            if cards[j].value < cards[argmin].value:
                argmin = j
        cards[i], cards[argmin] = cards[argmin], cards[i]
    return cards


def print_cards(cards):
    for i, card in enumerate(cards):
        end = "" if i == len(cards) - 1 else " "
        print(card.suit, card.value, sep="", end=end)
    print()


def main():
    _ = input()
    cards = [Card(i[0], int(i[1])) for i in input().split()]
    bubble_sorted = bubble(cards)
    selection_sorted = selection(cards)

    print_cards(bubble_sorted)
    print("Stable")
    print_cards(selection_sorted)
    if bubble_sorted == selection_sorted:
        print("Stable")
    else:
        print("Not stable")


if __name__ == "__main__":
    main()


# Example run
# Input:
diwp
-4
# Output:
-4
Stable
-4
Stable
import copy

class Card():
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value

def bubblesort(n,a):
    flag = 1
    while flag:
        flag = False
        for i in reversed(range(1,n)):
            if a[i-1].value > a[i].value:
                a[i], a[i-1] = a[i-1], a[i]
                flag = True
    return a

def selectionsort(n,a):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]
    return a

def is_stable(before, after):
    n = 9
    lb = [[] for _ in range(n)]
    la = [[] for _ in range(n)]
    for i in range(len(before)):
        lb[before[i].value-1].append(before[i].suit)
        la[after[i].value-1].append(after[i].suit)
    if la == lb:
        print('Stable')
    else:
        print('Not stable')


if __name__ == '__main__':
    n = int(input())
    cards = [Card(x[0], int(x[1])) for x in input().split()]

    bubble_cards = bubblesort(n, copy.deepcopy(cards))
    selection_cards = selectionsort(n, copy.deepcopy(cards))

    print(' '.join(map(lambda x: x.suit+str(x.value), bubble_cards)))
    is_stable(cards, bubble_cards)

    print(' '.join(map(lambda x: x.suit+str(x.value), selection_cards)))
    is_stable(cards, selection_cards)










# Example run
# Input:
-150069
470
# Output:
47
Stable
47
Stable
# coding: utf-8
# Here your code !
A = int(input())
N = tuple(input().split())
bs=[]
ss=[]
def isStable(a,b):
    leng = int(len(a))
    for i in range(leng):
        for j in range(i+1,leng):
            for x in range(leng):
                for y in range(x+1,leng):
                    if a[i][1]==a[j][1] and a[i]==b[x] and a[j]==b[y]:
                        return "Stable"
    return "Not Stable"
    
def bSort(n,a):
    n = list(n)
    for i in range(a):
        for j in range(a-1,i,-1):
            if int(n[j][1]) < int(n[j-1][1]):
                n[j],n[j-1]=n[j-1],n[j]
    return n
    #print(" ".join(n))

    
def seleSort(n,a):
    n = list(n)
    for i in range(a):
        minj = i
        for j in range(i+1,a):
            if n[j][1]<n[minj][1]:
                minj = j
                
        n[i],n[minj]=n[minj],n[i]
    return n
    #print(" ".join(n))

bs = bSort(N,A)
ss = seleSort(N,A)
print(" ".join(bs))
print(isStable(bs,bs))
print(" ".join(ss))
print(isStable(bs,ss))

# Example run
# Input:
-14
Bt~,E,/
# Output:
Bt~,E,/
Not Stable
Bt~,E,/
Not Stable
def isStable(inlist, outlist):
	flag = True
	for i in range(0, N):
		for j in range(i+1, N):
			for a in range(0, N):
				for b in range(a+1, N):
					if int(inlist[i][1:]) == int(inlist[j][1:]) and inlist[i] == outlist[b] and inlist[j] == outlist[a]:
						flag = False
						break
				else:
					continue
				break
			else:
				continue
			break
		else:
			continue
		break

	return(flag)
N = int(input())
A = input().split()
B = A[:]
C = A[:]

flag = 1
counter = 0
while flag:
    flag = 0
    for i in reversed(range(1,N)):
        if int(C[i][1:]) < int(C[i-1][1:]):
            C[i], C[i-1] = C[i-1], C[i]
            counter += 1
            flag = 1
print(" ".join(map(str, C)))

if(isStable(A, C)):
	print("Stable")
else:
	print("Not Stable")

counter=0
for i in range(N):
	Br = B[i:]
	Brr = [int(Br[j][1:]) for j in range(N-i)]
	num = Brr.index(min(Brr)) 
	if num != 0:
		B[i], B[(i+num)] = B[(i+num)], B[i]
		counter += 1
print(" ".join(map(str,B)))
if(isStable(A, B)):
	print("Stable")
else:
	print("Not Stable")

# Example run
# Input:
-224852
+Cav
# Output:
+Cav
Stable
+Cav
Stable
def isStable(before_sort, after_sort):
    num = len(before_sort)
    
    for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
    return True

def isStable2(sorted_data, bubble_sort_data):
    for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
    return True
    
def BubbleSort(c, n):
    for i in range(0, 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]

def SelectionSort(c, n):
    for i in range(0, 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]
    
num = int(input())
data = input().split(' ')

copy_data = data.copy()
BubbleSort(copy_data, num)
print(' '.join(copy_data))
if isStable(copy_data, copy_data):
    print("Stable")
else:
    print("Not stable")

bubble_sort_data = data.copy()
SelectionSort(bubble_sort_data, num)
print(' '.join(bubble_sort_data))
if isStable(bubble_sort_data, copy_data):
    print("Stable")
else:
    print("Not stable")

# Example run
# Input:
-83
3mGQ\v
# Output:
3mGQ\v
Stable
3mGQ\v
Stable
class Card:
    def __init__(self, s, i):
        self.suit = s[0]
        self.value = s[1]
        self.iniorder = i

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:
                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].value < C[minj].value:
                minj = j

        C[i], C[minj] = C[minj], C[i]

    return C


n = int(input())
cards = [Card(c, i) for (i, c) in enumerate(input().split())]

res_bub = BubbleSort(cards[:], n)
res_sel = SelectionSort(cards[:], n)

print(*[c.suit + c.value for c in res_bub])

for i in range(n - 1):
    if res_bub[i].value == res_bub[i + 1].value:
        if res_bub[i].iniorder > res_bub[i + 1].iniorder:
            print("Not stable")
            break
else:
    print("Stable")

print(*[c.suit + c.value for c in res_sel])

for i in range(n - 1):
    if res_sel[i].value == res_sel[i + 1].value:
        if res_sel[i].iniorder > res_sel[i + 1].iniorder:
            print("Not stable")
            break
else:
    print("Stable")

# Example run
# Input:
-111
Neu">/
# Output:
Ne
Stable
Ne
Stable
def bubble(d):
    for i in range(len(d) - 1):
        for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j]

def selection(d):
    for i in range(len(b)):
        min_j = i
        for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
        if min_j != i:
            d[i],d[min_j] = d[min_j], d[i]

n = int(input())
a = list(map(str, input().split()))

b = a.copy()
c = a.copy()

bubble(b)
selection(c)

for d in [b, c]:
    print(" ".join(d))
    if d == b:
        print("Stable")
    else:
        print("Not stable")

# Example run
# Input:
34675473
-579377
# Output:
-579377
Stable
-579377
Stable
n = int(input())

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

def insertion_sort(l):
    for i in range(0, len(l) - 1):
        x = i + 1
        while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
    return l


def babble_sort(l):
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
    return l

def is_stable(a, l):
    for i in range(0, len(a)):
        if a[i] != l[i]:
            return False
    return True

def print_with_space(l):
    print(' '.join(str(x) for x in l))

B = insertion_sort(A[:])

babbled = babble_sort(A[:])
print_with_space(babbled)

if is_stable(B, babbled):
    print('Stable')
else:
    print('Not stable')

def selection_sort(l):
    for i in range(0, len(l)):
        minj = i
        for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        t = l[i]
        l[i] = l[minj]
        l[minj] = t
    return l

selected = selection_sort(A[:])
print_with_space(selected)

if is_stable(B, selected):
    print('Stable')
else:
    print('Not stable')

# Example run
# Input:
-1
-3439167
# Output:
-3439167
Stable
-3439167
Stable
def bubble_sort(num_list):
    flag = 1
    while flag:
        flag = 0
        for i in range(len(num_list)-1,0,-1):
            if int(num_list[i][1:]) < int(num_list[i-1][1:]):
                num_list[i],num_list[i-1] = num_list[i-1],num_list[i]
                flag = 1

def selectin_sort(num_list):
    for i in range(len(num_list)):
        min_idx = i
        for j in range(i,len(num_list)):
            if int(num_list[j][1:]) < int(num_list[min_idx][1:]):
                min_idx = j
        num_list[i],num_list[min_idx] = num_list[min_idx],num_list[i]

n = input()
card_list_1 = [i for i in input().split()]
card_list_2 = [i for i in card_list_1]
bubble_sort  (card_list_1)
selectin_sort(card_list_2)

print(' '.join(card_list_1))
print('Stable')
print(' '.join(card_list_2))
if card_list_1 == card_list_2:
    print('Stable')
else:
    print('Not stable')



# Example run
# Input:
Y{MN[
637975
# Output:
637975
Stable
637975
Stable
#judge stable or not stbale

def printout(array, n):
    output = ""
    for i in range(n - 1):
        output += str(array[i]) + " "
    output += str(array[N - 1])
    print(output)


def bubble_sort(array):
    for i in range(N):
        for j in reversed(range(i+1,N)):
            if (int(array[j-1][1]) > int(array[j][1])):
                #swap
                tmp = array[j]
                array[j] = array[j-1]
                array[j-1] = tmp
    return array


def linearsearch(subarray):
    # return index of minimum array element
    min = int(subarray[0][1])
    min_index = 0;
    for i in range(1,len(subarray)):
        if min > int(subarray[i][1]):
            min = int(subarray[i][1])
            min_index = i
    return min_index


def selection_sort(array):
    index,tmp = 0,0
    for i in range(N):
        index = linearsearch(array[i:]) + i

        if index != i:
            #swap
            tmp = array[index]
            array[index] = array[i]
            array[i] = tmp
    return array


N = int(input())
array = [i for i in input().split()]
array1 = bubble_sort(array[:])
array2 = selection_sort(array[:])
original_array = array[:]

printout(array1,N)
print("Stable")
printout(array2,N)
if array1 == array2:
    print("Stable")
else:
    print("Not stable")



# Example run
# Input:
0
z<=*q6n
# Output:
z<=*q6n
Stable
z<=*q6n
Stable
def bubble_sort_index(n, number_from_cards):
    flag = True
    index_lists = list(range(n))
    while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if number_from_cards[i] < number_from_cards[i - 1]:
                number_from_cards[i], number_from_cards[i - 1] = number_from_cards[i - 1], number_from_cards[i]
                index_lists[i], index_lists[i - 1] = index_lists[i - 1], index_lists[i]
                flag = True
    return index_lists


def selection_sort_index(n, number_from_cards):
    index_list = list(range(n))
    for i in range(n):
        min_j = i
        for j in range(i, n):
            if number_from_cards[min_j] > number_from_cards[j]:
                min_j = j
        if min_j == i:
            continue
        number_from_cards[i], number_from_cards[min_j] = number_from_cards[min_j], number_from_cards[i]
        index_list[i], index_list[min_j] = index_list[min_j], index_list[i]
    return index_list


def main():
    N = int(input())
    true_cards = input().split(' ')
    number_from_cards = [int(c[-1]) for c in true_cards]
    sorted_index_lists_for_bubble = bubble_sort_index(N, number_from_cards.copy())
    sorted_bubble = [true_cards[index] for index in sorted_index_lists_for_bubble]

    sorted_index_lists_for_selection = selection_sort_index(N, number_from_cards.copy())
    sorted_selection = [true_cards[index] for index in sorted_index_lists_for_selection]

    print(' '.join(sorted_bubble))
    print('Stable')
    print(' '.join(sorted_selection))
    if sorted_bubble == sorted_selection:
        print('Stable')
    else:
        print('Not stable')


if __name__ == '__main__':
    main()



# Example run
# Input:
-15220
71127
# Output:

Stable

Stable
import copy

def BubbleSort(C, N):
    for i in range(0,N):
        for j in range(N-1,i,-1):
            if C[j][1:] < C[j-1][1:]:
                #  C[j] と C[j-1] を交換
                C[j] , C[j-1] = C[j-1] , C[j]
    ret = " ".join(C)
    return ret

def SelectionSort(C, N):
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if C[j][1:] < C[minj][1:]:
                minj = j
        # C[i] と C[minj] を交換
        C[i] , C[minj] = C[minj] , C[i]
    ret = " ".join(C)
    return ret

N = int(input())
C = input().split(" ")
ret_B = BubbleSort(copy.deepcopy(C),N)
print("debug:C = {}".format(C))
ret_S = SelectionSort(copy.deepcopy(C),N)
if ret_B == ret_S:
    print("Stable")
else:
    print("Not stable")



# Example run
# Input:
-299483
~vkXMy>
# Output:
debug:C = ['~vkXMy>']
Stable
input_line = int(input())
out_selection = input().split()
out_bubble = out_selection[:]

# bubblesort                                                                                  
for i in range(input_line):
    for j in range(input_line-1, i, -1):
        if out_bubble[j][1] < out_bubble[j-1][1]:
            out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j]
print(*out_bubble)
print("Stable")

# selectionsort                                                                               
for i in range(input_line):
    minj = i
    for j in range(i, input_line):
        if out_selection[j][1] < out_selection[minj][1]:
            minj = j
    out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i]

print(*out_selection)
print("Stable" if out_bubble == out_selection else "Not stable")


# Example run
# Input:
-114886
Crhw
# Output:
Crhw
Stable
Crhw
Stable
n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 m=d.index(min(d[i:]),i)
 if d[i][1]>=d[m][1]:d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
b={i[1]for i in c}
print(["Stable","Not stable"][len(b)<len(c)])


# Example run
# Input:
-1325982
8YU=Cz
# Output:
8YU=Cz
Stable
8YU=Cz
Stable
count = int(input());
data = input().split(" ");

def bubble_sort(data):
    # print(data);
    count = len(data);
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j][1] < data[j - 1][1]:
                data[j], data[j - 1] = data[j - 1], data[j];
        # print(data);

def selection_sort(data):
    count = len(data);
    # print(data);
    for i in range(count - 1):
        minI = i;
        for j in range(i + 1, count):
            if data[j][1] < data[minI][1]:
                minI = j;
        if i != minI:
            data[i], data[minI] = data[minI], data[i];
        # print(data);

def show(data):
    print(" ".join(data));

A = list(data);
bubble_sort(A);
show(A);
print("Stable");

B = list(data);
selection_sort(B);
show(B);
if A == B:
    print("Stable");
else:
    print("Not Stable");


# Example run
# Input:
49968
@j"4g#.G
# Output:
@j"4g#.G
Stable
@j"4g#.G
Stable
#! /usr/local/bin/python3
# coding: utf-8

def swap(c, i, j):
    t = c[i]
    c[i] = c[j]
    c[j] = t

def bubble_sort(cs, f):
    c = cs[:]
    for i in range(len(c) - 1):
        for j in range(len(c) - 1, i - 1, -1):
            if f(c[j - 1]) > f(c[j]):
                swap(c, j - 1, j)
            # print(i, j, c)
    return c

def selection_sort(cs, f):
    c = cs[:]
    for i in range(len(c)):
        minj = i
        for j in range(i, len(c)):
            if f(c[j]) < f(c[minj]):
                minj = j
        swap(c, i, minj)
        # print(c)
    return c

def to_group(c):
    b = {}
    for i in c:
        if not(i[1] in b):
            b[i[1]] = [i]
        else:
            b[i[1]] = b[i[1]] + [i]
    return b

def is_stable(c, s): 
    bc = to_group(c)
    bs = to_group(s(c, lambda x: x[1]))
    # print(bc)
    # print(bs)
    for k in bc:
        if bc[k] != bs[k]:
            return "Not stable"
    return "Stable"

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

print(" ".join(bubble_sort(c, lambda x: x[1])))
print(is_stable(c, bubble_sort))

print(" ".join(selection_sort(c, lambda x: x[1])))
print(is_stable(c, selection_sort))


# Example run
# Input:
49968
@j"4g#.G
# Output:
@j"4g#.G
Stable
@j"4g#.G
Stable
N = int(input())

C = input().split()

B = C[:]
S = C[:]

# bubble sort
flag = 1
while(flag):
    flag = 0
    for x in range(1, N):
        if B[x][1:] < B[x-1][1:]:
            B[x], B[x-1] = B[x-1], B[x]
            flag = 1

# sectionSot
for x in range(0,N):
    minj = x
    for j in range(x,N):
        if S[j][1:] < S[minj][1:]:
            minj = j
    if minj != x:
        S[x], S[minj] = S[minj], S[x]



print(" ".join(b for b in B))
print("Stable")


if(B == S):
    print(" ".join(b for b in S))
    print("Stable")
else:
    print(" ".join(b for b in S))
    print("Not stable")

# Example run
# Input:
-15
$,u|iBS0
# Output:
$,u|iBS0
Stable
$,u|iBS0
Stable
class Card:
    __slots__ = ["mark", "value"]

    def __init__(self, text):
        self.mark = text[0]
        self.value = int(text[1])

    def __str__(self):
        return f"{self.mark}{self.value}"


def BubbleSort(lst):
    lst = lst.copy()
    for i in range(0, len(lst)):
        for j in range(len(lst) - 1, i, -1):
            if lst[j].value < lst[j -1].value:
                lst[j], lst[j - 1] = lst[j - 1], lst[j]
    return lst


def SelectionSort(lst):
    lst = lst.copy()
    for i in range(0, len(lst)):
        minj = i
        for j in range(i, len(lst)):
            if lst[j].value < lst[minj].value:
                minj = j
        lst[i], lst[minj] = lst[minj], lst[i]
    return lst

def check_stable(lst):
    for x in range(1, 10):
        if "".join(c.mark for c in lst if c.value == x) != "".join(c.mark for c in C if c.value == x):
            return False
    return True


input()
C = [Card(i) for i in input().split()]
B = BubbleSort(C)
S = SelectionSort(C)
print(" ".join(map(str, B)))
print("Stable" if check_stable(B) else "Not stable")
print(" ".join(map(str, S)))
print("Stable" if check_stable(S) else "Not stable")



# Example run
# Input:
#7f%jC
923
# Output:
92
Stable
92
Stable
def is_stable(output_str, same_num_str):
    if len(same_num_str)>0:
        for i in range(len(same_num_str)):
            if output_str.find(same_num_str[i]) == -1:
                return "Not Stable"
    return "Stable"
    
data_num = int(input())
cards = input().split(" ")
cards2 = cards[:]
cnt = 0
num_1 = 0
num_2 = 0
same_num_str = []
output_str = ""
judge_stbl = ""
for i in range(data_num):
    
    for j in range(data_num-1, i,-1):
        if int(cards[j][1:]) < int(cards[j-1][1:]):
            cards[j], cards[j-1] = cards[j-1], cards[j]
        elif int(cards[j][1:]) == int(cards[j-1][1:]):
            same_num_str.append(cards[j-1]+" "+cards[j])    
            
output_str = " ".join(cards) 
judge_stbl = is_stable(output_str, same_num_str)

print(output_str + "\n" + judge_stbl)

same_num_str = []
output_str = ""
judge_stbl = ""

for i in range(data_num):
    min_idx = i
    for j in range(i, data_num):
        if int(cards2[j][1:]) < int(cards2[min_idx][1:]):
            min_idx = j
        elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
            same_num_str.append(cards2[min_idx]+" "+cards2[j])    

    if i != min_idx:
        cards2[i], cards2[min_idx] = cards2[min_idx], cards2[i]

output_str = " ".join(cards2) 
judge_stbl = is_stable(output_str, same_num_str)

print(output_str + "\n" + judge_stbl)

# Example run
# Input:
-6086
tY3<*F;s
# Output:
tY3<*F;s
Stable
tY3<*F;s
Stable