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]
    return A

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]
    return A

N =int(input())
cards = input().split()
bub , sel =cards[:] , cards[:]
X = bubbleSort(bub , N)
print(*X)
print("Stable")
Y = selectionSort(sel,N)
print(*Y)
print("Stable" if X == Y else "Not stable") 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]
    return A bubbleSort 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]
     i range(N) 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]
     j range(N-1,i,-1) range N-1 N 1 i -1 if A[j][1:] < A[j-1][1:] :
                A[j] , A[j-1] = A[j-1] , A[j]
     A[j][1:] < A[j-1][1:] A[j][1:] [j] A j 1: 1 A[j-1][1:] [j-1] A j-1 j 1 1: 1 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 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]
    return A selectionSort 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]
     i range(N) range N minj = i minj i for j in range(i,N):
            if A[j][1:] < A[minj][1:]:
                minj = j
         j range(i,N) range i N if A[j][1:] < A[minj][1:]:
                minj = j
         A[j][1:] < A[minj][1:] A[j][1:] [j] A j 1: 1 A[minj][1:] [minj] A minj 1: 1 minj = j minj j A[i] , A[minj] = A[minj] , A[i] A[i] A i A[minj] A minj A[minj] A minj A[i] A i return A A A A N N N =int(input()) N int(input()) int input() input cards = input().split() cards input().split() ().split () input split bub , sel =cards[:] , cards[:] bub cards[:] cards : sel cards[:] cards : X = bubbleSort(bub , N) X bubbleSort(bub , N) bubbleSort bub N print(*X) print *X X print("Stable") print "Stable" Y = selectionSort(sel,N) Y selectionSort(sel,N) selectionSort sel N print(*Y) print *Y Y print("Stable" if X == Y else "Not stable") print "Stable" if X == Y else "Not stable" X == Y X Y "Stable" "Not stable" X = bubbleSort(bub , N) bubbleSort(bub , N) X N =int(input()) int(input()) N cards = input().split() input().split() cards sel =cards[:] , cards[:] cards[:] sel bub , sel =cards[:] , cards[:] cards[:] bub 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]
    return A 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]
    return A selectionSort Y = selectionSort(sel,N) selectionSort(sel,N) Y 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]
    return 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]
    return A bubbleSort
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]
    return A

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]
    return A

N =int(input())
cards = input().split()
bub , sel =cards[:] , cards[:]
X = bubbleSort(bub , N)
print(*X)
print("Stable")
Y = selectionSort(sel,N)
print(*Y)
print("Stable" if X == Y else "Not stable")