from collections import namedtuple


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]


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]


Card = namedtuple('Card', 'mark value')
n = int(input())
a = [Card(i[0], int(i[1])) for i in input().split()]
b = a[:]

BubbleSort(a, n)
SelectionSort(b, n)

print(" ".join([i.mark + str(i.value) for i in a]))
print("Stable")
print(" ".join([i.mark + str(i.value) for i in b]))
print("Stable" if a == b else "Not stable") from collections import namedtuple 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] BubbleSort 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] i range(N) 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] j range(N-1, i, -1) range N-1 N 1 i -1 if C[j].value < C[j-1].value:
                C[j], C[j-1] = C[j-1], C[j] C[j].value < C[j-1].value C[j].value [j] C j value C[j-1].value [j-1] C j-1 j 1 value C[j], C[j-1] = C[j-1], C[j] C[j] C j C[j-1] C j-1 j 1 C[j-1] C j-1 j 1 C[j] C j C C N N 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] SelectionSort 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] i range(N) range N minj = i minj i for j in range(i, N):
            if C[j].value < C[minj].value:
                minj = j
         j range(i, N) range i N if C[j].value < C[minj].value:
                minj = j
         C[j].value < C[minj].value C[j].value [j] C j value C[minj].value [minj] C minj value minj = j minj j C[i], C[minj] = C[minj], C[i] C[i] C i C[minj] C minj C[minj] C minj C[i] C i C C N N Card = namedtuple('Card', 'mark value') Card namedtuple('Card', 'mark value') namedtuple 'Card' 'mark value' n = int(input()) n int(input()) int input() input Card(i[0], int(i[1])) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() Card(i[0], int(i[1])) Card i[0] i 0 int(i[1]) int i[1] i 1 a = [Card(i[0], int(i[1])) for i in input().split()] a [Card(i[0], int(i[1])) for i in input().split()] b = a[:] b a[:] a : BubbleSort(a, n) BubbleSort a n SelectionSort(b, n) SelectionSort b n i.mark + str(i.value) for i in a for i in a i a for i in a i.mark + str(i.value) i.mark i mark str(i.value) str i.value i value print(" ".join([i.mark + str(i.value) for i in a])) print " ".join([i.mark + str(i.value) for i in a]) " ".join " " join [i.mark + str(i.value) for i in a] print("Stable") print "Stable" i.mark + str(i.value) for i in b for i in b i b for i in b i.mark + str(i.value) i.mark i mark str(i.value) str i.value i value print(" ".join([i.mark + str(i.value) for i in b])) print " ".join([i.mark + str(i.value) for i in b]) " ".join " " join [i.mark + str(i.value) for i in b] print("Stable" if a == b else "Not stable") print "Stable" if a == b else "Not stable" a == b a b "Stable" "Not stable" n = int(input()) int(input()) n b = a[:] a[:] b a = [Card(i[0], int(i[1])) for i in input().split()] [Card(i[0], int(i[1])) for i in input().split()] a 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] 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] SelectionSort Card = namedtuple('Card', 'mark value') namedtuple('Card', 'mark value') Card 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] 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] BubbleSort
from collections import namedtuple


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]


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]


Card = namedtuple('Card', 'mark value')
n = int(input())
a = [Card(i[0], int(i[1])) for i in input().split()]
b = a[:]

BubbleSort(a, n)
SelectionSort(b, n)

print(" ".join([i.mark + str(i.value) for i in a]))
print("Stable")
print(" ".join([i.mark + str(i.value) for i in b]))
print("Stable" if a == b else "Not stable")