from sys import stdin
def stdinput():
    return stdin.readline().strip()

class Card:
    def __init__(self, value):
        self.value = int(value[1:])
        self.value2 = value

def main():
    n = int(stdinput())
    A = list(map(Card, stdinput().split()))

    bubble_sorted = bubble_sort(A[:], len(A))
    selection_sorted = selection_sort(A[:], len(A))

    print(' '.join(map(lambda c: c.value2, bubble_sorted)))
    print('Stable' if is_stable(A, bubble_sorted) else 'Not stable')
    print(' '.join(map(lambda c: c.value2, selection_sorted)))
    print('Stable' if is_stable(A, selection_sorted) else 'Not 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:
                A[j], A[j-1] = A[j-1], A[j]
    return A

def selection_sort(A, N):
    for i in range(N):
        min_idx = i
        for j in range(i+1, N):
            if A[j].value < A[min_idx].value:
                min_idx = j
        if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
    return A

def is_stable(A, B):
    for i in range(1, 10):
        sub_A = list(filter(lambda c: c.value == i, A))
        sub_B = list(filter(lambda c: c.value == i, B))
        for a, b in zip(sub_A, sub_B):
            if a.value2 != b.value2:
                return False
    return True

if __name__ == '__main__':
    main() from sys import stdin def stdinput():
    return stdin.readline().strip() stdinput return stdin.readline().strip() stdin.readline().strip() stdin.readline().strip stdin.readline() stdin.readline stdin readline strip class Card:
    def __init__(self, value):
        self.value = int(value[1:])
        self.value2 = value Card def __init__(self, value):
        self.value = int(value[1:])
        self.value2 = value __init__ self.value = int(value[1:]) self.value self value int(value[1:]) int value[1:] value 1: 1 self.value2 = value self.value2 self value2 value self self value value def main():
    n = int(stdinput())
    A = list(map(Card, stdinput().split()))

    bubble_sorted = bubble_sort(A[:], len(A))
    selection_sorted = selection_sort(A[:], len(A))

    print(' '.join(map(lambda c: c.value2, bubble_sorted)))
    print('Stable' if is_stable(A, bubble_sorted) else 'Not stable')
    print(' '.join(map(lambda c: c.value2, selection_sorted)))
    print('Stable' if is_stable(A, selection_sorted) else 'Not stable') main n = int(stdinput()) n int(stdinput()) int stdinput() stdinput A = list(map(Card, stdinput().split())) A list(map(Card, stdinput().split())) list map(Card, stdinput().split()) map Card stdinput().split() ().split () stdinput split bubble_sorted = bubble_sort(A[:], len(A)) bubble_sorted bubble_sort(A[:], len(A)) bubble_sort A[:] A : len(A) len A selection_sorted = selection_sort(A[:], len(A)) selection_sorted selection_sort(A[:], len(A)) selection_sort A[:] A : len(A) len A print(' '.join(map(lambda c: c.value2, bubble_sorted))) print ' '.join(map(lambda c: c.value2, bubble_sorted)) ' '.join ' ' join map(lambda c: c.value2, bubble_sorted) map lambda c: c.value2 c.value2 c value2 c bubble_sorted print('Stable' if is_stable(A, bubble_sorted) else 'Not stable') print 'Stable' if is_stable(A, bubble_sorted) else 'Not stable' is_stable(A, bubble_sorted) is_stable A bubble_sorted 'Stable' 'Not stable' print(' '.join(map(lambda c: c.value2, selection_sorted))) print ' '.join(map(lambda c: c.value2, selection_sorted)) ' '.join ' ' join map(lambda c: c.value2, selection_sorted) map lambda c: c.value2 c.value2 c value2 c selection_sorted print('Stable' if is_stable(A, selection_sorted) else 'Not stable') print 'Stable' if is_stable(A, selection_sorted) else 'Not stable' is_stable(A, selection_sorted) is_stable A selection_sorted 'Stable' 'Not 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:
                A[j], A[j-1] = A[j-1], A[j]
    return A bubble_sort for i in range(N):
        for j in range(N-1, i, -1):
            if A[j].value < A[j-1].value:
                A[j], A[j-1] = A[j-1], A[j]
     i range(N) range N for j in range(N-1, i, -1):
            if A[j].value < A[j-1].value:
                A[j], A[j-1] = A[j-1], A[j]
     j range(N-1, i, -1) range N-1 N 1 i -1 if A[j].value < A[j-1].value:
                A[j], A[j-1] = A[j-1], A[j]
     A[j].value < A[j-1].value A[j].value [j] A j value A[j-1].value [j-1] A j-1 j 1 value A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j return A A A A N N def selection_sort(A, N):
    for i in range(N):
        min_idx = i
        for j in range(i+1, N):
            if A[j].value < A[min_idx].value:
                min_idx = j
        if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
    return A selection_sort for i in range(N):
        min_idx = i
        for j in range(i+1, N):
            if A[j].value < A[min_idx].value:
                min_idx = j
        if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
     i range(N) range N min_idx = i min_idx i for j in range(i+1, N):
            if A[j].value < A[min_idx].value:
                min_idx = j
         j range(i+1, N) range i+1 i 1 N if A[j].value < A[min_idx].value:
                min_idx = j
         A[j].value < A[min_idx].value A[j].value [j] A j value A[min_idx].value [min_idx] A min_idx value min_idx = j min_idx j if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
     min_idx != i min_idx i A[i], A[min_idx] = A[min_idx], A[i] A[i] A i A[min_idx] A min_idx A[min_idx] A min_idx A[i] A i return A A A A N N def is_stable(A, B):
    for i in range(1, 10):
        sub_A = list(filter(lambda c: c.value == i, A))
        sub_B = list(filter(lambda c: c.value == i, B))
        for a, b in zip(sub_A, sub_B):
            if a.value2 != b.value2:
                return False
    return True is_stable for i in range(1, 10):
        sub_A = list(filter(lambda c: c.value == i, A))
        sub_B = list(filter(lambda c: c.value == i, B))
        for a, b in zip(sub_A, sub_B):
            if a.value2 != b.value2:
                return False
     i range(1, 10) range 1 10 sub_A = list(filter(lambda c: c.value == i, A)) sub_A list(filter(lambda c: c.value == i, A)) list filter(lambda c: c.value == i, A) filter lambda c: c.value == i c.value == i c.value c value i c A sub_B = list(filter(lambda c: c.value == i, B)) sub_B list(filter(lambda c: c.value == i, B)) list filter(lambda c: c.value == i, B) filter lambda c: c.value == i c.value == i c.value c value i c B for a, b in zip(sub_A, sub_B):
            if a.value2 != b.value2:
                return False
     a b zip(sub_A, sub_B) zip sub_A sub_B if a.value2 != b.value2:
                return False
     a.value2 != b.value2 a.value2 a value2 b.value2 b value2 return False False return True True A A B B if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main 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:
                A[j], A[j-1] = A[j-1], A[j]
    return A 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:
                A[j], A[j-1] = A[j-1], A[j]
    return A bubble_sort def selection_sort(A, N):
    for i in range(N):
        min_idx = i
        for j in range(i+1, N):
            if A[j].value < A[min_idx].value:
                min_idx = j
        if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
    return A def selection_sort(A, N):
    for i in range(N):
        min_idx = i
        for j in range(i+1, N):
            if A[j].value < A[min_idx].value:
                min_idx = j
        if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
    return A selection_sort def stdinput():
    return stdin.readline().strip() def stdinput():
    return stdin.readline().strip() stdinput def main():
    n = int(stdinput())
    A = list(map(Card, stdinput().split()))

    bubble_sorted = bubble_sort(A[:], len(A))
    selection_sorted = selection_sort(A[:], len(A))

    print(' '.join(map(lambda c: c.value2, bubble_sorted)))
    print('Stable' if is_stable(A, bubble_sorted) else 'Not stable')
    print(' '.join(map(lambda c: c.value2, selection_sorted)))
    print('Stable' if is_stable(A, selection_sorted) else 'Not stable') def main():
    n = int(stdinput())
    A = list(map(Card, stdinput().split()))

    bubble_sorted = bubble_sort(A[:], len(A))
    selection_sorted = selection_sort(A[:], len(A))

    print(' '.join(map(lambda c: c.value2, bubble_sorted)))
    print('Stable' if is_stable(A, bubble_sorted) else 'Not stable')
    print(' '.join(map(lambda c: c.value2, selection_sorted)))
    print('Stable' if is_stable(A, selection_sorted) else 'Not stable') main def is_stable(A, B):
    for i in range(1, 10):
        sub_A = list(filter(lambda c: c.value == i, A))
        sub_B = list(filter(lambda c: c.value == i, B))
        for a, b in zip(sub_A, sub_B):
            if a.value2 != b.value2:
                return False
    return True def is_stable(A, B):
    for i in range(1, 10):
        sub_A = list(filter(lambda c: c.value == i, A))
        sub_B = list(filter(lambda c: c.value == i, B))
        for a, b in zip(sub_A, sub_B):
            if a.value2 != b.value2:
                return False
    return True is_stable class Card:
    def __init__(self, value):
        self.value = int(value[1:])
        self.value2 = value class Card:
    def __init__(self, value):
        self.value = int(value[1:])
        self.value2 = value Card
from sys import stdin
def stdinput():
    return stdin.readline().strip()

class Card:
    def __init__(self, value):
        self.value = int(value[1:])
        self.value2 = value

def main():
    n = int(stdinput())
    A = list(map(Card, stdinput().split()))

    bubble_sorted = bubble_sort(A[:], len(A))
    selection_sorted = selection_sort(A[:], len(A))

    print(' '.join(map(lambda c: c.value2, bubble_sorted)))
    print('Stable' if is_stable(A, bubble_sorted) else 'Not stable')
    print(' '.join(map(lambda c: c.value2, selection_sorted)))
    print('Stable' if is_stable(A, selection_sorted) else 'Not 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:
                A[j], A[j-1] = A[j-1], A[j]
    return A

def selection_sort(A, N):
    for i in range(N):
        min_idx = i
        for j in range(i+1, N):
            if A[j].value < A[min_idx].value:
                min_idx = j
        if min_idx != i:
            A[i], A[min_idx] = A[min_idx], A[i]
    return A

def is_stable(A, B):
    for i in range(1, 10):
        sub_A = list(filter(lambda c: c.value == i, A))
        sub_B = list(filter(lambda c: c.value == i, B))
        for a, b in zip(sub_A, sub_B):
            if a.value2 != b.value2:
                return False
    return True

if __name__ == '__main__':
    main()
