import copy
def inputInline():
    N = int(input())
    cards = input().split(" ")
    return cards

def selectionSort(list):
    cards=copy.deepcopy(list)
    n = len(cards)
    count = 0
    for i in range(n):
        min_j = i
        for j in range(i + 1, n):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        if min_j != i:
            temp = cards[i]
            cards[i] = cards[min_j]
            cards[min_j] = temp
            count += 1
    return (" ".join(cards), count)

def bubbleSort(list):
    cards=copy.deepcopy(list)
    N = len(cards)
    count = 0
    flag = True
    while flag:
        flag = False
        for i in range(N - 1):
            if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
    return (" ".join(cards), count)
cards=inputInline()
sortedbubble=bubbleSort(cards)[0]
sortedselection=selectionSort(cards)[0]
print(sortedbubble)
print("Stable")
print(sortedselection)
if sortedbubble==sortedselection:
    print("Stable")
else:
    print("Not stable") import copy copy def inputInline():
    N = int(input())
    cards = input().split(" ")
    return cards inputInline N = int(input()) N int(input()) int input() input cards = input().split(" ") cards input().split(" ") ().split () input split " " return cards cards def selectionSort(list):
    cards=copy.deepcopy(list)
    n = len(cards)
    count = 0
    for i in range(n):
        min_j = i
        for j in range(i + 1, n):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        if min_j != i:
            temp = cards[i]
            cards[i] = cards[min_j]
            cards[min_j] = temp
            count += 1
    return (" ".join(cards), count) selectionSort cards=copy.deepcopy(list) cards copy.deepcopy(list) copy.deepcopy copy deepcopy list n = len(cards) n len(cards) len cards count = 0 count 0 for i in range(n):
        min_j = i
        for j in range(i + 1, n):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        if min_j != i:
            temp = cards[i]
            cards[i] = cards[min_j]
            cards[min_j] = temp
            count += 1
     i range(n) range n min_j = i min_j i for j in range(i + 1, n):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
         j range(i + 1, n) range i + 1 i 1 n if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
         int(cards[j][1]) < int(cards[min_j][1]) int(cards[j][1]) int cards[j][1] [j] cards j 1 int(cards[min_j][1]) int cards[min_j][1] [min_j] cards min_j 1 min_j = j min_j j if min_j != i:
            temp = cards[i]
            cards[i] = cards[min_j]
            cards[min_j] = temp
            count += 1
     min_j != i min_j i temp = cards[i] temp cards[i] cards i cards[i] = cards[min_j] cards[i] cards i cards[min_j] cards min_j cards[min_j] = temp cards[min_j] cards min_j temp count += 1 count 1 return (" ".join(cards), count) (" ".join(cards), count) " ".join(cards) " ".join " " join cards count list list def bubbleSort(list):
    cards=copy.deepcopy(list)
    N = len(cards)
    count = 0
    flag = True
    while flag:
        flag = False
        for i in range(N - 1):
            if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
    return (" ".join(cards), count) bubbleSort cards=copy.deepcopy(list) cards copy.deepcopy(list) copy.deepcopy copy deepcopy list N = len(cards) N len(cards) len cards count = 0 count 0 flag = True flag True while flag:
        flag = False
        for i in range(N - 1):
            if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
     flag flag = False flag False for i in range(N - 1):
            if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
     i range(N - 1) range N - 1 N 1 if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
     int(cards[i][1]) > int(cards[i + 1][1]) int(cards[i][1]) int cards[i][1] [i] cards i 1 int(cards[i + 1][1]) int cards[i + 1][1] [i + 1] cards i + 1 i 1 1 temp = cards[i] temp cards[i] cards i cards[i] = cards[i + 1] cards[i] cards i cards[i + 1] cards i + 1 i 1 cards[i + 1] = temp cards[i + 1] cards i + 1 i 1 temp flag = True flag True count += 1 count 1 return (" ".join(cards), count) (" ".join(cards), count) " ".join(cards) " ".join " " join cards count list list cards=inputInline() cards inputInline() inputInline sortedbubble=bubbleSort(cards)[0] sortedbubble bubbleSort(cards)[0] (cards) bubbleSort cards 0 sortedselection=selectionSort(cards)[0] sortedselection selectionSort(cards)[0] (cards) selectionSort cards 0 print(sortedbubble) print sortedbubble print("Stable") print "Stable" print(sortedselection) print sortedselection if sortedbubble==sortedselection:
    print("Stable")
else:
    print("Not stable") sortedbubble==sortedselection sortedbubble sortedselection print("Stable") print "Stable" print("Not stable") print "Not stable" def bubbleSort(list):
    cards=copy.deepcopy(list)
    N = len(cards)
    count = 0
    flag = True
    while flag:
        flag = False
        for i in range(N - 1):
            if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
    return (" ".join(cards), count) def bubbleSort(list):
    cards=copy.deepcopy(list)
    N = len(cards)
    count = 0
    flag = True
    while flag:
        flag = False
        for i in range(N - 1):
            if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
    return (" ".join(cards), count) bubbleSort sortedselection=selectionSort(cards)[0] selectionSort(cards)[0] sortedselection def inputInline():
    N = int(input())
    cards = input().split(" ")
    return cards def inputInline():
    N = int(input())
    cards = input().split(" ")
    return cards inputInline def selectionSort(list):
    cards=copy.deepcopy(list)
    n = len(cards)
    count = 0
    for i in range(n):
        min_j = i
        for j in range(i + 1, n):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        if min_j != i:
            temp = cards[i]
            cards[i] = cards[min_j]
            cards[min_j] = temp
            count += 1
    return (" ".join(cards), count) def selectionSort(list):
    cards=copy.deepcopy(list)
    n = len(cards)
    count = 0
    for i in range(n):
        min_j = i
        for j in range(i + 1, n):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        if min_j != i:
            temp = cards[i]
            cards[i] = cards[min_j]
            cards[min_j] = temp
            count += 1
    return (" ".join(cards), count) selectionSort sortedbubble=bubbleSort(cards)[0] bubbleSort(cards)[0] sortedbubble cards=inputInline() inputInline() cards
import copy
def inputInline():
    N = int(input())
    cards = input().split(" ")
    return cards

def selectionSort(list):
    cards=copy.deepcopy(list)
    n = len(cards)
    count = 0
    for i in range(n):
        min_j = i
        for j in range(i + 1, n):
            if int(cards[j][1]) < int(cards[min_j][1]):
                min_j = j
        if min_j != i:
            temp = cards[i]
            cards[i] = cards[min_j]
            cards[min_j] = temp
            count += 1
    return (" ".join(cards), count)

def bubbleSort(list):
    cards=copy.deepcopy(list)
    N = len(cards)
    count = 0
    flag = True
    while flag:
        flag = False
        for i in range(N - 1):
            if int(cards[i][1]) > int(cards[i + 1][1]):
                temp = cards[i]
                cards[i] = cards[i + 1]
                cards[i + 1] = temp
                flag = True
                count += 1
    return (" ".join(cards), count)
cards=inputInline()
sortedbubble=bubbleSort(cards)[0]
sortedselection=selectionSort(cards)[0]
print(sortedbubble)
print("Stable")
print(sortedselection)
if sortedbubble==sortedselection:
    print("Stable")
else:
    print("Not stable")